2020-07-10 03:32:37 +00:00
|
|
|
import * as path from 'path';
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
const Module = require('module');
|
|
|
|
|
|
|
|
// We modified the original process.argv to let node.js load the
|
|
|
|
// init.js, we need to restore it here.
|
|
|
|
process.argv.splice(1, 1);
|
|
|
|
|
|
|
|
// Clear search paths.
|
|
|
|
require('../common/reset-search-paths');
|
|
|
|
|
|
|
|
// Import common settings.
|
2018-09-20 03:43:26 +00:00
|
|
|
require('@electron/internal/common/init');
|
2017-03-08 09:58:54 +00:00
|
|
|
|
2021-07-04 23:48:46 +00:00
|
|
|
// Process command line arguments.
|
|
|
|
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');
|
|
|
|
|
2017-03-08 09:58:54 +00:00
|
|
|
// Export node bindings to global.
|
2023-05-25 01:09:17 +00:00
|
|
|
const { makeRequireFunction } = __non_webpack_require__('internal/modules/cjs/helpers');
|
2019-06-04 00:03:59 +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.
|
2023-02-02 00:03:23 +00:00
|
|
|
// NB. 'self' isn't defined in an AudioWorklet.
|
|
|
|
if (typeof self !== 'undefined' && self.location.protocol === 'file:') {
|
|
|
|
const pathname = process.platform === 'win32' && self?.location.pathname[0] === '/' ? self?.location.pathname.substr(1) : self?.location.pathname;
|
2017-03-08 09:58:54 +00:00
|
|
|
global.__filename = path.normalize(decodeURIComponent(pathname));
|
|
|
|
global.__dirname = path.dirname(global.__filename);
|
|
|
|
|
|
|
|
// Set module's filename so relative require can work as expected.
|
2019-06-02 20:03:03 +00:00
|
|
|
global.module.filename = global.__filename;
|
2017-03-08 09:58:54 +00:00
|
|
|
|
|
|
|
// Also search for module under the html file.
|
2019-06-04 00:03:59 +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
|
|
|
|
global.__filename = path.join(process.resourcesPath, 'electron.asar', 'worker', 'init.js');
|
|
|
|
global.__dirname = path.join(process.resourcesPath, 'electron.asar', 'worker');
|
2021-07-04 23:48:46 +00:00
|
|
|
|
|
|
|
const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null;
|
|
|
|
if (appPath) {
|
|
|
|
// Search for module under the app directory.
|
|
|
|
global.module.paths = Module._nodeModulePaths(appPath);
|
|
|
|
}
|
2017-03-08 09:58:54 +00:00
|
|
|
}
|