summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBradley Farias <bfarias@godaddy.com>2019-09-27 12:12:18 -0500
committerGuy Bedford <guybedford@gmail.com>2019-10-05 20:11:15 -0400
commit0b495a899bdf9a26b25a6e31177512531c841e0e (patch)
treed0c3a6b3768c0882ddf2eae1a01df419b50bb38f /doc
parente1e2f669f65fd53323b8a58d80ed3cee039706b7 (diff)
downloadandroid-node-v8-0b495a899bdf9a26b25a6e31177512531c841e0e.tar.gz
android-node-v8-0b495a899bdf9a26b25a6e31177512531c841e0e.tar.bz2
android-node-v8-0b495a899bdf9a26b25a6e31177512531c841e0e.zip
esm: remove proxy for builtin exports
PR-URL: https://github.com/nodejs/node/pull/29737 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/esm.md12
-rw-r--r--doc/api/modules.md30
2 files changed, 38 insertions, 4 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md
index 5805284016..e0a548f042 100644
--- a/doc/api/esm.md
+++ b/doc/api/esm.md
@@ -555,10 +555,11 @@ cjs === 'cjs'; // true
## Builtin modules
-Builtin modules will provide named exports of their public API, as well as a
-default export which can be used for, among other things, modifying the named
-exports. Named exports of builtin modules are updated when the corresponding
-exports property is accessed, redefined, or deleted.
+Builtin modules will 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
+[`module.syncBuiltinESMExports()`][].
```js
import EventEmitter from 'events';
@@ -578,8 +579,10 @@ readFile('./foo.txt', (err, source) => {
```js
import fs, { readFileSync } from 'fs';
+import { syncBuiltinESMExports } from 'module';
fs.readFileSync = () => Buffer.from('Hello, ESM');
+syncBuiltinESMExports();
fs.readFileSync === readFileSync;
```
@@ -1008,6 +1011,7 @@ success!
[`import.meta.url`]: #esm_import_meta
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
[`module.createRequire()`]: modules.html#modules_module_createrequire_filename
+[`module.syncBuiltinESMExports()`]: modules.html#modules_module_syncbuiltinesmexports
[dynamic instantiate hook]: #esm_dynamic_instantiate_hook
[package exports]: #esm_package_exports
[special scheme]: https://url.spec.whatwg.org/#special-scheme
diff --git a/doc/api/modules.md b/doc/api/modules.md
index 32490cf47f..9ed9273e0b 100644
--- a/doc/api/modules.md
+++ b/doc/api/modules.md
@@ -984,6 +984,36 @@ const requireUtil = createRequireFromPath('../src/utils/');
requireUtil('./some-tool');
```
+### module.syncBuiltinESMExports()
+<!-- YAML
+added: REPLACEME
+-->
+
+The `module.syncBuiltinESMExports()` method updates all the live bindings for
+builtin ES Modules to match the properties of the CommonJS exports. It does
+not add or remove exported names from the ES Modules.
+
+```js
+const fs = require('fs');
+const { syncBuiltinESMExports } = require('module');
+
+fs.readFile = null;
+
+delete fs.readFileSync;
+
+fs.newAPI = function newAPI() {
+ // ...
+};
+
+syncBuiltinESMExports();
+
+import('fs').then((esmFS) => {
+ assert.strictEqual(esmFS.readFile, null);
+ assert.strictEqual('readFileSync' in fs, true);
+ assert.strictEqual(esmFS.newAPI, undefined);
+});
+```
+
[GLOBAL_FOLDERS]: #modules_loading_from_the_global_folders
[`Error`]: errors.html#errors_class_error
[`__dirname`]: #modules_dirname