Skip to content

Commit 7a54302

Browse files
authored
Update module list (#18)
1 parent fb25601 commit 7a54302

File tree

5 files changed

+200
-18
lines changed

5 files changed

+200
-18
lines changed

.github/workflows/update.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Update
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# “At 00:00 on Sunday.” https://crontab.guru/#0_0_*_*_0
7+
- cron: "0 0 * * 0"
8+
9+
jobs:
10+
update:
11+
if: github.event_name != 'schedule' || github.repository == 'sindresorhus/builtin-modules'
12+
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write
15+
contents: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
check-latest: true
21+
node-version: latest
22+
- run: node make.js --incremental
23+
- uses: peter-evans/create-pull-request@v7
24+
with:
25+
commit-message: Update
26+
branch: automated-update
27+
branch-suffix: timestamp
28+
title: Update

builtin-modules.json

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,111 @@
11
[
2+
"node:assert",
23
"assert",
4+
"node:assert/strict",
35
"assert/strict",
6+
"node:async_hooks",
47
"async_hooks",
8+
"node:buffer",
59
"buffer",
10+
"node:child_process",
611
"child_process",
12+
"node:cluster",
713
"cluster",
14+
"node:console",
815
"console",
16+
"node:constants",
917
"constants",
18+
"node:crypto",
1019
"crypto",
20+
"node:dgram",
1121
"dgram",
22+
"node:diagnostics_channel",
1223
"diagnostics_channel",
24+
"node:dns",
1325
"dns",
26+
"node:dns/promises",
1427
"dns/promises",
28+
"node:domain",
1529
"domain",
30+
"node:events",
1631
"events",
32+
"node:fs",
1733
"fs",
34+
"node:fs/promises",
1835
"fs/promises",
36+
"node:http",
1937
"http",
38+
"node:http2",
2039
"http2",
40+
"node:https",
2141
"https",
42+
"node:inspector",
2243
"inspector",
44+
"node:inspector/promises",
2345
"inspector/promises",
46+
"node:module",
2447
"module",
48+
"node:net",
2549
"net",
50+
"node:os",
2651
"os",
52+
"node:path",
2753
"path",
54+
"node:path/posix",
2855
"path/posix",
56+
"node:path/win32",
2957
"path/win32",
58+
"node:perf_hooks",
3059
"perf_hooks",
60+
"node:process",
3161
"process",
32-
"punycode",
62+
"node:querystring",
3363
"querystring",
64+
"node:quic",
65+
"node:readline",
3466
"readline",
67+
"node:readline/promises",
3568
"readline/promises",
69+
"node:repl",
3670
"repl",
71+
"node:sea",
72+
"node:sqlite",
73+
"node:stream",
3774
"stream",
75+
"node:stream/consumers",
3876
"stream/consumers",
77+
"node:stream/promises",
3978
"stream/promises",
79+
"node:stream/web",
4080
"stream/web",
81+
"node:string_decoder",
4182
"string_decoder",
83+
"node:test",
84+
"node:test/reporters",
85+
"node:timers",
4286
"timers",
87+
"node:timers/promises",
4388
"timers/promises",
89+
"node:tls",
4490
"tls",
91+
"node:trace_events",
4592
"trace_events",
93+
"node:tty",
4694
"tty",
95+
"node:url",
4796
"url",
97+
"node:util",
4898
"util",
99+
"node:util/types",
49100
"util/types",
101+
"node:v8",
50102
"v8",
103+
"node:vm",
51104
"vm",
105+
"node:wasi",
52106
"wasi",
107+
"node:worker_threads",
53108
"worker_threads",
109+
"node:zlib",
54110
"zlib"
55111
]

make.js

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,81 @@
11
import fs from 'node:fs';
2-
import {builtinModules} from 'node:module';
2+
import process from 'node:process';
3+
import {builtinModules, isBuiltin} from 'node:module';
4+
import childProcess from 'node:child_process';
35

4-
const final = builtinModules
5-
.filter(x => !/^_|^sys$/.test(x))
6-
.sort();
6+
const JOB_BUILD_LIST = 'buildList';
7+
const LIST_FILE = 'builtin-modules.json';
8+
const NODE_PROTOCOL = 'node:';
79

8-
fs.writeFileSync('builtin-modules.json', JSON.stringify(final, undefined, '\t') + '\n');
10+
const stripNodeProtocol = name => name.startsWith(NODE_PROTOCOL) ? name.slice(NODE_PROTOCOL.length) : name;
11+
const deprecatedModules = new Set(['node:sys', 'node:punycode'].flatMap(name => [name, stripNodeProtocol(name)]));
12+
13+
const sorter = (nameA, nameB) => {
14+
const nameAWithoutProtocol = stripNodeProtocol(nameA);
15+
const nameBWithoutProtocol = stripNodeProtocol(nameB);
16+
17+
if (nameAWithoutProtocol === nameBWithoutProtocol) {
18+
return nameA.startsWith(NODE_PROTOCOL) ? -1 : 1;
19+
}
20+
21+
return nameAWithoutProtocol.localeCompare(nameBWithoutProtocol);
22+
};
23+
24+
function runInChildProcess(flag) {
25+
childProcess.execFileSync(process.execPath, [flag, import.meta.filename], {
26+
encoding: 'utf8',
27+
env: {
28+
JOB: JOB_BUILD_LIST,
29+
},
30+
});
31+
}
32+
33+
function run() {
34+
if (!process.argv.includes('--incremental')) {
35+
fs.writeFileSync(LIST_FILE, '[]');
36+
}
37+
38+
console.log('Building list without flags...');
39+
buildList();
40+
41+
for (const flag of process.allowedNodeEnvironmentFlags) {
42+
if (!flag.startsWith('--experimental-')) {
43+
continue;
44+
}
45+
46+
console.log();
47+
console.log(`Building list with '${flag}'...`);
48+
49+
try {
50+
runInChildProcess(flag);
51+
} catch {}
52+
}
53+
}
54+
55+
function buildList() {
56+
const existing = new Set(
57+
fs.existsSync(LIST_FILE)
58+
? JSON.parse(fs.readFileSync(LIST_FILE))
59+
: [],
60+
);
61+
const found = builtinModules
62+
.filter(name => !existing.has(name) && !name.startsWith('_'))
63+
.flatMap(name => name.startsWith(NODE_PROTOCOL) ? [name] : [name, `${NODE_PROTOCOL}${name}`])
64+
.filter(name => !deprecatedModules.has(name) && isBuiltin(name));
65+
66+
if (found.length === 0) {
67+
return;
68+
}
69+
70+
const final = [...existing, ...found].sort((nameA, nameB) => sorter(nameA, nameB));
71+
72+
fs.writeFileSync(LIST_FILE, JSON.stringify(final, undefined, '\t') + '\n');
73+
74+
console.log(`${final.length} module(s) found:\n${final.map(name => ` - ${name}`).join('\n')}`);
75+
}
76+
77+
if (process.env.JOB === JOB_BUILD_LIST) {
78+
buildList();
79+
} else {
80+
run();
81+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"node": ">=18.20"
2121
},
2222
"scripts": {
23-
"//test": "xo && ava && tsd",
23+
"test": "xo && ava && tsd",
2424
"test": "ava && tsd",
2525
"make": "node make.js"
2626
},
@@ -44,6 +44,9 @@
4444
"devDependencies": {
4545
"ava": "^6.1.2",
4646
"tsd": "^0.31.0",
47-
"xo": "^0.58.0"
47+
"xo": "^0.60.0"
48+
},
49+
"xo":{
50+
"ignore": ["index.js"]
4851
}
4952
}

