diff --git a/lib/walker.ts b/lib/walker.ts index 7daebf91..3f96dfb1 100644 --- a/lib/walker.ts +++ b/lib/walker.ts @@ -2,11 +2,11 @@ import assert from 'assert'; import fs from 'fs-extra'; -import isCore from 'is-core-module'; import globby from 'globby'; import path from 'path'; import chalk from 'chalk'; import { minimatch } from 'minimatch'; +import { builtinModules } from 'module'; import { ALIAS_AS_RELATIVE, @@ -74,6 +74,19 @@ const strictVerify = Boolean(process.env.PKG_STRICT_VER); const win32 = process.platform === 'win32'; +/** + * Checks if a module is a core module + * module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older + * versions of Node.js, we can use module.isBuiltin instead of this function. + */ +function isBuiltin(moduleName: string) { + const moduleNameWithoutPrefix = moduleName.startsWith('node:') + ? moduleName.slice(5) + : moduleName; + + return builtinModules.includes(moduleNameWithoutPrefix); +} + function unlikelyJavascript(file: string) { return ['.css', '.html', '.json', '.vue'].includes(path.extname(file)); } @@ -865,7 +878,7 @@ class Walker { ) { for (const derivative of derivatives) { // TODO: actually use the target node version - if (isCore(derivative.alias, '99.0.0')) continue; + if (isBuiltin(derivative.alias)) continue; switch (derivative.aliasType) { case ALIAS_AS_RELATIVE: diff --git a/package.json b/package.json index c028e4b1..5fda6f0e 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "fs-extra": "^9.1.0", "globby": "^11.1.0", "into-stream": "^6.0.0", - "is-core-module": "2.9.0", "minimatch": "9.0.4", "minimist": "^1.2.6", "multistream": "^4.1.0", @@ -43,7 +42,6 @@ "@release-it/conventional-changelog": "7.0.2", "@types/babel__generator": "7.6.5", "@types/fs-extra": "9.0.13", - "@types/is-core-module": "2.2.0", "@types/minimatch": "^5.1.2", "@types/minimist": "1.2.2", "@types/multistream": "4.1.0", @@ -141,5 +139,6 @@ }, "publishConfig": { "access": "public" - } + }, + "packageManager": "yarn@1.22.22" } diff --git a/yarn.lock b/yarn.lock index c1e37489..0e4515d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -516,11 +516,6 @@ resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz#b979ebad3919799c979b17c72621c0bc0a31c6c4" integrity sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA== -"@types/is-core-module@2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@types/is-core-module/-/is-core-module-2.2.0.tgz#a6f01308db449fb9200cc8b8b05aa26f404f0ddb" - integrity sha512-4jdbEoadP1B6v5/6YoVFPKUr2NC+knEWMSllpX3cL4FAZktVmveeWTcUHQY7bU6Vx8TEt/ARbQyQapkZvGgFog== - "@types/json-schema@^7.0.12": version "7.0.15" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" @@ -2721,13 +2716,6 @@ is-ci@3.0.1, is-ci@^3.0.1: dependencies: ci-info "^3.2.0" -is-core-module@2.9.0: - version "2.9.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69" - integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A== - dependencies: - has "^1.0.3" - is-core-module@^2.13.0, is-core-module@^2.8.1: version "2.13.1" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384"