2017-03-08 09:58:54 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
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
|
|
|
|
|
|
|
// Export node bindings to global.
|
2019-06-02 20:03:03 +00:00
|
|
|
global.require = __non_webpack_require__ // eslint-disable-line
|
|
|
|
global.module = Module._cache[__filename]
|
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:') {
|
2018-10-02 01:56:31 +00:00
|
|
|
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-02 20:03:03 +00:00
|
|
|
global.module.paths = global.module.paths.concat(Module._nodeModulePaths(global.__dirname))
|
2017-03-08 09:58:54 +00:00
|
|
|
} else {
|
|
|
|
global.__filename = __filename
|
|
|
|
global.__dirname = __dirname
|
|
|
|
}
|