process.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. const maybeReturnProcess = () => {
  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. const p = maybeReturnProcess() || {};
  28. if (!p.cwd)
  29. p.cwd = () => '/';
  30. if (!p.nextTick)
  31. p.nextTick = require('./setImmediate').default;
  32. if (!p.emitWarning)
  33. p.emitWarning = (message, type) => {
  34. // tslint:disable-next-line:no-console
  35. console.warn(`${type}${type ? ': ' : ''}${message}`);
  36. };
  37. if (!p.env)
  38. p.env = {};
  39. return p;
  40. }
  41. exports.createProcess = createProcess;
  42. exports.default = createProcess();