chore: remove node patches by using the preload feature (#41080)
This commit is contained in:
parent
031d636823
commit
d13a93fb61
21 changed files with 403 additions and 135 deletions
31
lib/node/init.ts
Normal file
31
lib/node/init.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Initialize ASAR support in fs module.
|
||||
import { wrapFsWithAsar } from './asar-fs-wrapper';
|
||||
wrapFsWithAsar(require('fs'));
|
||||
|
||||
// Hook child_process.fork.
|
||||
const cp = require('child_process');
|
||||
const originalFork = cp.fork;
|
||||
cp.fork = (modulePath: string, args: any, options: any) => {
|
||||
// Parse optional args.
|
||||
if (args == null) {
|
||||
args = [];
|
||||
} else if (typeof args === 'object' && !Array.isArray(args)) {
|
||||
options = args;
|
||||
args = [];
|
||||
}
|
||||
// Fallback to original fork to report arg type errors.
|
||||
if (typeof modulePath !== 'string' || !Array.isArray(args) ||
|
||||
(typeof options !== 'object' && typeof options !== 'undefined')) {
|
||||
return originalFork(modulePath, args, options);
|
||||
}
|
||||
// When forking a child script, we setup a special environment to make
|
||||
// the electron binary run like upstream Node.js.
|
||||
options = options ?? {};
|
||||
options.env = Object.create(options.env || process.env);
|
||||
options.env.ELECTRON_RUN_AS_NODE = 1;
|
||||
// On mac the child script runs in helper executable.
|
||||
if (!options.execPath && process.platform === 'darwin') {
|
||||
options.execPath = process.helperExecPath;
|
||||
}
|
||||
return originalFork(modulePath, args, options);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue