Skip to content

Commit

Permalink
fix: remove is-core-module dependency (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj authored Jun 28, 2024
1 parent ba407ef commit 2f27414
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
17 changes: 15 additions & 2 deletions lib/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -141,5 +139,6 @@
},
"publishConfig": {
"access": "public"
}
},
"packageManager": "yarn@1.22.22"
}
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2f27414

Please # to comment.