Skip to content

Commit

Permalink
fix(#303): use @nolyfill/is-core-module (#305)
Browse files Browse the repository at this point in the history
* fix(#303): use @nolyfill/is-core-module

* chore: add changeset
  • Loading branch information
SukkaW committed Jul 23, 2024
1 parent a4c6c78 commit f8d7b82
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-lobsters-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-import-resolver-typescript': patch
---

Fix resolve for `node:test`, `node:sea`, and `node:sqlite` without sacrificing installation size
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 2 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"extends": "@1stg/tsconfig/node16",
"compilerOptions": {
"module": "Node16",
"outDir": "./lib"
"outDir": "./lib",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["./src", "./shim.d.ts"]
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f8d7b82

Please sign in to comment.