-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
module: add --experimental-ext #59840
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
Conversation
|
Review requested:
|
62bee79 to
2587b9a
Compare
2587b9a to
d5a9da7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59840 +/- ##
==========================================
+ Coverage 88.28% 88.29% +0.01%
==========================================
Files 701 701
Lines 206774 206841 +67
Branches 39772 39792 +20
==========================================
+ Hits 182545 182635 +90
+ Misses 16234 16233 -1
+ Partials 7995 7973 -22
🚀 New features to boost your workflow:
|
|
Shouldn't this be more about "the format" instead of "the extension"? The extension does not necessarily accurately identify the format (in the case of .js and .ts, they are both ambiguous extensions that lead to the hoops of module format detections) On that note this seems to be overlapping with |
GeoffreyBooth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is misguided, for the reasons I gave in #59565 (comment) and in previous linked issues: many platforms don’t support flags in shebang lines, so for all those platforms the goal of this flag—to allow extensionless TypeScript files—won’t be achieved, and the feature will feel broken.
A better solution is to build on what we achieved with syntax detection, where if a file fails to evaluate as CommonJS and then fails to evaluate as ESM and then succeeds as TypeScript, it runs as TypeScript. This not only will work everywhere, it doesn’t require a new flag or opting in.
|
@GeoffreyBooth what you are saying is unfortunately not possible to do smoothly for Typescript. fetch<Object>("example.org")is valid js and produces To answer @joyeecheung this should be pretty similar to |
tbh the same argument can be made for ESM detection (e.g. |
|
I'm not saying it is not possible, we are already doing this for eval. I'm saying that a flag to change the default behavior "saying execute this as ts and not as js" is still needed. So the detection can come first (I might open a PR for it) but we still can discuss how to implement this format ovveride |
|
It sounds like the |
|
If someone wants to pickup ts detection I started looking into it marco-ippolito@995b47d but going on PTO for the next 2 weeks |
|
FWIW I think no matter what we do, the new hoops should only apply to files without any extension. For example, it should not apply TypeScript syntax detection on .js files - that does have an extension. Or forcing .js files to get executed as TypeScript. That sounds like a can of worms. |
I don't think a flag for this purpose is needed. The only case that's not currently already handled is extensionless TypeScript files, and I think it's okay to ask people to use unambiguously TypeScript syntax in extensionless files if they want their extensionless TypeScript file to work. That's better than asking them to try to use a flag but then the flag doesn't work in their shebang line and they open a bug with us and we tell them that their operating system doesn't support flags in shebang lines, and the user is frustrated. It's a very unusual TypeScript file that could be ambiguously JavaScript, so the case where the user would need to go back and add something unambiguously TypeScript in order to force the correct detection is unlikely to happen in real world scenarios. |
Fixes: #59565
This PR adds the flag
--experimental-ext=ext.This flag overrides the entrypoint extension module resolution.
Immagine you are trying to run an extensionless file with typescript content.
By default extensionless files or unknown extensions are never treated as ts so it's not possible to run it.
With this flag it is possible to override it:
The override only applies to the entrypoint and not for the whole graph.
With typescript support this becomes necessary while a few years ago when there was some discussion #23868 (comment) this wasnt the case.