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

Commit

Permalink
fixup: s/type/entry-type doc
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesBorins committed Mar 27, 2019
1 parent 330ab11 commit 3a40599
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 42 deletions.
24 changes: 13 additions & 11 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ conjunction with native stack and other runtime environment data.
added: v6.0.0
-->

### `--entry-type=type`
<!-- YAML
added: REPLACEME
-->

Used with `--experimental-modules`, this configures Node.js to interpret the
initial entry point as CommonJS or as an ES module.

Valid values are `"commonjs"` and `"module"`. The default is to infer from
the file extension and the `"type"` field in the nearest parent `package.json`.

Works for executing a file as well as `--eval`, `--print`, `STDIN`.

Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with
`./configure --openssl-fips`.)

Expand Down Expand Up @@ -556,17 +569,6 @@ added: v2.4.0

Track heap object allocations for heap snapshots.

### `--type=type`

Used with `--experimental-modules`, this configures Node.js to interpret the
initial entry point as CommonJS or as an ES module.

Valid values are `"commonjs"` and `"module"`. The default is to infer from
the file extension and the `"type"` field in the nearest parent `package.json`.

Works for executing a file as well as `--eval`, `--print`, `STDIN`.


### `--use-bundled-ca`, `--use-openssl-ca`
<!-- YAML
added: v6.11.0
Expand Down
33 changes: 13 additions & 20 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2223,26 +2223,7 @@ while trying to read and parse it.

> Stability: 1 - Experimental
The `--type=...` flag is not compatible with the Node.js REPL.

<a id="ERR_TYPE_MISMATCH"></a>
#### ERR_TYPE_MISMATCH

> Stability: 1 - Experimental
The `--type=commonjs` flag was used to attempt to execute an `.mjs` file or
a `.js` file where the nearest parent `package.json` contains
`"type": "module"`; or
the `--type=module` flag was used to attempt to execute a `.cjs` file or
a `.js` file where the nearest parent `package.json` either lacks a `"type"`
field or contains `"type": "commonjs"`.

<a id="ERR_INVALID_TYPE_FLAG"></a>
#### ERR_INVALID_TYPE_FLAG

> Stability: 1 - Experimental
An invalid `--type=...` flag value was provided.
The `--entry-type=...` flag is not compatible with the Node.js REPL.

<a id="ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK"></a>
#### ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK
Expand Down Expand Up @@ -2274,6 +2255,18 @@ size.
This `Error` is thrown when a read is attempted on a TTY `WriteStream`,
such as `process.stdout.on('data')`.

<a id="ERR_TYPE_MISMATCH"></a>
#### ERR_TYPE_MISMATCH

> Stability: 1 - Experimental
The `--entry-type=commonjs` flag was used to attempt to execute an `.mjs` file
or a `.js` file where the nearest parent `package.json` contains
`"type": "module"`; or
the `--entry-type=module` flag was used to attempt to execute a `.cjs` file or
a `.js` file where the nearest parent `package.json` either lacks a `"type"`
field or contains `"type": "commonjs"`.

[`'uncaughtException'`]: process.html#process_event_uncaughtexception
[`--force-fips`]: cli.html#cli_force_fips
[`Class: assert.AssertionError`]: assert.html#assert_class_assert_assertionerror
Expand Down
22 changes: 11 additions & 11 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ loaded as an ES module.
node --experimental-modules my-app.mjs
```

### <code>--type=module</code> flag
### <code>--entry-type=module</code> flag

Files ending with `.js` or `.mjs`, or lacking any extension,
will be loaded as ES modules when the `--type=module` flag is set.
will be loaded as ES modules when the `--entry-type=module` flag is set.

```sh
node --experimental-modules --type=module my-app.js
node --experimental-modules --entry-type=module my-app.js
```

For completeness there is also `--type=commonjs`, for explicitly running a `.js`
file as CommonJS. This is the default behavior if `--type` is
For completeness there is also `--entry-type=commonjs`, for explicitly running
a `.js` file as CommonJS. This is the default behavior if `--entry-type` is
unspecified.

The `--type=module` flag can also be used to configure Node.js to treat
The `--entry-type=module` flag can also be used to configure Node.js to treat
as an ES module input sent in via `--eval` or `--print` (or `-e` or `-p`) or
piped to Node.js via `STDIN`.

```sh
node --experimental-modules --type=module --eval \
node --experimental-modules --entry-type=module --eval \
"import { sep } from 'path'; console.log(sep);"

echo "import { sep } from 'path'; console.log(sep);" | \
node --experimental-modules --type=module
node --experimental-modules --entry-type=module
```

### <code>package.json</code> <code>"type"</code> field
Expand Down Expand Up @@ -419,8 +419,8 @@ The `--experimental-json-modules` flag is needed for the module
to work.
```bash
node --experimental-modules --type=module index.js # fails
node --experimental-modules --type=module --experimental-json-modules index.js # works
node --experimental-modules --entry-type=module index.js # fails
node --experimental-modules --entry-type=module --experimental-json-modules index.js # works
```
## Experimental Loader hooks
Expand Down Expand Up @@ -575,7 +575,7 @@ of these top-level routines.
_isMain_ is **true** when resolving the Node.js application entry point.
When using the `--type` flag, it overrides the ESM_FORMAT result while
When using the `--entry-type` flag, it overrides the ESM_FORMAT result while
providing errors in the case of explicit conflicts.
<details>
Expand Down

0 comments on commit 3a40599

Please sign in to comment.