|
@@ -711,31 +711,42 @@
|
|
|
overrideAPISync(Module._extensions, '.node', 1)
|
|
|
overrideAPISync(fs, 'openSync')
|
|
|
|
|
|
- // Lazily override the child_process APIs only when child_process is fetched the first time
|
|
|
- const originalModuleLoad = Module._load
|
|
|
- Module._load = (request, ...args) => {
|
|
|
- const loadResult = originalModuleLoad(request, ...args)
|
|
|
- if (request === 'child_process') {
|
|
|
- if (!v8Util.getHiddenValue(loadResult, 'asar-ready')) {
|
|
|
- v8Util.setHiddenValue(loadResult, 'asar-ready', true)
|
|
|
- // Just to make it obvious what we are dealing with here
|
|
|
- const childProcess = loadResult
|
|
|
-
|
|
|
- // Executing a command string containing a path to an asar
|
|
|
- // archive confuses `childProcess.execFile`, which is internally
|
|
|
- // called by `childProcess.{exec,execSync}`, causing
|
|
|
- // Electron to consider the full command as a single path
|
|
|
- // to an archive.
|
|
|
- const { exec, execSync } = childProcess
|
|
|
- childProcess.exec = invokeWithNoAsar(exec)
|
|
|
- childProcess.exec[util.promisify.custom] = invokeWithNoAsar(exec[util.promisify.custom])
|
|
|
- childProcess.execSync = invokeWithNoAsar(execSync)
|
|
|
-
|
|
|
- overrideAPI(childProcess, 'execFile')
|
|
|
- overrideAPISync(childProcess, 'execFileSync')
|
|
|
+ const overrideChildProcess = (childProcess) => {
|
|
|
+ // Executing a command string containing a path to an asar archive
|
|
|
+ // confuses `childProcess.execFile`, which is internally called by
|
|
|
+ // `childProcess.{exec,execSync}`, causing Electron to consider the full
|
|
|
+ // command as a single path to an archive.
|
|
|
+ const { exec, execSync } = childProcess
|
|
|
+ childProcess.exec = invokeWithNoAsar(exec)
|
|
|
+ childProcess.exec[util.promisify.custom] = invokeWithNoAsar(exec[util.promisify.custom])
|
|
|
+ childProcess.execSync = invokeWithNoAsar(execSync)
|
|
|
+
|
|
|
+ overrideAPI(childProcess, 'execFile')
|
|
|
+ overrideAPISync(childProcess, 'execFileSync')
|
|
|
+ }
|
|
|
+
|
|
|
+ // Lazily override the child_process APIs only when child_process is
|
|
|
+ // fetched the first time. We will eagerly override the child_process APIs
|
|
|
+ // when this env var is set so that stack traces generated inside node unit
|
|
|
+ // tests will match. This env var will only slow things down in users apps
|
|
|
+ // and should not be used.
|
|
|
+ if (process.env.ELECTRON_EAGER_ASAR_HOOK_FOR_TESTING) {
|
|
|
+ overrideChildProcess(require('child_process'))
|
|
|
+ } else {
|
|
|
+ const originalModuleLoad = Module._load
|
|
|
+ Module._load = (request, ...args) => {
|
|
|
+ const loadResult = originalModuleLoad(request, ...args)
|
|
|
+ if (request === 'child_process') {
|
|
|
+ if (!v8Util.getHiddenValue(loadResult, 'asar-ready')) {
|
|
|
+ v8Util.setHiddenValue(loadResult, 'asar-ready', true)
|
|
|
+ // Just to make it obvious what we are dealing with here
|
|
|
+ const childProcess = loadResult
|
|
|
+
|
|
|
+ overrideChildProcess(childProcess)
|
|
|
+ }
|
|
|
}
|
|
|
+ return loadResult
|
|
|
}
|
|
|
- return loadResult
|
|
|
}
|
|
|
}
|
|
|
})()
|