From c2a495ae2f0864ff82c17403001ad843485ddef7 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Mon, 22 Jul 2024 11:44:57 +0800 Subject: [PATCH 1/2] fix(#303): use @nolyfill/is-core-module --- package.json | 1 + src/index.ts | 13 ++----------- tsconfig.json | 4 +++- yarn.lock | 8 ++++++++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c815d86..6228665 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ } }, "dependencies": { + "@nolyfill/is-core-module": "1.0.39", "debug": "^4.3.5", "enhanced-resolve": "^5.15.0", "eslint-module-utils": "^2.8.1", diff --git a/src/index.ts b/src/index.ts index 2cd5aee..e0e97ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs' -import { builtinModules } from 'node:module' import path from 'node:path' +import isNodeCoreModule from '@nolyfill/is-core-module' import debug from 'debug' import type { FileSystem, ResolveOptions, Resolver } from 'enhanced-resolve' import enhancedResolve from 'enhanced-resolve' @@ -119,15 +119,6 @@ let resolver: Resolver | undefined const digestHashObject = (value: object | null | undefined) => hashObject(value ?? {}).digest('hex') -/** - * 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) { - return builtinModules.includes(moduleName.replace(/^node:/, '')) -} - /** * @param source the module to resolve; i.e './some-module' * @param file the importing file's full path; i.e. '/usr/local/bin/file.js' @@ -172,7 +163,7 @@ export function resolve( // don't worry about core node/bun modules if ( - isBuiltin(source) || + isNodeCoreModule(source) || isBunModule(source, (process.versions.bun ?? 'latest') as Version) ) { log('matched core:', source) diff --git a/tsconfig.json b/tsconfig.json index a303861..39c6900 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,9 @@ "extends": "@1stg/tsconfig/node16", "compilerOptions": { "module": "Node16", - "outDir": "./lib" + "outDir": "./lib", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true }, "include": ["./src", "./shim.d.ts"] } diff --git a/yarn.lock b/yarn.lock index 699049a..21444a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3219,6 +3219,13 @@ __metadata: languageName: node linkType: hard +"@nolyfill/is-core-module@npm:1.0.39": + version: 1.0.39 + resolution: "@nolyfill/is-core-module@npm:1.0.39" + checksum: 0d6e098b871eca71d875651288e1f0fa770a63478b0b50479c99dc760c64175a56b5b04f58d5581bbcc6b552b8191ab415eada093d8df9597ab3423c8cac1815 + languageName: node + linkType: hard + "@npmcli/agent@npm:^2.0.0": version: 2.2.0 resolution: "@npmcli/agent@npm:2.2.0" @@ -6109,6 +6116,7 @@ __metadata: "@changesets/cli": "npm:^2.27.6" "@commitlint/cli": "npm:^17.8.1" "@mozilla/glean": "npm:^3.0.0" + "@nolyfill/is-core-module": "npm:1.0.39" "@pkgr/rollup": "npm:^4.1.3" "@types/debug": "npm:^4.1.12" "@types/is-glob": "npm:^4.0.4" From 925527973c20d93ad0e0901a2afa50d8847aa169 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Tue, 23 Jul 2024 20:35:59 +0800 Subject: [PATCH 2/2] chore: add changeset --- .changeset/dirty-lobsters-behave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dirty-lobsters-behave.md diff --git a/.changeset/dirty-lobsters-behave.md b/.changeset/dirty-lobsters-behave.md new file mode 100644 index 0000000..bdb1bca --- /dev/null +++ b/.changeset/dirty-lobsters-behave.md @@ -0,0 +1,5 @@ +--- +'eslint-import-resolver-typescript': patch +--- + +Fix resolve for `node:test`, `node:sea`, and `node:sqlite` without sacrificing installation size