-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: add support for
node:
‑prefixed require(…)
calls
Fixes: #36098 Co-authored-by: Antoine du Hamel <[email protected]> Co-authored-by: Guy Bedford <[email protected]> Co-authored-by: Darshan Sen <[email protected]> PR-URL: #37246 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
7 changed files
with
90 additions
and
6 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 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
const errUnknownBuiltinModuleRE = /^No such built-in module: /u; | ||
|
||
// For direct use of require expressions inside of CJS modules, | ||
// all kinds of specifiers should work without issue. | ||
{ | ||
assert.strictEqual(require('fs'), fs); | ||
assert.strictEqual(require('node:fs'), fs); | ||
|
||
assert.throws( | ||
() => require('node:unknown'), | ||
{ | ||
code: 'ERR_UNKNOWN_BUILTIN_MODULE', | ||
message: errUnknownBuiltinModuleRE, | ||
}, | ||
); | ||
|
||
assert.throws( | ||
() => require('node:internal/test/binding'), | ||
{ | ||
code: 'ERR_UNKNOWN_BUILTIN_MODULE', | ||
message: errUnknownBuiltinModuleRE, | ||
}, | ||
); | ||
} | ||
|
||
// `node:`-prefixed `require(...)` calls bypass the require cache: | ||
{ | ||
const fakeModule = {}; | ||
|
||
require.cache.fs = { exports: fakeModule }; | ||
|
||
assert.strictEqual(require('fs'), fakeModule); | ||
assert.strictEqual(require('node:fs'), fs); | ||
|
||
delete require.cache.fs; | ||
} |