-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: provide named exports for builtin libs
provide named exports for all builtin libraries so that the libraries may be imported in a nicer way for esm users: `import { readFile } from 'fs'` instead of importing the entire namespace, `import fs from 'fs'`, and calling `fs.readFile`. the default export is left as the entire namespace (module.exports)
- Loading branch information
Showing
9 changed files
with
222 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Flags: --experimental-modules | ||
|
||
import '../common'; | ||
import assert from 'assert'; | ||
|
||
import fs, { readFile } from 'fs'; | ||
|
||
const s = Symbol(); | ||
const fn = () => s; | ||
|
||
delete fs.readFile; | ||
assert.strictEqual(fs.readFile, undefined); | ||
assert.strictEqual(readFile, undefined); | ||
|
||
fs.readFile = fn; | ||
|
||
assert.strictEqual(fs.readFile(), s); | ||
assert.strictEqual(readFile(), s); | ||
|
||
Reflect.deleteProperty(fs, 'readFile'); | ||
|
||
Reflect.defineProperty(fs, 'readFile', { | ||
value: fn, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
|
||
assert.strictEqual(fs.readFile(), s); | ||
assert.strictEqual(readFile(), s); | ||
|
||
Reflect.deleteProperty(fs, 'readFile'); | ||
assert.strictEqual(fs.readFile, undefined); | ||
assert.strictEqual(readFile, undefined); | ||
|
||
Reflect.defineProperty(fs, 'readFile', { | ||
get() { return fn; }, | ||
set() {}, | ||
configurable: true, | ||
}); | ||
|
||
assert.strictEqual(fs.readFile(), s); | ||
assert.strictEqual(readFile(), s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters