-
-
Couldn't load subscription status.
- Fork 66
007: --entry-extension CLI flag proposal #62
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| | Title | Implement --extension flag | | ||
| |--------|-----------------------------| | ||
| | Author | @bmeck | | ||
| | Status | DRAFT | | ||
| | Date | 2017-08-09T10:00:00-05:00 | | ||
|
|
||
| ## Description | ||
|
|
||
| The Node CLI currently accepts input in both filename (`node app.js`) and opaque text stream form (`node -e '123'` and `node <app.js`). This behavior always results in running the stream as a CommonJS goal. With the upcoming usage of ESM and WASM there will be cases where developers wish to pipe other forms of text to the CLI. | ||
|
|
||
| This proposal is to implement an `--entry-extension` CLI flag for the cases which may want to use a stream that does not have a file extension. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are defining the name here, might be worthwhile to also specify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have any abbreviates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure but I don't really see an issue with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use that, I suppose. Does it have any common UNIX meaning it might be confused with? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ## Example | ||
|
|
||
| ```sh | ||
| node --entry-extension=js <app.js | ||
| node --entry-extension=js -e $(cat <app.js) | ||
| node --entry-extension=wasm <app.wasm | ||
| node --entry-extension=wasm -e $(cat <app.wasm) | ||
| node --entry-extension=mjs <app.mjs | ||
| node --entry-extension=mjs -e $(cat <app.mjs) | ||
| ``` | ||
|
|
||
| ## Considerations | ||
|
|
||
| If mixing `--entry-extension` with a non-stream argument such as a file path or entry URL, Node should exit with an error prior to any evaluation. This also means that `--entry-extension` cannot be used to override the extension of file paths. | ||
|
|
||
| ```sh | ||
| # exits with an error | ||
| node --entry-extension=json app.js | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be a good example to add so that people don't think it's the mismatch that errors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely a good example since most of the feedback so far has been above this :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
| # exits with an error | ||
| node --entry-extension=js app.js | ||
| ``` | ||
|
|
||
| ### Userland Extensions | ||
|
|
||
| Some libraries extend `require.extensions` with new extensions. These libraries should be considered when determining the list of extensions allowed in `--entry-extension`. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this work? Only for preload modules I suppose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Only preload would affect this. |
||
|
|
||
| Any future extensions to the ESM based loading mechanisms will have to account for collisions and define behavior when they collide. | ||
|
|
||
| ### Early Errors | ||
|
|
||
| Any unknown file extension should prevent the main entry point to the program from executing anything. Preloaded files such as using `--require` should continue to load normally. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any concept of preloading files, but with a different entry extension? In other words, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ljharb not currently, use a wrapper for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, but Perhaps we should have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK, |
||
|
|
||
| Any error produced by this should describe how to get the list of known extensions; and the error should attempt to point towards how to add an extension if needed. The error may change from preferring `require.extensions` to a new mechanism that supports ESM over time. | ||
|
|
||
| ## Alternate Possibilities | ||
|
|
||
| Some alternate possibilities exist that might be relevant. `--entry-url` for example could be used to provide an `import.meta.url` properly while also providing the pathname that contains an extension. However, since URLs are not mandated to have file extensions this might be for nothing. Applications can also access `process.cwd()` to recreate similar data to `import.meta.url`. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems far less intuitive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, not suggested. |
||
|
|
||
| ## APIs | ||
|
|
||
| No new runtime APIs are to be added. | ||
|
|
||
| ## Future considerations | ||
|
|
||
| Some upcoming file formats are also proposed such as [WebPackage](https://github.com/WICG/webpackage) that would also benefit from this. | ||
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.
Script goaland maybe alsoother program forms to the CLIThere 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.
On second thought, I suppose that last one could also be clarified as
source textif that is more consistent.