0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/es-module
guybedford b1094dbe19
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 https://github.com/whatwg/html/issues/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: https://github.com/nodejs/modules/pull/180
Refs: https://github.com/nodejs/ecmascript-modules/pull/6
Refs: https://github.com/nodejs/ecmascript-modules/pull/12
Refs: https://github.com/nodejs/ecmascript-modules/pull/28
Refs: https://github.com/nodejs/modules/issues/255
Refs: https://github.com/whatwg/html/issues/4315
Refs: https://github.com/w3c/webcomponents/issues/770
Co-authored-by: Myles Borins <MylesBorins@google.com>
Co-authored-by: John-David Dalton <john.david.dalton@gmail.com>
Co-authored-by: Evan Plaice <evanplaice@gmail.com>
Co-authored-by: Geoffrey Booth <webmaster@geoffreybooth.com>
Co-authored-by: Michaël Zasso <targos@protonmail.com>

PR-URL: https://github.com/nodejs/node/pull/26745
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
2019-03-27 15:52:11 -04:00
..
es-module.status
test-esm-basic-imports.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-cjs-main.js test: refactor stdio handling in test-esm-cjs-main 2018-12-27 08:32:15 +01:00
test-esm-cyclic-dynamic-import.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-double-encoding.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-dynamic-import.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-encoded-path-native.js
test-esm-encoded-path.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-error-cache.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-example-loader.js test: move ESM fixtures to fixtures dir 2018-03-21 20:08:30 +01:00
test-esm-forbidden-globals.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-import-meta.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-json-cache.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-json.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-live-binding.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-loader-dependency.mjs test: move ESM fixtures to fixtures dir 2018-03-21 20:08:30 +01:00
test-esm-loader-invalid-format.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-loader-invalid-url.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-loader-missing-dynamic-instantiate-hook.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-loader-modulemap.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-loader-search.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-main-lookup.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-named-exports.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-namespace.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-no-extension.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-preserve-symlinks-main.js benchmark,doc,lib: capitalize more comments 2019-03-27 17:20:06 +01:00
test-esm-preserve-symlinks-not-found-plain.mjs lint: move eslint to new plugin system 2018-02-20 13:13:22 -06:00
test-esm-preserve-symlinks-not-found.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-preserve-symlinks.js test: move ESM fixtures to fixtures dir 2018-03-21 20:08:30 +01:00
test-esm-process.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-require-cache.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-resolve-hook.mjs test: move ESM fixtures to fixtures dir 2018-03-21 20:08:30 +01:00
test-esm-shared-loader-dep.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-shebang.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-snapshot.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-specifiers.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-symlink-main.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-symlink-type.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-symlink.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-throw-undefined.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-type-flag-errors.js esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
test-esm-type-flag.mjs esm: phase two of new esm implementation 2019-03-27 15:52:11 -04:00
testcfg.py test: run ESM tests in parallel 2018-08-04 18:14:13 +02:00