Skip to content

Commit 75f59d3

Browse files
committed
Require Node.js 18 and move to ESM
Closes #17 Fixes #12
1 parent 0d234f3 commit 75f59d3

File tree

12 files changed

+64
-86
lines changed

12 files changed

+64
-86
lines changed

.github/funding.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
15-
- 10
16-
- 8
13+
- 20
14+
- 18
1715
steps:
18-
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
2018
with:
2119
node-version: ${{ matrix.node-version }}
2220
- run: npm install

builtin-modules.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
22
"assert",
3+
"assert/strict",
34
"async_hooks",
45
"buffer",
56
"child_process",
@@ -10,31 +11,42 @@
1011
"dgram",
1112
"diagnostics_channel",
1213
"dns",
14+
"dns/promises",
1315
"domain",
1416
"events",
1517
"fs",
18+
"fs/promises",
1619
"http",
1720
"http2",
1821
"https",
1922
"inspector",
23+
"inspector/promises",
2024
"module",
2125
"net",
2226
"os",
2327
"path",
28+
"path/posix",
29+
"path/win32",
2430
"perf_hooks",
2531
"process",
2632
"punycode",
2733
"querystring",
2834
"readline",
35+
"readline/promises",
2936
"repl",
3037
"stream",
38+
"stream/consumers",
39+
"stream/promises",
40+
"stream/web",
3141
"string_decoder",
3242
"timers",
43+
"timers/promises",
3344
"tls",
3445
"trace_events",
3546
"tty",
3647
"url",
3748
"util",
49+
"util/types",
3850
"v8",
3951
"vm",
4052
"wasi",

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
List of the Node.js builtin modules.
2+
A static list of the Node.js builtin modules from the latest Node.js version.
33
44
@example
55
```
6-
import builtinModules = require('builtin-modules');
6+
import builtinModules from 'builtin-modules';
77
88
console.log(builtinModules);
99
//=> ['assert', 'buffer', …]
1010
```
1111
*/
1212
declare const builtinModules: readonly string[];
1313

14-
export = builtinModules;
14+
export default builtinModules;

index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
'use strict';
2-
const {builtinModules} = require('module');
1+
import builtinModules from './builtin-modules.json' with {type: 'json'};
32

4-
const ignoreList = [
5-
'sys'
6-
];
7-
8-
// eslint-disable-next-line node/no-deprecated-api
9-
module.exports = (builtinModules || (process.binding ? Object.keys(process.binding('natives')) : []) || [])
10-
.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && !ignoreList.includes(x))
11-
.sort();
3+
export default builtinModules;

index.test-d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import {expectType, expectError} from 'tsd';
2-
import builtinModules = require('.');
3-
import builtinModulesStatic = require ('./static');
2+
import builtinModules from './index.js';
43

54
expectType<readonly string[]>(builtinModules);
65
expectError<string[]>(builtinModules);
7-
8-
expectType<readonly string[]>(builtinModulesStatic);
9-
expectError<string[]>(builtinModulesStatic);

make.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
'use strict';
2-
const fs = require('fs');
3-
const builtinModules = require('.');
1+
import fs from 'node:fs';
2+
import {builtinModules} from 'node:module';
43

5-
fs.writeFileSync('builtin-modules.json', JSON.stringify(builtinModules, null, '\t') + '\n');
4+
const final = builtinModules
5+
.filter(x => !/^_|^sys$/.test(x))
6+
.sort();
7+
8+
fs.writeFileSync('builtin-modules.json', JSON.stringify(final, undefined, '\t') + '\n');

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "builtin-modules",
33
"version": "3.3.0",
4-
"description": "List of the Node.js builtin modules",
4+
"description": "A static list of the Node.js builtin modules from the latest Node.js version",
55
"license": "MIT",
66
"repository": "sindresorhus/builtin-modules",
77
"funding": "https://github.com/sponsors/sindresorhus",
@@ -10,18 +10,23 @@
1010
"email": "sindresorhus@gmail.com",
1111
"url": "https://sindresorhus.com"
1212
},
13+
"type": "module",
14+
"exports": {
15+
"types": "./index.d.ts",
16+
"default": "./index.js"
17+
},
18+
"sideEffects": false,
1319
"engines": {
14-
"node": ">=6"
20+
"node": ">=18.20"
1521
},
1622
"scripts": {
17-
"test": "xo && ava && tsd",
23+
"//test": "xo && ava && tsd",
24+
"test": "ava && tsd",
1825
"make": "node make.js"
1926
},
2027
"files": [
2128
"index.js",
2229
"index.d.ts",
23-
"static.js",
24-
"static.d.ts",
2530
"builtin-modules.json"
2631
],
2732
"keywords": [
@@ -37,8 +42,8 @@
3742
"names"
3843
],
3944
"devDependencies": {
40-
"ava": "^1.4.1",
41-
"tsd": "^0.7.2",
42-
"xo": "^0.24.0"
45+
"ava": "^6.1.2",
46+
"tsd": "^0.31.0",
47+
"xo": "^0.58.0"
4348
}
4449
}

readme.md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
# builtin-modules
22

3-
> List of the Node.js builtin modules
3+
> A static list of the Node.js builtin modules from the latest Node.js version
44
55
The list is just a [JSON file](builtin-modules.json) and can be used anywhere.
66

77
## Install
88

9-
```
10-
$ npm install builtin-modules
9+
```sh
10+
npm install builtin-modules
1111
```
1212

1313
## Usage
1414

1515
```js
16-
const builtinModules = require('builtin-modules');
16+
import builtinModules from 'builtin-modules';
1717

1818
console.log(builtinModules);
19-
//=> ['assert', 'buffer', ...]
19+
//=> ['assert', 'buffer', ]
2020
```
2121

22-
## API
23-
24-
Returns an array of builtin modules fetched from the running Node.js version.
22+
## Tip
2523

26-
### Static list
24+
To get a list from the current Node.js version, use the built-in API:
2725

28-
This module also comes bundled with a static array of builtin modules generated from the latest Node.js version. You can get it with `require('builtin-modules/static');`
26+
```js
27+
import {builtinModules} from 'node:module';
28+
```
2929

3030
## Related
3131

3232
- [is-builtin-module](https://github.com/sindresorhus/is-builtin-module) - Check if a string matches the name of a Node.js builtin module
33-
34-
---
35-
36-
<div align="center">
37-
<b>
38-
<a href="https://tidelift.com/subscription/pkg/npm-builtin-modules?utm_source=npm-builtin-modules&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
39-
</b>
40-
<br>
41-
<sub>
42-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
43-
</sub>
44-
</div>

static.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)