Skip to content

Commit

Permalink
[New] add support for node: prefix, in node 16+
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 24, 2021
1 parent cb466a6 commit 7341223
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
65 changes: 64 additions & 1 deletion core.json
@@ -1,73 +1,132 @@
{
"assert": true,
"node:assert": ">= 16",
"assert/strict": ">= 15",
"node:assert/strict": ">= 16",
"async_hooks": ">= 8",
"node:async_hooks": ">= 16",
"buffer_ieee754": "< 0.9.7",
"buffer": true,
"node:buffer": ">= 16",
"child_process": true,
"node:child_process": ">= 16",
"cluster": true,
"node:cluster": ">= 16",
"console": true,
"node:console": ">= 16",
"constants": true,
"node:constants": ">= 16",
"crypto": true,
"node:crypto": ">= 16",
"_debug_agent": ">= 1 && < 8",
"_debugger": "< 8",
"dgram": true,
"node:dgram": ">= 16",
"diagnostics_channel": ">= 15.1",
"node:diagnostics_channel": ">= 16",
"dns": true,
"node:dns": ">= 16",
"dns/promises": ">= 15",
"node:dns/promises": ">= 16",
"domain": ">= 0.7.12",
"node:domain": ">= 16",
"events": true,
"node:events": ">= 16",
"freelist": "< 6",
"fs": true,
"node:fs": ">= 16",
"fs/promises": [">= 10 && < 10.1", ">= 14"],
"node:fs/promises": ">= 16",
"_http_agent": ">= 0.11.1",
"node:_http_agent": ">= 16",
"_http_client": ">= 0.11.1",
"node:_http_client": ">= 16",
"_http_common": ">= 0.11.1",
"node:_http_common": ">= 16",
"_http_incoming": ">= 0.11.1",
"node:_http_incoming": ">= 16",
"_http_outgoing": ">= 0.11.1",
"node:_http_outgoing": ">= 16",
"_http_server": ">= 0.11.1",
"node:_http_server": ">= 16",
"http": true,
"node:http": ">= 16",
"http2": ">= 8.8",
"node:http2": ">= 16",
"https": true,
"node:https": ">= 16",
"inspector": ">= 8",
"node:inspector": ">= 16",
"_linklist": "< 8",
"module": true,
"node:module": ">= 16",
"net": true,
"node:net": ">= 16",
"node-inspect/lib/_inspect": ">= 7.6 && < 12",
"node-inspect/lib/internal/inspect_client": ">= 7.6 && < 12",
"node-inspect/lib/internal/inspect_repl": ">= 7.6 && < 12",
"os": true,
"node:os": ">= 16",
"path": true,
"node:path": ">= 16",
"path/posix": ">= 15.3",
"node:path/posix": ">= 16",
"path/win32": ">= 15.3",
"node:path/win32": ">= 16",
"perf_hooks": ">= 8.5",
"node:perf_hooks": ">= 16",
"process": ">= 1",
"node:process": ">= 16",
"punycode": true,
"node:punycode": ">= 16",
"querystring": true,
"node:querystring": ">= 16",
"readline": true,
"node:readline": ">= 16",
"repl": true,
"node:repl": ">= 16",
"smalloc": ">= 0.11.5 && < 3",
"_stream_duplex": ">= 0.9.4",
"node:_stream_duplex": ">= 16",
"_stream_transform": ">= 0.9.4",
"node:_stream_transform": ">= 16",
"_stream_wrap": ">= 1.4.1",
"node:_stream_wrap": ">= 16",
"_stream_passthrough": ">= 0.9.4",
"node:_stream_passthrough": ">= 16",
"_stream_readable": ">= 0.9.4",
"node:_stream_readable": ">= 16",
"_stream_writable": ">= 0.9.4",
"node:_stream_writable": ">= 16",
"stream": true,
"node:stream": ">= 16",
"stream/promises": ">= 15",
"node:stream/promises": ">= 16",
"string_decoder": true,
"node:string_decoder": ">= 16",
"sys": [">= 0.6 && < 0.7", ">= 0.8"],
"node:sys": ">= 16",
"timers": true,
"node:timers": ">= 16",
"timers/promises": ">= 15",
"node:timers/promises": ">= 16",
"_tls_common": ">= 0.11.13",
"node:_tls_common": ">= 16",
"_tls_legacy": ">= 0.11.3 && < 10",
"_tls_wrap": ">= 0.11.3",
"node:_tls_wrap": ">= 16",
"tls": true,
"node:tls": ">= 16",
"trace_events": ">= 10",
"node:trace_events": ">= 16",
"tty": true,
"node:tty": ">= 16",
"url": true,
"node:url": ">= 16",
"util": true,
"node:util": ">= 16",
"util/types": ">= 15.3",
"node:util/types": ">= 16",
"v8/tools/arguments": ">= 10 && < 12",
"v8/tools/codemap": [">= 4.4 && < 5", ">= 5.2 && < 12"],
"v8/tools/consarray": [">= 4.4 && < 5", ">= 5.2 && < 12"],
Expand All @@ -76,8 +135,12 @@
"v8/tools/profile_view": [">= 4.4 && < 5", ">= 5.2 && < 12"],
"v8/tools/splaytree": [">= 4.4 && < 5", ">= 5.2 && < 12"],
"v8": ">= 1",
"node:v8": ">= 16",
"vm": true,
"node:vm": ">= 16",
"wasi": ">= 13.4 && < 13.5",
"worker_threads": ">= 11.7",
"zlib": true
"node:worker_threads": ">= 16",
"zlib": true,
"node:zlib": ">= 16"
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -53,6 +53,7 @@
"eslint": "^7.19.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^1.1.4",
"semver": "^6.3.0",
"tape": "^5.1.1"
},
"auto-changelog": {
Expand Down
25 changes: 25 additions & 0 deletions test/index.js
Expand Up @@ -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.

Copy link
@targos

targos Jul 19, 2021

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

This comment has been minimized.

Copy link
@ljharb

ljharb Jul 19, 2021

Author Member

@targos can you confirm that semver.satisfies(process.versions.node, '>= 16', { includePrereleases: true }); solves it?

This comment has been minimized.

Copy link
@targos

targos Jul 20, 2021

It solves it, but with includePrerelease: true (singular):

> require('semver').satisfies(process.versions.node, '>= 16', { includePrerelease: true });
true
> process.versions.node
'17.0.0-pre'

This comment has been minimized.

Copy link
@ljharb

ljharb Jul 20, 2021

Author Member

oops yes, thanks :-) i'll add that shortly.

This comment has been minimized.

Copy link
@ljharb

ljharb Jul 20, 2021

Author Member

This comment has been minimized.

Copy link
@targos

targos Jul 20, 2021

thank you!


test('core modules', function (t) {
t.test('isCore()', function (st) {
st.ok(isCore('fs'));
Expand Down Expand Up @@ -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();
Expand All @@ -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'
);
}
}
}
}
Expand Down

0 comments on commit 7341223

Please sign in to comment.