From 59036110a431262e4568201cbe45cd803a6c23a9 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Wed, 9 Aug 2017 09:31:04 -0500 Subject: [PATCH 1/4] 007: --entry-extension CLI flag proposal --- 000-index.md | 1 + 007-extension-flag.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 007-extension-flag.md diff --git a/000-index.md b/000-index.md index a503542..93f6be6 100644 --- a/000-index.md +++ b/000-index.md @@ -6,3 +6,4 @@ * [Port core to uv_link_t](004-uv_link_t.md) * [ABI Stable Module API](005-ABI-Stable-Module-API.md) * [AsyncHooks API](006-asynchooks-api.md) +* [Extension CLI Flag](007-extension-flag.md) diff --git a/007-extension-flag.md b/007-extension-flag.md new file mode 100644 index 0000000..d55853a --- /dev/null +++ b/007-extension-flag.md @@ -0,0 +1,34 @@ +| 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 Date: Wed, 9 Aug 2017 11:29:43 -0500 Subject: [PATCH 2/4] collision with file path CLI form --- 007-extension-flag.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/007-extension-flag.md b/007-extension-flag.md index d55853a..430b88e 100644 --- a/007-extension-flag.md +++ b/007-extension-flag.md @@ -21,6 +21,15 @@ node --entry-extension=mjs Date: Wed, 9 Aug 2017 12:54:14 -0500 Subject: [PATCH 3/4] another example of collision --- 007-extension-flag.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/007-extension-flag.md b/007-extension-flag.md index 430b88e..4d76fab 100644 --- a/007-extension-flag.md +++ b/007-extension-flag.md @@ -28,6 +28,8 @@ If mixing `--entry-extension` with a non-stream argument such as a file path or ```sh # exits with an error node --entry-extension=json app.js +# exits with an error +node --entry-extension=js app.js ``` ## Alternate Possibilities From 6ad705d08326cfad7410ee7ca08ff74d41c6ae9a Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Sun, 27 Aug 2017 09:22:02 -0500 Subject: [PATCH 4/4] address @ljarb s review --- 007-extension-flag.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/007-extension-flag.md b/007-extension-flag.md index 4d76fab..35e0746 100644 --- a/007-extension-flag.md +++ b/007-extension-flag.md @@ -32,6 +32,18 @@ node --entry-extension=json app.js 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`. + +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. + +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`.