-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode-polyfills.ts
More file actions
103 lines (92 loc) · 3.42 KB
/
node-polyfills.ts
File metadata and controls
103 lines (92 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
export class EventEmitter {
on() { return this; }
off() { return this; }
emit() { return true; }
once() { return this; }
addListener() { return this; }
removeListener() { return this; }
removeAllListeners() { return this; }
}
export default { EventEmitter };
export class Stream extends EventEmitter {
pipe() { return this; }
}
export class Readable extends Stream {}
export class Writable extends Stream {}
export class Transform extends Stream {}
export class StringDecoder {
write() { return ''; }
end() { return ''; }
}
export const promises = {
readFile: async () => '',
writeFile: async () => {},
stat: async () => ({ isDirectory: () => false, isFile: () => false }),
mkdir: async () => {},
rm: async () => {},
};
// os polyfills
export const type = () => 'Browser';
export const platform = () => 'browser';
export const release = () => '1.0.0';
export const tmpdir = () => '/tmp';
export const homedir = () => '/';
export const endianness = () => 'LE';
export const arch = () => 'javascript';
export const EOL = '\n';
export const readFileSync = () => '';
export const writeFileSync = () => {};
export const statSync = () => ({ isDirectory: () => false, isFile: () => false, isSymbolicLink: () => false });
export const lstatSync = () => ({ isDirectory: () => false, isFile: () => false, isSymbolicLink: () => false });
export const existsSync = () => false;
export const join = (...args) => args.join('/');
export const resolve = (...args) => args.join('/');
export const dirname = (path) => path;
export const basename = (path) => path;
export const extname = (path) => '';
export const sep = '/';
export const relative = () => '';
export const isAbsolute = () => false;
export const normalize = (p: string) => p;
export const posix = {};
export const win32 = {};
// fs/promises and other missing exports
export const open = async () => ({ close: async () => {} });
export class Stats {
isDirectory() { return false; }
isFile() { return false; }
isSymbolicLink() { return false; }
}
export const watchFile = () => {};
export const unwatchFile = () => {};
export const fileURLToPath = () => '';
export const pathToFileURL = () => '';
export const readdir = () => {};
export const readdirSync = () => [];
export const readlink = () => {};
export const readlinkSync = () => '';
export const realpath = async () => '';
export const realpathSync = () => '';
realpathSync.native = () => '';
export const constants = {};
export const lstat = async () => ({ isDirectory: () => false, isFile: () => false, isSymbolicLink: () => false });
export const stat = async () => ({ isDirectory: () => false, isFile: () => false, isSymbolicLink: () => false });
export const access = () => {};
export const accessSync = () => {};
export const mkdir = () => {};
export const mkdirSync = () => {};
export const rmdir = () => {};
export const rmdirSync = () => {};
export const unlink = () => {};
export const unlinkSync = () => {};
export const copyFile = () => {};
export const copyFileSync = () => {};
export const createReadStream = () => new Readable();
export const createWriteStream = () => new Writable();
export const watch = () => new EventEmitter();
export const readFile = async () => '';
export const writeFile = async () => {};
export const rename = async () => {};
export const renameSync = () => {};
export const createHash = () => ({ update: () => ({ digest: () => '' }) });
export const randomUUID = () => '00000000-0000-0000-0000-000000000000';