-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edge runtime also has externals (#6566)
### Description Add externals handling code to edge runtime ### Testing Instructions <!-- Give a quick description of steps to test your changes. --> Closes PACK-2034
- Loading branch information
Showing
11 changed files
with
134 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
crates/turbopack-ecmascript-runtime/js/src/shared-node/node-wasm-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// <reference path="../shared/runtime-utils.ts" /> | ||
|
||
function readWebAssemblyAsResponse(path: string) { | ||
const { createReadStream } = require("fs") as typeof import("fs"); | ||
const { Readable } = require("stream") as typeof import("stream"); | ||
|
||
const stream = createReadStream(path); | ||
|
||
// @ts-ignore unfortunately there's a slight type mismatch with the stream. | ||
return new Response(Readable.toWeb(stream), { | ||
headers: { | ||
"content-type": "application/wasm", | ||
}, | ||
}); | ||
} | ||
|
||
async function compileWebAssemblyFromPath( | ||
path: string | ||
): Promise<WebAssembly.Module> { | ||
const response = readWebAssemblyAsResponse(path); | ||
|
||
return await WebAssembly.compileStreaming(response); | ||
} | ||
|
||
async function instantiateWebAssemblyFromPath( | ||
path: string, | ||
importsObj: WebAssembly.Imports | ||
): Promise<Exports> { | ||
const response = readWebAssemblyAsResponse(path); | ||
|
||
const { instance } = await WebAssembly.instantiateStreaming( | ||
response, | ||
importsObj | ||
); | ||
|
||
return instance.exports; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
...urbopack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
...pack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js.map
Large diffs are not rendered by default.
Oops, something went wrong.