-
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 <duhamelantoine1995@gmail.com> Co-authored-by: Guy Bedford <guybedford@gmail.com> Co-authored-by: Darshan Sen <raisinten@gmail.com> PR-URL: #37246 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
7 changed files
with
93 additions
and
7 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; | ||
} |