-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d234f3
commit 75f59d3
Showing
12 changed files
with
64 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
/** | ||
List of the Node.js builtin modules. | ||
A static list of the Node.js builtin modules from the latest Node.js version. | ||
@example | ||
``` | ||
import builtinModules = require('builtin-modules'); | ||
import builtinModules from 'builtin-modules'; | ||
console.log(builtinModules); | ||
//=> ['assert', 'buffer', …] | ||
``` | ||
*/ | ||
declare const builtinModules: readonly string[]; | ||
|
||
export = builtinModules; | ||
export default builtinModules; |
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 |
---|---|---|
@@ -1,11 +1,3 @@ | ||
'use strict'; | ||
const {builtinModules} = require('module'); | ||
import builtinModules from './builtin-modules.json' with {type: 'json'}; | ||
|
||
const ignoreList = [ | ||
'sys' | ||
]; | ||
|
||
// eslint-disable-next-line node/no-deprecated-api | ||
module.exports = (builtinModules || (process.binding ? Object.keys(process.binding('natives')) : []) || []) | ||
.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && !ignoreList.includes(x)) | ||
.sort(); | ||
export default builtinModules; |
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import {expectType, expectError} from 'tsd'; | ||
import builtinModules = require('.'); | ||
import builtinModulesStatic = require ('./static'); | ||
import builtinModules from './index.js'; | ||
|
||
expectType<readonly string[]>(builtinModules); | ||
expectError<string[]>(builtinModules); | ||
|
||
expectType<readonly string[]>(builtinModulesStatic); | ||
expectError<string[]>(builtinModulesStatic); |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const builtinModules = require('.'); | ||
import fs from 'node:fs'; | ||
import {builtinModules} from 'node:module'; | ||
|
||
fs.writeFileSync('builtin-modules.json', JSON.stringify(builtinModules, null, '\t') + '\n'); | ||
const final = builtinModules | ||
.filter(x => !/^_|^sys$/.test(x)) | ||
.sort(); | ||
|
||
fs.writeFileSync('builtin-modules.json', JSON.stringify(final, undefined, '\t') + '\n'); |
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 |
---|---|---|
@@ -1,44 +1,32 @@ | ||
# builtin-modules | ||
|
||
> List of the Node.js builtin modules | ||
> A static list of the Node.js builtin modules from the latest Node.js version | ||
The list is just a [JSON file](builtin-modules.json) and can be used anywhere. | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install builtin-modules | ||
```sh | ||
npm install builtin-modules | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
const builtinModules = require('builtin-modules'); | ||
import builtinModules from 'builtin-modules'; | ||
|
||
console.log(builtinModules); | ||
//=> ['assert', 'buffer', ...] | ||
//=> ['assert', 'buffer', …] | ||
``` | ||
|
||
## API | ||
|
||
Returns an array of builtin modules fetched from the running Node.js version. | ||
## Tip | ||
|
||
### Static list | ||
To get a list from the current Node.js version, use the built-in API: | ||
|
||
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');` | ||
```js | ||
import {builtinModules} from 'node:module'; | ||
``` | ||
|
||
## Related | ||
|
||
- [is-builtin-module](https://github.com/sindresorhus/is-builtin-module) - Check if a string matches the name of a Node.js builtin module | ||
|
||
--- | ||
|
||
<div align="center"> | ||
<b> | ||
<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> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import test from 'ava'; | ||
import builtinModulesStatic from './static'; | ||
import builtinModules from '.'; | ||
import builtinModules from './index.js'; | ||
|
||
test('main', t => { | ||
test('main', async t => { | ||
console.log('Builtin modules:', builtinModules); | ||
|
||
t.notThrows(() => { | ||
for (const x of builtinModules) { | ||
require(x); | ||
await t.notThrowsAsync((async () => { | ||
for (const builtinModule of builtinModules) { | ||
// Only available in latest Node.js. | ||
if (builtinModule === 'trace_events') { | ||
continue; | ||
} | ||
|
||
await import(builtinModule); | ||
} | ||
}); | ||
})()); | ||
|
||
t.true(builtinModules.includes('fs')); | ||
t.true(Array.isArray(builtinModulesStatic)); | ||
t.true(Array.isArray(builtinModules)); | ||
}); |