@@ -108,9 +108,12 @@ test('Adds a custom error property to user errors during bundling', async () =>
108108 const messageBeforeStack = ( error as BundleError ) . message
109109 expect (
110110 messageBeforeStack
111- . replace ( / f i l e : \/ \/ \/ ( .* ?\/ ) ( b u i l d \/ p a c k a g e s \/ e d g e - b u n d l e r \/ d e n o \/ v e n d o r \/ d e n o \. l a n d \/ x \/ e s z i p .* ) / , 'file://$2' )
112111 // eslint-disable-next-line no-control-regex
113- . replace ( / [ \u001b \u009b ] [ [ ( ) # ; ? ] * (?: [ 0 - 9 ] { 1 , 4 } (?: ; [ 0 - 9 ] { 0 , 4 } ) * ) ? [ 0 - 9 A - O R Z c f - n q r y = > < ] / g, '' ) ,
112+ . replace ( / [ \u001b \u009b ] [ [ ( ) # ; ? ] * (?: [ 0 - 9 ] { 1 , 4 } (?: ; [ 0 - 9 ] { 0 , 4 } ) * ) ? [ 0 - 9 A - O R Z c f - n q r y = > < ] / g, '' )
113+ . replace (
114+ / f i l e : \/ \/ \/ ( .* ?\/ ) ( b u i l d \/ p a c k a g e s \/ e d g e - b u n d l e r \/ d e n o \/ v e n d o r \/ d e n o \. l a n d \/ x \/ e s z i p .* ) / ,
115+ 'file://$2' ,
116+ ) ,
114117 ) . toMatchSnapshot ( )
115118 expect ( ( error as BundleError ) . customErrorInfo ) . toEqual ( {
116119 location : {
@@ -1309,6 +1312,63 @@ describe.skipIf(lt(denoVersion, '2.4.2'))(
13091312
13101313 await cleanup ( )
13111314 } )
1315+
1316+ test ( 'Importing a remote module that imports a WebAssembly binary (deno_dom)' , async ( ) => {
1317+ // Deno <2.6 vendors `.wasm` imports under a `.d.mts` extension even though
1318+ // the content is the raw WASM binary. The rewriter must detect this by
1319+ // magic bytes and copy the file through untouched instead of attempting
1320+ // to parse it as UTF-8 source.
1321+ const { basePath, cleanup, distPath } = await useFixture ( 'imports_deno_dom_wasm' , { copyDirectory : true } )
1322+ const declarations : Declaration [ ] = [
1323+ {
1324+ function : 'func1' ,
1325+ path : '/func1' ,
1326+ } ,
1327+ ]
1328+ await bundle ( [ join ( basePath , 'netlify/edge-functions' ) ] , distPath , declarations , {
1329+ basePath,
1330+ featureFlags : {
1331+ edge_bundler_generate_tarball : true ,
1332+ } ,
1333+ } )
1334+ const expectedOutput = {
1335+ func1 : 'hello from deno_dom' ,
1336+ }
1337+
1338+ const manifestFile = await readFile ( resolve ( distPath , 'manifest.json' ) , 'utf8' )
1339+ const manifest = JSON . parse ( manifestFile )
1340+
1341+ const tarballPath = join ( distPath , manifest . bundles [ 0 ] . asset )
1342+ const tarballResult = await runTarball ( tarballPath )
1343+ expect ( tarballResult ) . toStrictEqual ( expectedOutput )
1344+
1345+ const entries : string [ ] = [ ]
1346+ await tar . list ( {
1347+ file : tarballPath ,
1348+ onReadEntry : ( entry ) => {
1349+ entries . push ( entry . path )
1350+ } ,
1351+ } )
1352+
1353+ expect ( entries ) . toContain ( './___netlify-edge-functions.json' )
1354+ expect ( entries ) . toContain ( './deno.json' )
1355+ expect ( entries ) . toContain ( './func1.ts' )
1356+
1357+ // The vendored deno_dom WASM payload must be present in the tarball.
1358+ // Deno <2.6 vendors `.wasm` imports under a `.d.mts` extension (with a
1359+ // content-hash suffix); 2.6+ keeps the original `.wasm` extension.
1360+ const denoDomVendorPrefix = './vendor/deno.land/x/deno_dom@v0.1.56/build/deno-wasm/'
1361+ const expectedWasmEntry = lt ( denoVersion , '2.6.0' )
1362+ ? `${ denoDomVendorPrefix } #deno-wasm_bg.wasm_d2792.d.mts`
1363+ : `${ denoDomVendorPrefix } deno-wasm_bg.wasm`
1364+ expect ( entries ) . toContain ( expectedWasmEntry )
1365+
1366+ const eszipPath = join ( distPath , manifest . bundles [ 1 ] . asset )
1367+ const eszipResult = await runESZIP ( eszipPath )
1368+ expect ( eszipResult ) . toStrictEqual ( expectedOutput )
1369+
1370+ await cleanup ( )
1371+ } )
13121372 } ,
1313- 10_000 ,
1373+ 50_000 ,
13141374)
0 commit comments