test.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
1+
import {builtinModules as builtinModulesOnCurrentVersion, isBuiltin} from 'node:module';
12
import test from 'ava';
23
import builtinModules from './index.js';
34

45
test('main', async t => {
56
console.log('Builtin modules:', builtinModules);
67

7-
await t.notThrowsAsync((async () => {
8-
for (const builtinModule of builtinModules) {
9-
// Only available in latest Node.js.
10-
if (builtinModule === 'trace_events' || builtinModule === 'inspector' || builtinModule === 'inspector/promises') {
11-
continue;
12-
}
13-
14-
await import(builtinModule);
8+
for (const builtinModule of builtinModules) {
9+
// Only test modules available on current version
10+
if (
11+
!isBuiltin(builtinModule)
12+
// https://nodejs.org/api/errors.html#err_trace_events_unavailable
13+
|| builtinModule === 'trace_events'
14+
|| builtinModule === 'node:trace_events'
15+
) {
16+
continue;
1517
}
16-
})());
1718

18-
t.true(builtinModules.includes('fs'));
19+
// eslint-disable-next-line no-await-in-loop
20+
await t.notThrowsAsync(() => import(builtinModule), `Can't import '${builtinModule}'.`);
21+
}
22+
23+
// Deprecated modules
24+
t.false(builtinModules.includes('sys'));
25+
t.false(builtinModules.includes('punycode'));
26+
t.false(builtinModules.includes('node:sys'));
27+
t.false(builtinModules.includes('node:punycode'));
28+
1929
t.true(Array.isArray(builtinModules));
30+
t.true(builtinModules.includes('node:fs'));
31+
t.true(builtinModules.includes('fs'));
32+
t.true(builtinModules.includes('node:test'));
33+
t.false(builtinModules.includes('test'));
34+
35+
t.true(builtinModulesOnCurrentVersion.every(
36+
name =>
37+
name.startsWith('_')
38+
|| name === 'sys'
39+
|| name === 'punycode'
40+
|| builtinModules.includes(name)
41+
));
2042
});

0 commit comments

Comments
 (0)