init.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const path = require('path');
  3. const Module = require('module');
  4. // We modified the original process.argv to let node.js load the
  5. // init.js, we need to restore it here.
  6. process.argv.splice(1, 1);
  7. // Clear search paths.
  8. require('../common/reset-search-paths');
  9. // Import common settings.
  10. require('@electron/internal/common/init');
  11. // Export node bindings to global.
  12. const { makeRequireFunction } = __non_webpack_require__('internal/modules/cjs/helpers') // eslint-disable-line
  13. global.module = new Module('electron/js2c/worker_init');
  14. global.require = makeRequireFunction(global.module);
  15. // Set the __filename to the path of html file if it is file: protocol.
  16. if (self.location.protocol === 'file:') {
  17. const pathname = process.platform === 'win32' && self.location.pathname[0] === '/' ? self.location.pathname.substr(1) : self.location.pathname;
  18. global.__filename = path.normalize(decodeURIComponent(pathname));
  19. global.__dirname = path.dirname(global.__filename);
  20. // Set module's filename so relative require can work as expected.
  21. global.module.filename = global.__filename;
  22. // Also search for module under the html file.
  23. global.module.paths = Module._nodeModulePaths(global.__dirname);
  24. } else {
  25. // For backwards compatibility we fake these two paths here
  26. global.__filename = path.join(process.resourcesPath, 'electron.asar', 'worker', 'init.js');
  27. global.__dirname = path.join(process.resourcesPath, 'electron.asar', 'worker');
  28. }