asarfuckery/electronasar/ptb/worker/init.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-10-01 13:49:56 +00:00
'use strict';
const path = require('path');
const Module = require('module');
2019-01-17 18:22:05 +00:00
// We modified the original process.argv to let node.js load the
// init.js, we need to restore it here.
2019-10-01 13:49:56 +00:00
process.argv.splice(1, 1);
2019-01-17 18:22:05 +00:00
// Clear search paths.
2019-10-01 13:49:56 +00:00
require('../common/reset-search-paths');
2019-01-17 18:22:05 +00:00
// Import common settings.
2019-10-01 13:49:56 +00:00
require('@electron/internal/common/init');
2019-01-17 18:22:05 +00:00
// Expose public APIs.
2019-10-01 13:49:56 +00:00
Module.globalPaths.push(path.join(__dirname, 'api', 'exports'));
2019-01-17 18:22:05 +00:00
// Export node bindings to global.
2019-10-01 13:49:56 +00:00
global.require = require;
global.module = module;
2019-01-17 18:22:05 +00:00
// Set the __filename to the path of html file if it is file: protocol.
if (self.location.protocol === 'file:') {
2019-10-01 13:49:56 +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);
// Set module's filename so relative require can work as expected.
module.filename = global.__filename;
// Also search for module under the html file.
module.paths = module.paths.concat(Module._nodeModulePaths(global.__dirname));
}
else {
global.__filename = __filename;
global.__dirname = __dirname;
2019-01-17 18:22:05 +00:00
}