fix: support esm entrypoint to utility process (#40047)
This commit is contained in:
parent
d6c8ff2e70
commit
371e83a8d2
4 changed files with 41 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
import { pathToFileURL } from 'url';
|
||||
|
||||
import { ParentPort } from '@electron/internal/utility/parent-port';
|
||||
const Module = require('module') as NodeJS.ModuleInternal;
|
||||
|
||||
const v8Util = process._linkedBinding('electron_common_v8_util');
|
||||
|
||||
const entryScript: string = v8Util.getHiddenValue(process, '_serviceStartupScript');
|
||||
|
@ -34,5 +36,14 @@ parentPort.on('removeListener', (name: string) => {
|
|||
});
|
||||
|
||||
// Finally load entry script.
|
||||
process._firstFileName = Module._resolveFilename(entryScript, null, false);
|
||||
Module._load(entryScript, Module, true);
|
||||
const { loadESM } = __non_webpack_require__('internal/process/esm_loader');
|
||||
const mainEntry = pathToFileURL(entryScript);
|
||||
loadESM(async (esmLoader: any) => {
|
||||
try {
|
||||
await esmLoader.import(mainEntry.toString(), undefined, Object.create(null));
|
||||
} catch (err) {
|
||||
// @ts-ignore internalBinding is a secret internal global that we shouldn't
|
||||
// really be using, so we ignore the type error instead of declaring it in types
|
||||
internalBinding('errors').triggerUncaughtException(err);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue