GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: fix module syncBuiltinESMExports example · nodejs/node@5770ae0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • module.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/module.md‎

Copy file name to clipboardExpand all lines: doc/api/module.md
+13-5Lines changed: 13 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,29 @@ does not add or remove exported names from the [ES Modules][].
8787
8888
```js
8989
const fs = require('fs');
90+
const assert = require('assert');
9091
const { syncBuiltinESMExports } = require('module');
9192

92-
fs.readFile = null;
93+
fs.readFile = newAPI;
9394

9495
delete fs.readFileSync;
9596

96-
fs.newAPI = function newAPI() {
97+
function newAPI() {
9798
// ...
98-
};
99+
}
100+
101+
fs.newAPI = newAPI;
99102

100103
syncBuiltinESMExports();
101104

102105
import('fs').then((esmFS) => {
103-
assert.strictEqual(esmFS.readFile, null);
104-
assert.strictEqual('readFileSync' in fs, true);
106+
// It syncs the existing readFile property with the new value
107+
assert.strictEqual(esmFS.readFile, newAPI);
108+
// readFileSync has been deleted from the required fs
109+
assert.strictEqual('readFileSync' in fs, false);
110+
// syncBuiltinESMExports() does not remove readFileSync from esmFS
111+
assert.strictEqual('readFileSync' in esmFS, true);
112+
// syncBuiltinESMExports() does not add names
105113
assert.strictEqual(esmFS.newAPI, undefined);
106114
});
107115
```

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.