Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.

Commit 7bca4a9

Browse files
guybedfordMylesBorinsjdalton
committed
esm: irp type implementation
Refs: https://github.com/GeoffreyBooth/node-import-file-specifier-resolution-proposal Refs: nodejs/modules#180 Refs: #6 Refs: #12 Refs: #28 Co-authored-by: Myles Borins <[email protected]> Co-authored-by: John-David Dalton <[email protected]>
1 parent 969c63a commit 7bca4a9

File tree

105 files changed

+1247
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1247
-527
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module.exports = {
3838
{
3939
files: [
4040
'doc/api/esm.md',
41+
'test/es-module/test-esm-type-flag.js',
42+
'test/es-module/test-esm-type-flag-alias.js',
4143
'*.mjs',
4244
'test/es-module/test-esm-example-loader.js',
4345
],

doc/api/cli.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,18 @@ added: v2.4.0
511511

512512
Track heap object allocations for heap snapshots.
513513

514+
### `-m`, `--type=type`
515+
516+
When using `--experimental-modules`, this informs the module resolution type
517+
to interpret the top-level entry into Node.js.
518+
519+
Works with stdin, `--eval`, `--print` as well as standard execution.
520+
521+
Valid values are `"commonjs"` and `"module"`, where the default is to infer
522+
from the file extension and package type boundary.
523+
524+
`-m` is an alias for `--type=module`.
525+
514526
### `--use-bundled-ca`, `--use-openssl-ca`
515527
<!-- YAML
516528
added: v6.11.0
@@ -904,7 +916,7 @@ greater than `4` (its current default value). For more information, see the
904916
[debugger]: debugger.html
905917
[debugging security implications]: https://nodejs.org/en/docs/guides/debugging-getting-started/#security-implications
906918
[emit_warning]: process.html#process_process_emitwarning_warning_type_code_ctor
907-
[experimental ECMAScript Module]: esm.html#esm_loader_hooks
919+
[experimental ECMAScript Module]: esm.html#esm_experimental_loader_hooks
908920
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html
909921
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
910922
[secureProtocol]: tls.html#tls_tls_createsecurecontext_options

doc/api/errors.md

+34-11
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,11 @@ An invalid or unexpected value was passed in an options object.
12671267

12681268
An invalid or unknown file encoding was passed.
12691269

1270+
<a id="ERR_INVALID_PACKAGE_CONFIG"></a>
1271+
### ERR_INVALID_PACKAGE_CONFIG
1272+
1273+
An invalid `package.json` file was found which failed parsing.
1274+
12701275
<a id="ERR_INVALID_PERFORMANCE_MARK"></a>
12711276
### ERR_INVALID_PERFORMANCE_MARK
12721277

@@ -1449,26 +1454,19 @@ a `dynamicInstantiate` hook.
14491454
A `MessagePort` was found in the object passed to a `postMessage()` call,
14501455
but not provided in the `transferList` for that call.
14511456

1452-
<a id="ERR_MISSING_MODULE"></a>
1453-
### ERR_MISSING_MODULE
1454-
1455-
> Stability: 1 - Experimental
1456-
1457-
An [ES6 module][] could not be resolved.
1458-
14591457
<a id="ERR_MISSING_PLATFORM_FOR_WORKER"></a>
14601458
### ERR_MISSING_PLATFORM_FOR_WORKER
14611459

14621460
The V8 platform used by this instance of Node.js does not support creating
14631461
Workers. This is caused by lack of embedder support for Workers. In particular,
14641462
this error will not occur with standard builds of Node.js.
14651463

1466-
<a id="ERR_MODULE_RESOLUTION_LEGACY"></a>
1467-
### ERR_MODULE_RESOLUTION_LEGACY
1464+
<a id="ERR_MODULE_NOT_FOUND"></a>
1465+
### ERR_MODULE_NOT_FOUND
14681466

14691467
> Stability: 1 - Experimental
14701468
1471-
A failure occurred resolving imports in an [ES6 module][].
1469+
An [ESM module][] could not be resolved.
14721470

14731471
<a id="ERR_MULTIPLE_CALLBACK"></a>
14741472
### ERR_MULTIPLE_CALLBACK
@@ -2220,6 +2218,32 @@ A non-specific HTTP/2 error has occurred.
22202218
Used in the `repl` in case the old history file is used and an error occurred
22212219
while trying to read and parse it.
22222220

2221+
<a id="ERR_INVALID_REPL_TYPE"></a>
2222+
### ERR_INVALID_REPL_TYPE
2223+
2224+
> Stability: 1 - Experimental
2225+
2226+
The `--type=...` flag is not compatible with the Node.js REPL.
2227+
2228+
<a id="ERR_TYPE_MISMATCH"></a>
2229+
### ERR_TYPE_MISMATCH
2230+
2231+
> Stability: 1 - Experimental
2232+
2233+
The `--type=commonjs` flag was used to attempt to execute an `.mjs` file or
2234+
a `.js` file where the nearest parent `package.json` contains
2235+
`"type": "module"`; or
2236+
the `--type=module` flag was used to attempt to execute a `.cjs` file or
2237+
a `.js` file where the nearest parent `package.json` either lacks a `"type"`
2238+
field or contains `"type": "commonjs"`.
2239+
2240+
<a id="ERR_INVALID_TYPE_FLAG"></a>
2241+
### ERR_INVALID_TYPE_FLAG
2242+
2243+
> Stability: 1 - Experimental
2244+
2245+
An invalid `--type=...` flag value was provided.
2246+
22232247
<a id="ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK"></a>
22242248
#### ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK
22252249

@@ -2250,7 +2274,6 @@ size.
22502274
This `Error` is thrown when a read is attempted on a TTY `WriteStream`,
22512275
such as `process.stdout.on('data')`.
22522276

2253-
22542277
[`'uncaughtException'`]: process.html#process_event_uncaughtexception
22552278
[`--force-fips`]: cli.html#cli_force_fips
22562279
[`Class: assert.AssertionError`]: assert.html#assert_class_assert_assertionerror

0 commit comments

Comments
 (0)