Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] add support for
node:
prefix, in node 16+
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ | |
|
||
var test = require('tape'); | ||
var keys = require('object-keys'); | ||
var semver = require('semver'); | ||
var isCore = require('../'); | ||
var data = require('../core.json'); | ||
|
||
var supportsNodePrefix = semver.satisfies(process.versions.node, '>= 16'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ljharb
Author
Member
|
||
|
||
test('core modules', function (t) { | ||
t.test('isCore()', function (st) { | ||
st.ok(isCore('fs')); | ||
|
@@ -48,6 +51,17 @@ test('core modules', function (t) { | |
function () { require(mod); }, // eslint-disable-line no-loop-func | ||
'requiring ' + mod + ' does not throw' | ||
); | ||
if (supportsNodePrefix) { | ||
st.doesNotThrow( | ||
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func | ||
'requiring node:' + mod + ' does not throw' | ||
); | ||
} else { | ||
st['throws']( | ||
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func | ||
'requiring node:' + mod + ' throws' | ||
); | ||
} | ||
} | ||
} | ||
st.end(); | ||
|
@@ -73,6 +87,17 @@ test('core modules', function (t) { | |
function () { require(mod); }, // eslint-disable-line no-loop-func | ||
'requiring ' + mod + ' does not throw' | ||
); | ||
if (supportsNodePrefix) { | ||
st.doesNotThrow( | ||
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func | ||
'requiring node:' + mod + ' does not throw' | ||
); | ||
} else { | ||
st['throws']( | ||
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func | ||
'requiring node:' + mod + ' throws' | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
Would it be possible to make this work with prereleases of Node.js? Currently this fails with them in citgm because
semver.satisfies('17.0.0-pre', '>= 16') === false