forked from nodejs/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Edit of minimal kernel doc #2
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
Merged
MylesBorins
merged 6 commits into
MylesBorins:minimal-kernel
from
GeoffreyBooth:minimal-kernel
Sep 20, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
79d8fff
Rewrite: emphasize that minimal kernel is just the first phase of a m…
GeoffreyBooth 6148b83
Revisions per Myles' notes
GeoffreyBooth 7392f9f
Move up features that are already part of the existing implementation
GeoffreyBooth d79cad9
Don't name formats
GeoffreyBooth 1ec5469
Remove specific later phases plans
GeoffreyBooth 7597e0b
some minor changes to satisfy myles
MylesBorins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Plan for New Modules Implementation | ||
|
||
This document outlines the plan for building a new implementation to support ECMAScript modules in Node.js. The general idea is to start with a “minimal kernel” as Phase 1, which consists of features that the @nodejs/modules group have agreed will be necessary for all potential iterations of our ESM implementation. Phase 1 does _not_ include features that preclude other potential features or implementation approaches; and Phase 1 also does not include some features that should naturally be built in a later phase of development, for example because those features depend on features planned for Phase 1. The minimal kernel/phase 1 is _not_ intended to be merged into Node core or released; it is only a starting point for gradually building layers of consensus. | ||
|
||
At every phase, the following standards must be maintained: | ||
|
||
* Spec compliance ([#132](https://github.com/nodejs/modules/issues/132)): We must always follow the ES spec. | ||
* Browser equivalence ([#133](https://github.com/nodejs/modules/issues/133)): There’s room for debate in specific cases, but in general if Node is doing something that browsers also do, Node should do it in the same way. Alternatively, code that executes in both environments should produce identical results. | ||
* Don’t break CommonJS ([#112](https://github.com/nodejs/modules/issues/112)): We cannot cause breaking changes with regards to CommonJS. | ||
|
||
See also the [features list in the README](https://github.com/nodejs/modules#features). | ||
|
||
## Phase 1: The Minimal Kernel | ||
|
||
These features will be part of the first phase of development: | ||
|
||
* `module.createRequireFromPath` ([nodejs/node#19360](https://github.com/nodejs/node/pull/19360)) is the only way to import CommonJS into an ES module, for now. | ||
- `import.meta.require` fails at runtime as opposed to import time. This is not desireable to all committee members | ||
- Hold off on `import` statements for CommonJS until more progress is made on the dynamic modules spec. | ||
- landed in https://github.com/nodejs/node/commit/246f6332e5a5f395d1e39a3594ee5d6fe869d622 | ||
|
||
* `import` statements will only support files with an `.mjs` extension, and will import only ES modules, for now. | ||
- In a later phase, the intention is to move forward with format databases to map extensions and support multiple use cases. | ||
- No JSON or native modules; `createRequireFunction` can be used to get these. | ||
|
||
* `import.meta.url`. | ||
- Already in the existing implementation. | ||
|
||
* Dynamic `import()`. | ||
- Already in the existing implementation. | ||
|
||
|
||
### How will we get from where we are to Phase 1 | ||
|
||
* Remove support in the `import` statement of formats other than ESM: | ||
- No CommonJS. | ||
- No JSON. | ||
- No native modules. | ||
- Implemented in https://github.com/nodejs/ecmascript-modules/pull/3 | ||
|
||
* Remove dynamic path searching: | ||
- No extension adding. | ||
- No directory resolution, including no support for `index.js` or `index.mjs`. | ||
- No support for `main` field for ESM. | ||
- Implemented in https://github.com/nodejs/ecmascript-modules/pull/2 | ||
|
||
|
||
## Later Phases | ||
|
||
There **will** be future phases. We will **not** ship the code produced by Phase 1. This first phase lacks support for important use cases and will not be released as the new modules implementation. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was not part of the initial decision on the minimal kernel. Have real mixed feelings about removing this, but can understand why we may not want to make this decision right now, especially if we are going to use another keyword. I'd rather punt this conversation to review on the original PR rather than making the decision here
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 put this here because I was assuming there would be no bare imports resolution algorithm of any kind (not
require
‘s algorithm nor package name maps) in Phase 1. If there are no bare imports in Phase 1, of what use is amain
field?Don’t be like everyone else concerned that their priority isn’t part of the minimal kernel. 😄 Obviously we’ll have some way to do bare imports in the final implementation. It doesn’t need to be in Phase 1, and probably shouldn’t, since figuring it out will take a lot of discussion. I think it’s more important to show progress and get a Phase 1 nailed down than get sidetracked on bare imports for weeks.
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.
bare imports + main is not the require algorithm.
This was what was discussed and in the original document. From the conversation we initially had (me + @bmeck + @guybedford) it was discussed that any implementation, including the browsers, would require bare imports to be useful. A practical argument against this for right now is that we don't have consensus for main, so it would make sense to potentially drop.
I see where you are coming from this but don't find this particular kind of rhetoric helpful or productive. Say what you need to say from a technical stand point and don't make it personal.
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.
Of course it would. But again, we’re not shipping Phase 1, are we? So Phase 1 doesn’t need to be useful in a technical sense. Phase 1 will be useful that it will start to establish consensus and show that we can make forward progress, and give people a starting point for further PRs. There absolutely is value in pulling together a single commit on the repo that does that, even if it lacks support for huge obvious use cases that we all agree need to be covered in a final release.
I think “whatever we can merge together right now without needing further debate” is a good dividing line for what goes into Phase 1 versus later on. And if Phase 1 is incomplete technically, that’s all the better, in that it reassures everyone that there will be later phases.
Uh oh!
There was an error while loading. Please reload this page.
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.
Supporting th
main
field for ESM at this point doesn't make a lot of sense in my point of view since 99.9% of existingmain
fields are CJS and one would have to explicitly write an ESM package to make it work, which I hope isn't the final intend. It's very confusing and in the worst case leads to folks starting to publishname-esm
packages for 'testing proposes or 'because that's whatnode
does now'.pkg.module
is already a thing for tooling and while it shouldn't be final to support it in the future it would definitely be sufficient for testing atm. Otherwise it's better to not support anything related topackage.json
and the NRA (Node Resolution Algorithm) in the first iteration of the minimal kernel (for ESM)