UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2// Here we mock the global `process` variable in case we are not in Node's environment.
3Object.defineProperty(exports, "__esModule", { value: true });
4exports.createProcess = void 0;
5/**
6 * Looks to return a `process` object, if one is available.
7 *
8 * The global `process` is returned if defined;
9 * otherwise `require('process')` is attempted.
10 *
11 * If that fails, `undefined` is returned.
12 *
13 * @return {IProcess | undefined}
14 */
15var maybeReturnProcess = function () {
16 if (typeof process !== 'undefined') {
17 return process;
18 }
19 try {
20 return require('process');
21 }
22 catch (_a) {
23 return undefined;
24 }
25};
26function createProcess() {
27 var p = maybeReturnProcess() || {};
28 if (!p.getuid)
29 p.getuid = function () { return 0; };
30 if (!p.getgid)
31 p.getgid = function () { return 0; };
32 if (!p.cwd)
33 p.cwd = function () { return '/'; };
34 if (!p.nextTick)
35 p.nextTick = require('./setImmediate').default;
36 if (!p.emitWarning)
37 p.emitWarning = function (message, type) {
38 // tslint:disable-next-line:no-console
39 console.warn("" + type + (type ? ': ' : '') + message);
40 };
41 if (!p.env)
42 p.env = {};
43 return p;
44}
45exports.createProcess = createProcess;
46exports.default = createProcess();