Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
esm: --experimental-default-type flag to flip module defaults#49869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c7b6685e2bfe8ad51cabce2532317feafa5ebc5795f4d936774fed342a9612573ff39a70366fb9b3b7c47075fcdb1c3ac2d0939f06497dbe6b1a515d6820034c5238d3874795f79c9e18e354e03da79321f93d5eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,9 +2,12 @@ | ||
| const { | ||
| RegExpPrototypeExec, | ||
| Uint8Array, | ||
| } = primordials; | ||
| const { getOptionValue } = require('internal/options'); | ||
| const { closeSync, openSync, readSync } = require('fs'); | ||
| const experimentalWasmModules = getOptionValue('--experimental-wasm-modules'); | ||
| const extensionFormatMap = { | ||
| @@ -35,7 +38,33 @@ function mimeToFormat(mime) { | ||
| return null; | ||
| } | ||
| /** | ||
| * For extensionless files in a `module` package scope, or a default `module` scope enabled by the | ||
| * `--experimental-default-type` flag, we check the file contents to disambiguate between ES module JavaScript and Wasm. | ||
| * We do this by taking advantage of the fact that all Wasm files start with the header `0x00 0x61 0x73 0x6d` (`_asm`). | ||
| * @param {URL} url | ||
| */ | ||
| function getFormatOfExtensionlessFile(url) { | ||
| if (!experimentalWasmModules) { return 'module'; } | ||
| const magic = new Uint8Array(4); | ||
| let fd; | ||
| try { | ||
| // TODO(@anonrig): Optimize the following by having a single C++ call | ||
| fd = openSync(url); | ||
| readSync(fd, magic, 0, 4); // Only read the first four bytes | ||
| if (magic[0] === 0x00 && magic[1] === 0x61 && magic[2] === 0x73 && magic[3] === 0x6d) { | ||
| return 'wasm'; | ||
| } | ||
GeoffreyBooth marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| } finally { | ||
| if (fd !== undefined) { closeSync(fd); } | ||
| } | ||
| return 'module'; | ||
| } | ||
| module.exports = { | ||
| extensionFormatMap, | ||
| getFormatOfExtensionlessFile, | ||
| mimeToFormat, | ||
| }; | ||
GeoffreyBooth marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.