-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
esm: add package type wasm #31388
esm: add package type wasm #31388
Conversation
wasm is already a |
@devsnek package types are format mappings, this just adds another set of format mappings to allow files without extensions to be seen as WASM. |
interesting. i guess we should change the logic to just pass whatever value is present straight through to the resolver unless it equals |
@devsnek I think that passing things around to the resolver would be a different API/PR. People have already asked about a |
What I dislike about this change is that
After this lands, there's now a gray area: {
"type": {
"ambiguous javascript": ": "module",
"extension-less": "wasm"
}
} But that opens a whole can of worms about configuring all kinds of file extension mappings. I'm pretty close to saying "do we need to support extension-less wasm"? |
This makes me again question the package.json field additions :( |
@jkrems how is ".js" ambiguous? It has a specified value (which is "module" in this case as you guessed)
The same could have been said about extension-less ESM. I'm not sure how wanting to run a purely WASM application would be considered a bad thing given WASI and the like coming in the future. |
I'm not opposed to support for running a purely WASM application. But the field name is awkward to me. Right now it can be read as "(content) I think I would even prefer if this PR would treat |
We could also just not give .js a format, and then it would error. .mjs and
.cjs would still work. Seems better than forcing a new extension onto WASM
and we could then ask the MIME owner about adding .js if truly desired for
this pr to land.
…On Thu, Jan 16, 2020, 5:19 PM Jan Olaf Krems ***@***.***> wrote:
I'm not opposed to support for running a purely WASM application. But the
field name is awkward to me. Right now it can be read as "(content) type
of inherently ambiguous files like .js and files lacking an extension".
With this change, it's "(content) type of extension-less files and
sometimes also of .js, you have to know from context if that applies".
I think I would even prefer if this PR would treat .js within those
packages as WASM. That would be consistent with what the field currently
does. That wouldn't break people who want to ship a purely WASM app and
everyone else can use .mjs.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#31388?email_source=notifications&email_token=AABZJI4BQSR4RVOO3A7K7YLQ6DTRFA5CNFSM4KH2TNG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJF4YXY#issuecomment-575392863>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABZJI3LS4NSYQV6A2YMEMLQ6DTRFANCNFSM4KH2TNGQ>
.
|
Throwing on |
(See nodejs/modules#283 for a prediction of this inevitable occurrence) |
I do not want the focus of the PR to be on preserving this idea. Already this is not true (see My desire is for the focus of this PR is solely on ensuring we have a way for WASM to be supported at the same level as other first class sources by enabling loading WASM from files without extensions. |
I don’t see the purpose of this. If WASM files are always parse goal Module, then they’re unaffected by the |
Can you clarify? WASM files can be entry points of a program and there it can be nice if we don't force the user experience to be |
You’re talking about from the command line, e.g. |
that there would be a difference is a signal that something is wrong with our resolver. it should behave consistently no matter the placement of a specifier. |
You could've said the same thing for ESM: just create an extension-less CommonJS file and |
I would also like to point out that WASM vs JS is seen as a security concern by some and is part of the discussion of https://github.com/tc39/proposal-module-attributes , to people of that mindset it might be undesirable to have any JS in their application. |
This is really asking for an entirely new feature. Currently all extensionless files are treated as JavaScript, and I think there’s certainly no rush to add such a feature. I’ve never heard discussed that Node would treat anything other than JavaScript as equivalent first-class with JavaScript, and that’s a broader discussion that should be had before we start doing so. Having a one-line |
one of the main design goals of esm is to allow loading resources of any type. if we can load a format, we should be able to load it from any position that source text modules can be loaded from. if it can't be, it's an artificial limitation we should correct. |
That feels like a very blurry definition of a "file type". CommonJS and ES modules are two different file types. They both happen to be text files while WASM is a binary format. But just because both are text (and their syntax has some overlap) doesn't mean they are the same file type. I can also write some CoffeeScript that parses as CommonJS and/or ES modules. Doesn't mean that CoffeeScript isn't a different file type. :) |
Why is this important? Using Having We should probably just drop support for extensionless files in the ESM loader while it’s still experimental. The CommonJS loader will always load such files as CommonJS JavaScript. |
I'm curious about how could |
@targos you can create a binfmt entry: |
#31415 is removing support for any extension-less files and supersedes this for now. A different PR can be opened if other features are found to warrant this feature. |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesThe main benefit of this is to allow files without an extension to be treated as WASM. This does alter the logic for detecting if something should be treated as going through the ESM loader for the main module slightly by inverting the condition from checking for
"module"
to instead check it doesn't match"commonjs"
This remains flagged behind the WASM modules flag