Skip to content

Commit

Permalink
module: print location of unsettled top-level await in entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed May 10, 2024
1 parent e3ece91 commit 0059ab0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/browser/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ delete process.appCodeLoaded;
if (packagePath) {
// Finally load app's main.js and transfer control to C++.
if ((packageJson.type === 'module' && !mainStartupScript.endsWith('.cjs')) || mainStartupScript.endsWith('.mjs')) {
const { loadESM } = __non_webpack_require__('internal/process/esm_loader');
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main');
const main = (require('url') as typeof url).pathToFileURL(path.join(packagePath, mainStartupScript));
loadESM(async (esmLoader: any) => {
runEntryPointWithESMLoader(async (cascadedLoader: any) => {
try {
await esmLoader.import(main.toString(), undefined, Object.create(null));
await cascadedLoader.import(main.toString(), undefined, Object.create(null));
appCodeLoaded!();
} catch (err) {
appCodeLoaded!();
Expand Down
6 changes: 3 additions & 3 deletions lib/renderer/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ if (cjsPreloads.length) {
}
}
if (esmPreloads.length) {
const { loadESM } = __non_webpack_require__('internal/process/esm_loader');
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main');

loadESM(async (esmLoader: any) => {
runEntryPointWithESMLoader(async (cascadedLoader: any) => {
// Load the preload scripts.
for (const preloadScript of esmPreloads) {
await esmLoader.import(pathToFileURL(preloadScript).toString(), undefined, Object.create(null)).catch((err: Error) => {
await cascadedLoader.import(pathToFileURL(preloadScript).toString(), undefined, Object.create(null)).catch((err: Error) => {
console.error(`Unable to load preload script: ${preloadScript}`);
console.error(err);

Expand Down
7 changes: 4 additions & 3 deletions lib/utility/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ parentPort.on('removeListener', (name: string) => {
});

// Finally load entry script.
const { loadESM } = __non_webpack_require__('internal/process/esm_loader');
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main');
const mainEntry = pathToFileURL(entryScript);
loadESM(async (esmLoader: any) => {

runEntryPointWithESMLoader(async (cascadedLoader: any) => {
try {
await esmLoader.import(mainEntry.toString(), undefined, Object.create(null));
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
Expand Down

0 comments on commit 0059ab0

Please sign in to comment.