Skip to content

Commit 88c0778

Browse files
committed
[New] add many missing core modules.
Also add better tests.
1 parent 2acf953 commit 88c0778

File tree

3 files changed

+95
-6
lines changed

3 files changed

+95
-6
lines changed

lib/core.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
22

3-
function versionIncluded(specifier) {
4-
if (specifier === true) { return true; }
3+
function specifierIncluded(specifier) {
54
var parts = specifier.split(' ');
65
var op = parts[0];
76
var versionParts = parts[1].split('.');
@@ -20,7 +19,27 @@ function versionIncluded(specifier) {
2019
return false;
2120
}
2221
}
23-
return false;
22+
return op === '>=';
23+
}
24+
25+
function matchesRange(range) {
26+
var specifiers = range.split(/ ?&& ?/);
27+
if (specifiers.length === 0) { return false; }
28+
for (var i = 0; i < specifiers.length; ++i) {
29+
if (!specifierIncluded(specifiers[i])) { return false; }
30+
}
31+
return true;
32+
}
33+
34+
function versionIncluded(specifierValue) {
35+
if (typeof specifierValue === 'boolean') { return specifierValue; }
36+
if (specifierValue && typeof specifierValue === 'object') {
37+
for (var i = 0; i < specifierValue.length; ++i) {
38+
if (matchesRange(specifierValue[i])) { return true; }
39+
}
40+
return false;
41+
}
42+
return matchesRange(specifierValue);
2443
}
2544

2645
var data = require('./core.json');

lib/core.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515
"events": true,
1616
"freelist": "< 6",
1717
"fs": true,
18+
"_http_agent": ">= 0.11.1",
19+
"_http_client": ">= 0.11.1",
20+
"_http_common": ">= 0.11.1",
21+
"_http_incoming": ">= 0.11.1",
22+
"_http_outgoing": ">= 0.11.1",
23+
"_http_server": ">= 0.11.1",
1824
"http": true,
1925
"http2": ">= 8.8",
2026
"https": true,
21-
"_http_server": ">= 0.11",
27+
"inspector": ">= 8.0.0",
2228
"_linklist": "< 8",
2329
"module": true,
2430
"net": true,
31+
"node-inspect/lib/_inspect": ">= 7.6.0",
32+
"node-inspect/lib/internal/inspect_client": ">= 7.6.0",
33+
"node-inspect/lib/internal/inspect_repl": ">= 7.6.0",
2534
"os": true,
2635
"path": true,
2736
"perf_hooks": ">= 8.5",
@@ -30,14 +39,30 @@
3039
"querystring": true,
3140
"readline": true,
3241
"repl": true,
42+
"smalloc": ">= 0.11.5 && < 3",
43+
"_stream_duplex": ">= 0.9.4",
44+
"_stream_transform": ">= 0.9.4",
45+
"_stream_wrap": ">= 1.4.1",
46+
"_stream_passthrough": ">= 0.9.4",
47+
"_stream_readable": ">= 0.9.4",
48+
"_stream_writable": ">= 0.9.4",
3349
"stream": true,
3450
"string_decoder": true,
3551
"sys": true,
3652
"timers": true,
53+
"_tls_common": ">= 0.11.13",
54+
"_tls_legacy": ">= 0.11.3",
55+
"_tls_wrap": ">= 0.11.3",
3756
"tls": true,
3857
"tty": true,
3958
"url": true,
4059
"util": true,
60+
"v8/tools/codemap": [">= 4.4.0 && < 5", ">= 5.2.0"],
61+
"v8/tools/consarray": [">= 4.4.0 && < 5", ">= 5.2.0"],
62+
"v8/tools/csvparser": [">= 4.4.0 && < 5", ">= 5.2.0"],
63+
"v8/tools/logreader": [">= 4.4.0 && < 5", ">= 5.2.0"],
64+
"v8/tools/profile_view": [">= 4.4.0 && < 5", ">= 5.2.0"],
65+
"v8/tools/splaytree": [">= 4.4.0 && < 5", ">= 5.2.0"],
4166
"v8": ">= 1",
4267
"vm": true,
4368
"zlib": true

test/core.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,60 @@ test('core modules', function (t) {
2222
if (resolve.core[mod]) {
2323
st.doesNotThrow(
2424
function () { require(mod); }, // eslint-disable-line no-loop-func
25-
'requiring ' + mod + ' does not throw'
25+
mod + ' supported; requiring does not throw'
2626
);
2727
} else {
28-
st.skip(mod + ' not supported');
28+
st.throws(
29+
function () { require(mod); }, // eslint-disable-line no-loop-func
30+
mod + ' not supported; requiring throws'
31+
);
2932
}
3033
}
3134

3235
st.end();
3336
});
3437

38+
t.test('core via repl module', { skip: !resolve.core.repl }, function (st) {
39+
var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
40+
if (!libs) {
41+
st.skip('module.builtinModules does not exist');
42+
return st.end();
43+
}
44+
for (var i = 0; i < libs.length; ++i) {
45+
var mod = libs[i];
46+
st.ok(resolve.core[mod], mod + ' is a core module');
47+
st.doesNotThrow(
48+
function () { require(mod); }, // eslint-disable-line no-loop-func
49+
'requiring ' + mod + ' does not throw'
50+
);
51+
}
52+
st.end();
53+
});
54+
55+
t.test('core via buildinModules list', { skip: !resolve.core.module }, function (st) {
56+
var libs = require('module').builtinModules;
57+
if (!libs) {
58+
st.skip('module.builtinModules does not exist');
59+
return st.end();
60+
}
61+
var blacklist = [
62+
'v8/tools/tickprocessor-driver',
63+
'v8/tools/SourceMap',
64+
'v8/tools/tickprocessor',
65+
'v8/tools/profile'
66+
];
67+
for (var i = 0; i < libs.length; ++i) {
68+
var mod = libs[i];
69+
if (blacklist.indexOf(mod) === -1) {
70+
st.ok(resolve.core[mod], mod + ' is a core module');
71+
st.doesNotThrow(
72+
function () { require(mod); }, // eslint-disable-line no-loop-func
73+
'requiring ' + mod + ' does not throw'
74+
);
75+
}
76+
}
77+
st.end();
78+
});
79+
3580
t.end();
3681
});

0 commit comments

Comments
 (0)