diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..a94f3b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,14 +10,31 @@ jobs: fail-fast: false matrix: node-version: + - 18 + - 17 + - 16 - 14 - 12 - 10 - 8 + # Note: not easy to setup GitHub Actions correctly in this case for Node 6, but you can run the tests locally (test-on-all-versions.sh) steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test + test-static-list-is-up-to-date: + name: Static list is up-to-date + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: latest + - run: npm install + - run: npm test + - run: mv builtin-modules.json builtin-modules-original.json + - run: npm run make + - run: diff builtin-modules.json builtin-modules-original.json diff --git a/builtin-modules.json b/builtin-modules.json index f2f4dbd..d586b23 100644 --- a/builtin-modules.json +++ b/builtin-modules.json @@ -1,5 +1,6 @@ [ "assert", + "assert/strict", "async_hooks", "buffer", "child_process", @@ -10,9 +11,11 @@ "dgram", "diagnostics_channel", "dns", + "dns/promises", "domain", "events", "fs", + "fs/promises", "http", "http2", "https", @@ -21,23 +24,30 @@ "net", "os", "path", + "path/posix", + "path/win32", "perf_hooks", "process", "punycode", "querystring", "readline", + "readline/promises", "repl", "stream", + "stream/consumers", + "stream/promises", + "stream/web", "string_decoder", "timers", + "timers/promises", "tls", "trace_events", "tty", "url", "util", + "util/types", "v8", "vm", - "wasi", "worker_threads", "zlib" ] diff --git a/index.js b/index.js index 8596b8d..2b236b3 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,6 @@ 'use strict'; const {builtinModules} = require('module'); -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)) +module.exports = (builtinModules || []) + .filter(x => !/^_|^v8\/|^node-inspect\/|^sys$/.test(x)) .sort(); diff --git a/package.json b/package.json index 39ddc44..53f553e 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ }, "scripts": { "test": "xo && ava && tsd", + "test-on-all-versions": "./test-on-all-versions.sh", "make": "node make.js" }, "files": [ diff --git a/test-on-all-versions.sh b/test-on-all-versions.sh new file mode 100755 index 0000000..82e8497 --- /dev/null +++ b/test-on-all-versions.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +for version in 6 8 10 12 14 16 17 18; do + fnm use "$version" + ./node_modules/.bin/ava +done diff --git a/test.js b/test.js index 8ea6022..851c45f 100644 --- a/test.js +++ b/test.js @@ -2,8 +2,13 @@ import test from 'ava'; import builtinModulesStatic from './static'; import builtinModules from '.'; -test('main', t => { - console.log('Builtin modules:', builtinModules); +const nodejsMajorVersion = Number.parseInt( + process.version.split('.')[0].replace('v', ''), + 10 +); + +test('builtinModules', t => { + console.log(`Builtin modules (Node.js ${nodejsMajorVersion}):`, builtinModules); t.notThrows(() => { for (const x of builtinModules) { @@ -12,5 +17,21 @@ test('main', t => { }); t.true(builtinModules.includes('fs')); + + if (nodejsMajorVersion >= 14) { + t.true(builtinModules.includes('fs/promises')); + } + + if (nodejsMajorVersion >= 16) { + t.true(builtinModules.includes('assert/strict')); + } + + // Some Node.js versions (e.g v10) include some `v8/` and `node-inspect/` modules in `require('module').builtinModules`, but we want to ignore them + t.false(builtinModules.some(x => x.startsWith('v8/'))); + t.false(builtinModules.some(x => x.startsWith('node-inspect/'))); +}); + +test('builtinModulesStatic', t => { t.true(Array.isArray(builtinModulesStatic)); + t.true(builtinModulesStatic.every(x => typeof x === 'string')); });