├── .editorconfig ├── .gitattributes ├── .github ├── security.md └── workflows │ ├── main.yml │ └── update.yml ├── .gitignore ├── .npmrc ├── builtin-modules.json ├── index.d.ts ├── index.js ├── index.test-d.ts ├── license ├── make.js ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 20 14 | - 18 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - run: npm install 21 | - run: npm test 22 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 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 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /builtin-modules.json: -------------------------------------------------------------------------------- 1 | [ 2 | "node:assert", 3 | "assert", 4 | "node:assert/strict", 5 | "assert/strict", 6 | "node:async_hooks", 7 | "async_hooks", 8 | "node:buffer", 9 | "buffer", 10 | "node:child_process", 11 | "child_process", 12 | "node:cluster", 13 | "cluster", 14 | "node:console", 15 | "console", 16 | "node:constants", 17 | "constants", 18 | "node:crypto", 19 | "crypto", 20 | "node:dgram", 21 | "dgram", 22 | "node:diagnostics_channel", 23 | "diagnostics_channel", 24 | "node:dns", 25 | "dns", 26 | "node:dns/promises", 27 | "dns/promises", 28 | "node:domain", 29 | "domain", 30 | "node:events", 31 | "events", 32 | "node:fs", 33 | "fs", 34 | "node:fs/promises", 35 | "fs/promises", 36 | "node:http", 37 | "http", 38 | "node:http2", 39 | "http2", 40 | "node:https", 41 | "https", 42 | "node:inspector", 43 | "inspector", 44 | "node:inspector/promises", 45 | "inspector/promises", 46 | "node:module", 47 | "module", 48 | "node:net", 49 | "net", 50 | "node:os", 51 | "os", 52 | "node:path", 53 | "path", 54 | "node:path/posix", 55 | "path/posix", 56 | "node:path/win32", 57 | "path/win32", 58 | "node:perf_hooks", 59 | "perf_hooks", 60 | "node:process", 61 | "process", 62 | "node:querystring", 63 | "querystring", 64 | "node:quic", 65 | "node:readline", 66 | "readline", 67 | "node:readline/promises", 68 | "readline/promises", 69 | "node:repl", 70 | "repl", 71 | "node:sea", 72 | "node:sqlite", 73 | "node:stream", 74 | "stream", 75 | "node:stream/consumers", 76 | "stream/consumers", 77 | "node:stream/promises", 78 | "stream/promises", 79 | "node:stream/web", 80 | "stream/web", 81 | "node:string_decoder", 82 | "string_decoder", 83 | "node:test", 84 | "node:test/reporters", 85 | "node:timers", 86 | "timers", 87 | "node:timers/promises", 88 | "timers/promises", 89 | "node:tls", 90 | "tls", 91 | "node:trace_events", 92 | "trace_events", 93 | "node:tty", 94 | "tty", 95 | "node:url", 96 | "url", 97 | "node:util", 98 | "util", 99 | "node:util/types", 100 | "util/types", 101 | "node:v8", 102 | "v8", 103 | "node:vm", 104 | "vm", 105 | "node:wasi", 106 | "wasi", 107 | "node:worker_threads", 108 | "worker_threads", 109 | "node:zlib", 110 | "zlib" 111 | ] 112 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | A static list of the Node.js builtin modules from the latest Node.js version. 3 | 4 | @example 5 | ``` 6 | import builtinModules from 'builtin-modules'; 7 | 8 | console.log(builtinModules); 9 | //=> ['node:assert', 'assert', 'node:buffer', 'buffer', …] 10 | ``` 11 | */ 12 | declare const builtinModules: readonly string[]; 13 | 14 | export default builtinModules; 15 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import builtinModules from './builtin-modules.json' with {type: 'json'}; 2 | 3 | export default builtinModules; 4 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType, expectError} from 'tsd'; 2 | import builtinModules from './index.js'; 3 | 4 | expectType(builtinModules); 5 | expectError(builtinModules); 6 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /make.js: -------------------------------------------------------------------------------- 1 | import fs from 'node:fs'; 2 | import process from 'node:process'; 3 | import {builtinModules, isBuiltin} from 'node:module'; 4 | import childProcess from 'node:child_process'; 5 | 6 | const JOB_BUILD_LIST = 'buildList'; 7 | const LIST_FILE = 'builtin-modules.json'; 8 | const NODE_PROTOCOL = 'node:'; 9 | 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 | } 82 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "builtin-modules", 3 | "version": "5.0.0", 4 | "description": "A static list of the Node.js builtin modules from the latest Node.js version", 5 | "license": "MIT", 6 | "repository": "sindresorhus/builtin-modules", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": { 15 | "types": "./index.d.ts", 16 | "default": "./index.js" 17 | }, 18 | "sideEffects": false, 19 | "engines": { 20 | "node": ">=18.20" 21 | }, 22 | "scripts": { 23 | "test": "ava && tsd", 24 | "make": "node make.js" 25 | }, 26 | "files": [ 27 | "index.js", 28 | "index.d.ts", 29 | "builtin-modules.json" 30 | ], 31 | "keywords": [ 32 | "builtin", 33 | "built-in", 34 | "builtins", 35 | "node", 36 | "modules", 37 | "core", 38 | "bundled", 39 | "list", 40 | "array", 41 | "names" 42 | ], 43 | "devDependencies": { 44 | "ava": "^6.2.0", 45 | "tsd": "^0.31.2", 46 | "xo": "^0.60.0" 47 | }, 48 | "xo": { 49 | "ignore": [ 50 | "index.js" 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # builtin-modules 2 | 3 | > A static list of the Node.js builtin modules from the latest Node.js version 4 | 5 | The list is just a [JSON file](builtin-modules.json) and can be used anywhere. 6 | 7 | ## Install 8 | 9 | ```sh 10 | npm install builtin-modules 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | import builtinModules from 'builtin-modules'; 17 | 18 | console.log(builtinModules); 19 | //=> ['node:assert', 'assert', 'node:buffer', 'buffer', …] 20 | ``` 21 | 22 | ## Tip 23 | 24 | To get a list from the current Node.js version, use the built-in API: 25 | 26 | ```js 27 | import {builtinModules} from 'node:module'; 28 | ``` 29 | 30 | ## Related 31 | 32 | - [is-builtin-module](https://github.com/sindresorhus/is-builtin-module) - Check if a string matches the name of a Node.js builtin module 33 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import {builtinModules as builtinModulesOnCurrentVersion, isBuiltin} from 'node:module'; 2 | import test from 'ava'; 3 | import builtinModules from './index.js'; 4 | 5 | test('main', async t => { 6 | console.log('Builtin modules:', builtinModules); 7 | 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; 17 | } 18 | 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 | 29 | 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 | )); 42 | }); 43 | --------------------------------------------------------------------------------