Skip to content

Commit

Permalink
feat: 14.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
h7lin committed Oct 8, 2020
1 parent 3e71cd2 commit 3c2a768
Show file tree
Hide file tree
Showing 56 changed files with 535 additions and 367 deletions.
2 changes: 1 addition & 1 deletion async_hooks/asynchook_enable.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Returns: {AsyncHook} A reference to `asyncHook`.

Enable the callbacks for a given `AsyncHook` instance. If no callbacks are
provided enabling is a noop.
provided, enabling is a no-op.

The `AsyncHook` instance is disabled by default. If the `AsyncHook` instance
should be enabled immediately after creation, the following pattern can be used.
Expand Down
10 changes: 7 additions & 3 deletions child_process/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ ls.on('close', (code) => {
这与 shell 中的管道的行为相同。
如果不消费输出,则使用 `{ stdio: 'ignore' }` 选项。

如果传入 `options` 对象,则会使用 `options.env.PATH` 环境变量来执行命令查找,否则会使用 `process.env.PATH`
考虑到 Windows 的环境变量不区分大小写,Node.js 会按字典顺序对所有 `env` 的键进行排序,并且不区分大小写地选择第一个匹配的 `PATH` 来执行命令查找。
当传给 `env` 选项的对象具有多个 `PATH` 变量时,在 Windows 上可能会出现问题。
如果 `options` 对象中有 `options.env.PATH` 环境变量,则使用它来执行命令查找。
否则,则使用 `process.env.PATH`

Windows 上,环境变量不区分大小写。
Node.js 按字典顺序对 `env` 的键进行排序,并使用不区分大小写的第一个键。
只有第一个(按字典顺序)条目会被传给子流程。
当传给 `env` 选项的对象具有多个相同键名的变量时(例如 `PATH` `Path`),在 Windows 上可能会出现问题。

[`child_process.spawn()`] 方法会异步地衍生子进程,且不阻塞 Node.js 事件循环。
[`child_process.spawnSync()`] 函数则以同步的方式提供了等效的功能,但会阻塞事件循环直到衍生的进程退出或被终止。
Expand Down
4 changes: 2 additions & 2 deletions console/console_time_label.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ added: v0.1.104

启动一个计时器,用以计算一个操作的持续时间。
计时器由一个唯一的 `label` 标识。
当调用 [`console.timeEnd()`] 时,可以使用相同的 `label` 来停止计时器,并以毫秒为单位将持续时间输出到 `stdout`
计时器持续时间精确到亚毫秒
当调用 [`console.timeEnd()`] 时,可以使用相同的 `label` 来停止计时器,并以合适的时间单位将持续时间输出到 `stdout`
例如,如果持续时间为 3869 毫秒,则 `console.timeEnd()` 显示 "3.869s"

3 changes: 3 additions & 0 deletions console/console_timeend_label.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!-- YAML
added: v0.1.104
changes:
- version: v13.0.0
pr-url: https://github.com/nodejs/node/pull/29251
description: The elapsed time is diplayed with a suitable time unit.
- version: v6.0.0
pr-url: https://github.com/nodejs/node/pull/5901
description: This method no longer supports multiple calls that don’t map
Expand Down
2 changes: 1 addition & 1 deletion esm/builtin_modules.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[Core modules][] will provide named exports of their public API. A
[Core modules][] provide named exports of their public API. A
default export is also provided which is the value of the CommonJS exports.
The default export can be used for, among other things, modifying the named
exports. Named exports of builtin modules are updated only by calling
Expand Down
16 changes: 8 additions & 8 deletions esm/commonjs_namespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ console.log(cjs === cjsSugar);
// true
```

The ECMAScript Module Namespace representation of a CommonJS module will always
be a namespace with a `default` export key pointing to the CommonJS
The ECMAScript Module Namespace representation of a CommonJS module is always
a namespace with a `default` export key pointing to the CommonJS
`module.exports` value.

This Module Namespace Exotic Object can be directly observed either when using
Expand All @@ -36,19 +36,19 @@ console.log(m === await import('cjs'));
// true
```

For better compatibility with existing usage in the JS ecosystem, Node.js will
in addition attempt to determine the CommonJS named exports of every imported
For better compatibility with existing usage in the JS ecosystem, Node.js
in addition attempts to determine the CommonJS named exports of every imported
CommonJS module to provide them as separate ES module exports using a static
analysis process.

For example, a CommonJS module written:
For example, consider a CommonJS module written:

```js
// cjs.cjs
exports.name = 'exported';
```

will support named imports in ES modules:
The preceding module supports named imports in ES modules:

<!-- eslint-disable no-duplicate-imports -->
```js
Expand All @@ -72,8 +72,8 @@ directly on the ES module namespace when the module is imported.
Live binding updates or new exports added to `module.exports` are not detected
for these named exports.

The detection of named exports is based on common syntax patterns but will not
always correctly detect named exports, in these cases using the default
The detection of named exports is based on common syntax patterns but does not
always correctly detect named exports. In these cases, using the default
import form described above can be a better option.

Named exports detection covers many common export patterns, reexport patterns
Expand Down
6 changes: 3 additions & 3 deletions esm/data_imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ added: v12.10.0

* `text/javascript` for ES Modules
* `application/json` for JSON
* `application/wasm` for WASM.
* `application/wasm` for Wasm

`data:` URLs only resolve [_Bare specifiers_][Terminology] for builtin modules
and [_Absolute specifiers_][Terminology]. Resolving
[_Relative specifiers_][Terminology] will not work because `data:` is not a
[_Relative specifiers_][Terminology] does not work because `data:` is not a
[special scheme][]. For example, attempting to load `./foo`
from `data:text/javascript,import "./foo";` will fail to resolve since there
from `data:text/javascript,import "./foo";` fails to resolve because there
is no concept of relative resolution for `data:` URLs. An example of a `data:`
URLs being used is:
Expand Down
2 changes: 1 addition & 1 deletion esm/enabling.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Node.js treats JavaScript code as CommonJS modules by default.
Authors can tell Node.js to treat JavaScript code as ECMAScript modules
via the `.mjs` file extension, the `package.json` [`"type"`][] field, or the
`--input-type` flag. See
[Modules: Packages](packages.html#packages_determining_module_system) for more
[Modules: Packages](packages.md#packages_determining_module_system) for more
details.

<!-- Anchors to make sure old links find a target -->
Expand Down
8 changes: 4 additions & 4 deletions esm/experimental_json_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ and are loaded using the CJS loader. [WHATWG JSON modules specification][] are
still being standardized, and are experimentally supported by including the
additional flag `--experimental-json-modules` when running Node.js.

When the `--experimental-json-modules` flag is included both the
`commonjs` and `module` mode will use the new experimental JSON
loader. The imported JSON only exposes a `default`, there is no
When the `--experimental-json-modules` flag is included, both the
`commonjs` and `module` mode use the new experimental JSON
loader. The imported JSON only exposes a `default`. There is no
support for named exports. A cache entry is created in the CommonJS
cache, to avoid duplication. The same object will be returned in
cache to avoid duplication. The same object is returned in
CommonJS if the JSON module has already been imported from the
same path.

Expand Down
2 changes: 1 addition & 1 deletion esm/getformat_url_context_defaultgetformat.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Note: These types all correspond to classes defined in ECMAScript.
* The specific [`TypedArray`][] object is a [`Uint8Array`][].
Note: If the source value of a text-based format (i.e., `'json'`, `'module'`) is
not a string, it will be converted to a string using [`util.TextDecoder`][].
not a string, it is converted to a string using [`util.TextDecoder`][].
```js
/**
Expand Down
8 changes: 4 additions & 4 deletions esm/getglobalpreloadcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

* Returns: {string}

Sometimes it can be necessary to run some code inside of the same global scope
that the application will run in. This hook allows to return a string that will
be ran as sloppy-mode script on startup.
Sometimes it might be necessary to run some code inside of the same global scope
that the application runs in. This hook allows the return of a string that is
run as sloppy-mode script on startup.

Similar to how CommonJS wrappers work, the code runs in an implicit function
scope. The only argument is a `require`-like function that can be used to load
builtins like "fs": `getBuiltin(request: string)`.

If the code needs more advanced `require` features, it will have to construct
If the code needs more advanced `require` features, it has to construct
its own `require` using `module.createRequire()`.

```js
Expand Down
10 changes: 3 additions & 7 deletions esm/https_loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffee
console.log(VERSION);
```

With this loader, running:

```bash
node --experimental-loader ./https-loader.mjs ./main.mjs
```

Will print the current version of CoffeeScript per the module at the URL in
With the preceding loader, running
`node --experimental-loader ./https-loader.mjs ./main.mjs`
prints the current version of CoffeeScript per the module at the URL in
`main.mjs`.

21 changes: 21 additions & 0 deletions esm/modules_ecmascript_modules.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@

<!--introduced_in=v8.5.0-->
<!-- type=misc -->
<!-- YAML
added: v8.5.0
changes:
- version:
- v14.13.0
pr-url: https://github.com/nodejs/node/pull/35249
description: Support for detection of CommonJS named exports.
- version: v14.8.0
pr-url: https://github.com/nodejs/node/pull/34558
description: Unflag Top-Level Await.
- version:
- v13.2.0
- v12.17.0
pr-url: https://github.com/nodejs/node/pull/29866
description: Loading ECMAScript modules no longer requires a command-line flag.
- version: v12.0.0
pr-url: https://github.com/nodejs/node/pull/26745
description:
Add support for ES modules using `.js` file extension via `package.json`
`"type"` field.
-->

> Stability: 1 - Experimental

2 changes: 1 addition & 1 deletion esm/no_require_resolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from which to resolve from:
})();
```

This function is asynchronous since the ES module resolver in Node.js is
This function is asynchronous because the ES module resolver in Node.js is
asynchronous. With the introduction of [Top-Level Await][], these use cases
will be easier as they won't require an async function wrapper.

13 changes: 13 additions & 0 deletions esm/node_imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!-- YAML
added: v14.13.1
-->

`node:` URLs are supported as a means to load Node.js builtin modules. This
URL scheme allows for builtin modules to be referenced by valid absolute URL
strings.

```js
import fs from 'node:fs/promises';
```

2 changes: 1 addition & 1 deletion esm/packages.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

This section was moved to [Modules: Packages](packages.html).
This section was moved to [Modules: Packages](packages.md).

2 changes: 1 addition & 1 deletion esm/resolve_specifier_context_defaultresolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `conditions` property on the `context` is an array of conditions for
for looking up conditional mappings elsewhere or to modify the list when calling
the default resolution logic.

The current [package exports conditions][Conditional Exports] will always be in
The current [package exports conditions][Conditional Exports] are always in
the `context.conditions` array passed into the hook. To guarantee _default
Node.js module specifier resolution behavior_ when calling `defaultResolve`, the
`context.conditions` array passed to it _must_ include _all_ elements of the
Expand Down
Loading

0 comments on commit 3c2a768

Please sign in to comment.