new ESM implementation #26745
esm: phase two of new esm implementation
This PR updates the current `--experimental-modules` implementation based on the work of the modules team and reflects Phase 2 of our new modules plan. The largest differences from the current implementation include * `packge.type` which can be either `module` or `commonjs` - `type: "commonjs"`: - `.js` is parsed as commonjs - default for entry point without an extension is commonjs - `type: "module"`: - `.js` is parsed as esm - does not support loading JSON or Native Module by default - default for entry point without an extension is esm * `--entry-type=[mode]` - allows you set the type on entry point. * A new file extension `.cjs`. - this is specifically to support importing commonjs in the `module` mode. - this is only in the esm loader, the commonjs loader remains untouched, but the extension will work in the old loader if you use the full file path. * `--es-module-specifier-resolution=[type]` - options are `explicit` (default) and `node` - by default our loader will not allow for optional extensions in the import, the path for a module must include the extension if there is one - by default our loader will not allow for importing directories that have an index file - developers can use `--es-module-specifier-resolution=node` to enable the commonjs specifier resolution algorithm - This is not a “feature” but rather an implementation for experimentation. It is expected to change before the flag is removed * `--experimental-json-loader` - the only way to import json when `"type": "module"` - when enable all `import 'thing.json'` will go through the experimental loader independent of mode - based on whatwg/html#4315 * You can use `package.main` to set an entry point for a module - the file extensions used in main will be resolved based on the `type` of the module Refs: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md Refs: https://github.com/GeoffreyBooth/node-import-file-specifier-resolution-proposal Refs: nodejs/modules#180 Refs: nodejs/ecmascript-modules#6 Refs: nodejs/ecmascript-modules#12 Refs: nodejs/ecmascript-modules#28 Refs: nodejs/modules#255 Refs: whatwg/html#4315 Refs: w3c/webcomponents#770 Co-authored-by: Myles Borins <MylesBorins@google.com> Co-authored-by: John-David Dalton <firstname.lastname@example.org> Co-authored-by: Evan Plaice <email@example.com> Co-authored-by: Geoffrey Booth <firstname.lastname@example.org> Co-authored-by: Michaël Zasso <email@example.com> PR-URL: #26745 Reviewed-By: Gus Caplan <firstname.lastname@example.org> Reviewed-By: Guy Bedford <email@example.com> Reviewed-By: Ben Coe <firstname.lastname@example.org> Reviewed-By: James M Snell <email@example.com> Reviewed-By: Joyee Cheung <firstname.lastname@example.org> Reviewed-By: Ruben Bridgewater <email@example.com> Reviewed-By: Сковорода Никита Андреевич <firstname.lastname@example.org>
- Loading branch information...
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
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.