process.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. // Here we mock the global `process` variable in case we are not in Node's environment.
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. exports.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. */
  15. var 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. };
  26. function 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("".concat(type).concat(type ? ': ' : '').concat(message));
  40. };
  41. if (!p.env)
  42. p.env = {};
  43. return p;
  44. }
  45. exports.createProcess = createProcess;
  46. exports.default = createProcess();