2020-03-20 20:28:31 +00:00
|
|
|
'use strict';
|
2017-03-08 09:58:54 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const path = require('path');
|
|
|
|
const Module = require('module');
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// We modified the original process.argv to let node.js load the
|
|
|
|
// init.js, we need to restore it here.
|
2020-03-20 20:28:31 +00:00
|
|
|
process.argv.splice(1, 1);
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Clear search paths.
|
2020-03-20 20:28:31 +00:00
|
|
|
require('../common/reset-search-paths');
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Import common settings.
|
2020-03-20 20:28:31 +00:00
|
|
|
require('@electron/internal/common/init');
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Export node bindings to global.
|
2019-06-04 00:03:59 +00:00
|
|
|
const { makeRequireFunction } = __non_webpack_require__('internal/modules/cjs/helpers') // eslint-disable-line
|
2020-03-20 20:28:31 +00:00
|
|
|
global.module = new Module('electron/js2c/worker_init');
|
|
|
|
global.require = makeRequireFunction(global.module);
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Set the __filename to the path of html file if it is file: protocol.
|
|
|
|
if (self.location.protocol === 'file:') {
|
2020-03-20 20:28:31 +00:00
|
|
|
const pathname = process.platform === 'win32' && self.location.pathname[0] === '/' ? self.location.pathname.substr(1) : self.location.pathname;
|
|
|
|
global.__filename = path.normalize(decodeURIComponent(pathname));
|
|
|
|
global.__dirname = path.dirname(global.__filename);
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Set module's filename so relative require can work as expected.
|
2020-03-20 20:28:31 +00:00
|
|
|
global.module.filename = global.__filename;
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Also search for module under the html file.
|
2020-03-20 20:28:31 +00:00
|
|
|
global.module.paths = Module._nodeModulePaths(global.__dirname);
|
2017-03-08 09:58:54 +00:00
|
|
|
} else {
|
2019-06-04 00:03:59 +00:00
|
|
|
// For backwards compatibility we fake these two paths here
|
2020-03-20 20:28:31 +00:00
|
|
|
global.__filename = path.join(process.resourcesPath, 'electron.asar', 'worker', 'init.js');
|
|
|
|
global.__dirname = path.join(process.resourcesPath, 'electron.asar', 'worker');
|
2017-03-08 09:58:54 +00:00
|
|
|
}
|