Skip to content

Commit a1942b0

Browse files
Experiment with async modules
1 parent c59f631 commit a1942b0

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

packages/snaps-cli/src/webpack/config.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ export async function getDefaultConfiguration(
166166
*
167167
* @see https://webpack.js.org/configuration/output/#outputlibrarytarget
168168
*/
169-
type: 'commonjs',
169+
type: 'global',
170+
name: 'exports',
170171
},
171172

172173
/**
@@ -177,7 +178,7 @@ export async function getDefaultConfiguration(
177178
*
178179
* @see https://webpack.js.org/configuration/output/#outputchunkformat
179180
*/
180-
chunkFormat: 'commonjs',
181+
chunkFormat: 'module',
181182
},
182183

183184
/**
@@ -386,14 +387,7 @@ export async function getDefaultConfiguration(
386387
* @see https://webpack.js.org/configuration/experiments
387388
*/
388389
experiments: {
389-
/**
390-
* Experimental support for top level await.
391-
*
392-
* This is unsupported in Snaps and therefore disabled.
393-
*
394-
* @see https://webpack.js.org/configuration/experiments/#experimentstoplevelawait
395-
*/
396-
topLevelAwait: false,
390+
outputModule: true,
397391
},
398392

399393
/**

packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,9 @@ export class BaseSnapExecutor {
416416
compartment.globalThis.global = compartment.globalThis;
417417
compartment.globalThis.window = compartment.globalThis;
418418

419-
await this.executeInSnapContext(snapId, () => {
419+
await this.executeInSnapContext(snapId, async () => {
420420
compartment.evaluate(sourceCode);
421+
await snapModule.exports;
421422
this.registerSnapExports(snapId, snapModule);
422423
});
423424
} catch (error) {

0 commit comments

Comments
 (0)