diff options
author | guybedford <guybedford@gmail.com> | 2018-08-28 17:28:46 +0200 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-03-27 15:52:11 -0400 |
commit | b1094dbe19f31f7a69ad16d193748f610b159073 (patch) | |
tree | bb623ea607ed54c27ef36ee9453f5623e19cbb90 /lib/internal/bootstrap/pre_execution.js | |
parent | 39141426d46a7e55d93ad2e8efa12ed86d223522 (diff) | |
download | android-node-v8-b1094dbe19f31f7a69ad16d193748f610b159073.tar.gz android-node-v8-b1094dbe19f31f7a69ad16d193748f610b159073.tar.bz2 android-node-v8-b1094dbe19f31f7a69ad16d193748f610b159073.zip |
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>
Diffstat (limited to 'lib/internal/bootstrap/pre_execution.js')
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 820d931575..20b362f213 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -323,6 +323,10 @@ function initializeESMLoader() { const userLoader = getOptionValue('--loader'); // If --loader is specified, create a loader with user hooks. Otherwise // create the default loader. + if (userLoader) { + const { emitExperimentalWarning } = require('internal/util'); + emitExperimentalWarning('--loader'); + } esm.initializeLoader(process.cwd(), userLoader); } } |