Skip to content

Commit 437db59

Browse files
authored
fix: align pnpapi resolved path with enhanced-resolve (#245)
1 parent dcafcb3 commit 437db59

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

.changeset/ninety-coins-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix: align `pnpapi` resolved path with `enhanced-resolve`

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@types/json-schema": "^7.0.15",
9696
"@types/klaw-sync": "^6.0.5",
9797
"@types/node": "^20.17.24",
98+
"@types/pnpapi": "^0.0.5",
9899
"@typescript-eslint/eslint-plugin": "^8.26.1",
99100
"@typescript-eslint/parser": "^8.26.1",
100101
"@typescript-eslint/rule-tester": "^8.26.1",

src/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
import '@total-typescript/ts-reset'
2+
import type * as pnpapi from 'pnpapi'
3+
4+
declare module 'module' {
5+
namespace Module {
6+
function findPnpApi(source: string): typeof pnpapi
7+
}
8+
}

src/node-resolver.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isBuiltin } from 'node:module'
1+
import module from 'node:module'
22
import path from 'node:path'
33

44
import { ResolverFactory } from 'rspack-resolver'
@@ -49,13 +49,19 @@ export function createNodeResolver({
4949
interfaceVersion: 3,
5050
name: 'eslint-plugin-import-x built-in node resolver',
5151
resolve(modulePath, sourceFile) {
52-
if (
53-
isBuiltin(modulePath) ||
54-
(process.versions.pnp && modulePath === 'pnpapi')
55-
) {
52+
if (module.isBuiltin(modulePath)) {
5653
return { found: true, path: null }
5754
}
5855

56+
if (process.versions.pnp && modulePath === 'pnpapi') {
57+
return {
58+
found: true,
59+
path: module
60+
.findPnpApi(sourceFile)
61+
.resolveToUnqualified(modulePath, null),
62+
}
63+
}
64+
5965
if (modulePath.startsWith('data:')) {
6066
return { found: true, path: null }
6167
}

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,6 +3646,13 @@ __metadata:
36463646
languageName: node
36473647
linkType: hard
36483648

3649+
"@types/pnpapi@npm:^0.0.5":
3650+
version: 0.0.5
3651+
resolution: "@types/pnpapi@npm:0.0.5"
3652+
checksum: 10c0/2ade69b20d0ad5d16e6f709b1a40a8c43034ae5e8ca3b979a7fc7c26fbf0cc75791b7e8539f84e98c0e910b9c31d805fb420840e73482c6ed7bba9760ee938be
3653+
languageName: node
3654+
linkType: hard
3655+
36493656
"@types/responselike@npm:^1.0.0":
36503657
version: 1.0.3
36513658
resolution: "@types/responselike@npm:1.0.3"
@@ -5624,6 +5631,7 @@ __metadata:
56245631
"@types/json-schema": "npm:^7.0.15"
56255632
"@types/klaw-sync": "npm:^6.0.5"
56265633
"@types/node": "npm:^20.17.24"
5634+
"@types/pnpapi": "npm:^0.0.5"
56275635
"@typescript-eslint/eslint-plugin": "npm:^8.26.1"
56285636
"@typescript-eslint/parser": "npm:^8.26.1"
56295637
"@typescript-eslint/rule-tester": "npm:^8.26.1"

0 commit comments

Comments
 (0)