electron/lib/utility/init.ts
electron-roller[bot] 653d0f009e
chore: bump node to v20.13.1 (main) (#42088)
* chore: bump node in DEPS to v20.13.0

* crypto: enable NODE_EXTRA_CA_CERTS with BoringSSL

https://github.com/nodejs/node/pull/52217

* test: skip test for dynamically linked OpenSSL

https://github.com/nodejs/node/pull/52542

* lib, url: add a `windows` option to path parsing

https://github.com/nodejs/node/pull/52509

* src: use dedicated routine to compile function for builtin CJS loader

https://github.com/nodejs/node/pull/52016

* test: mark test as flaky

https://github.com/nodejs/node/pull/52671

* build,tools: add test-ubsan ci

https://github.com/nodejs/node/pull/46297

* src: preload function for Environment

https://github.com/nodejs/node/pull/51539

* chore: fixup patch indices

* deps: update c-ares to 1.28.1

https://github.com/nodejs/node/pull/52285

* chore: handle updated filenames

- https://github.com/nodejs/node/pull/51999
- https://github.com/nodejs/node/pull/51927

* chore: bump node in DEPS to v20.13.1

* events: extract addAbortListener for safe internal use

https://github.com/nodejs/node/pull/52081

* module: print location of unsettled top-level await in entry points

https://github.com/nodejs/node/pull/51999

* fs: add stacktrace to fs/promises

https://github.com/nodejs/node/pull/49849

* chore: update patches

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
2024-05-13 11:43:14 -04:00

50 lines
1.7 KiB
TypeScript

import { EventEmitter } from 'events';
import { pathToFileURL } from 'url';
import { ParentPort } from '@electron/internal/utility/parent-port';
const v8Util = process._linkedBinding('electron_common_v8_util');
const entryScript: string = v8Util.getHiddenValue(process, '_serviceStartupScript');
// 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, entryScript);
// Import common settings.
require('@electron/internal/common/init');
process._linkedBinding('electron_browser_event_emitter').setEventEmitterPrototype(EventEmitter.prototype);
const parentPort: ParentPort = new ParentPort();
Object.defineProperty(process, 'parentPort', {
enumerable: true,
writable: false,
value: parentPort
});
// Based on third_party/electron_node/lib/internal/worker/io.js
parentPort.on('newListener', (name: string) => {
if (name === 'message' && parentPort.listenerCount('message') === 0) {
parentPort.start();
}
});
parentPort.on('removeListener', (name: string) => {
if (name === 'message' && parentPort.listenerCount('message') === 0) {
parentPort.pause();
}
});
// Finally load entry script.
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main');
const mainEntry = pathToFileURL(entryScript);
runEntryPointWithESMLoader(async (cascadedLoader: any) => {
try {
await cascadedLoader.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);
}
});