GeezerVison is showing github.com — doc: fix module syncBuiltinESMExports example · nodejs/node@5770ae0
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
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 number | Diff line number | Diff line change |
|---|
@@ -87,21 +87,29 @@ does not add or remove exported names from the [ES Modules][]. |
87 | 87 |
|
88 | 88 | ```js |
89 | 89 | const fs = require('fs'); |
| 90 | +const assert = require('assert'); |
90 | 91 | const { syncBuiltinESMExports } = require('module'); |
91 | 92 |
|
92 | | -fs.readFile = null; |
| 93 | +fs.readFile = newAPI; |
93 | 94 |
|
94 | 95 | delete fs.readFileSync; |
95 | 96 |
|
96 | | -fs.newAPI = function newAPI() { |
| 97 | +function newAPI() { |
97 | 98 | // ... |
98 | | -}; |
| 99 | +} |
| 100 | + |
| 101 | +fs.newAPI = newAPI; |
99 | 102 |
|
100 | 103 | syncBuiltinESMExports(); |
101 | 104 |
|
102 | 105 | 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 |
105 | 113 | assert.strictEqual(esmFS.newAPI, undefined); |
106 | 114 | }); |
107 | 115 | ``` |
|