Skip to content

Commit

Permalink
Experiment with async modules
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Dec 2, 2024
1 parent c59f631 commit a1942b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
14 changes: 4 additions & 10 deletions packages/snaps-cli/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export async function getDefaultConfiguration(
*
* @see https://webpack.js.org/configuration/output/#outputlibrarytarget
*/
type: 'commonjs',
type: 'global',
name: 'exports',
},

/**
Expand All @@ -177,7 +178,7 @@ export async function getDefaultConfiguration(
*
* @see https://webpack.js.org/configuration/output/#outputchunkformat
*/
chunkFormat: 'commonjs',
chunkFormat: 'module',
},

/**
Expand Down Expand Up @@ -386,14 +387,7 @@ export async function getDefaultConfiguration(
* @see https://webpack.js.org/configuration/experiments
*/
experiments: {
/**
* Experimental support for top level await.
*
* This is unsupported in Snaps and therefore disabled.
*
* @see https://webpack.js.org/configuration/experiments/#experimentstoplevelawait
*/
topLevelAwait: false,
outputModule: true,
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,9 @@ export class BaseSnapExecutor {
compartment.globalThis.global = compartment.globalThis;
compartment.globalThis.window = compartment.globalThis;

await this.executeInSnapContext(snapId, () => {
await this.executeInSnapContext(snapId, async () => {
compartment.evaluate(sourceCode);
await snapModule.exports;
this.registerSnapExports(snapId, snapModule);
});
} catch (error) {
Expand Down

0 comments on commit a1942b0

Please sign in to comment.