/
process.ts
37 lines (33 loc) · 993 Bytes
/
process.ts
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
// Here we mock the global `process` variable in case we are not in Node's environment.
export interface IProcess {
getuid(): number;
getgid(): number;
cwd(): string;
platform: string;
nextTick: (callback: (...args) => void, ...args) => void;
emitWarning: (message: string, type: string) => void;
env: {
MEMFS_DONT_WARN?: boolean;
};
}
export function createProcess(): IProcess {
let p: IProcess = typeof process !== 'undefined' && process;
if (!p) {
try {
p = require('process');
} catch (e) {}
}
if (!p) p = {} as IProcess;
if (!p.getuid) p.getuid = () => 0;
if (!p.getgid) p.getgid = () => 0;
if (!p.cwd) p.cwd = () => '/';
if (!p.nextTick) p.nextTick = require('./setImmediate').default;
if (!p.emitWarning)
p.emitWarning = (message, type) => {
// tslint:disable-next-line:no-console
console.warn(`${type}${type ? ': ' : ''}${message}`);
};
if (!p.env) p.env = {};
return p;
}
export default createProcess();