Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-coins-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": patch
---

fix: align `pnpapi` resolved path with `enhanced-resolve`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"@types/json-schema": "^7.0.15",
"@types/klaw-sync": "^6.0.5",
"@types/node": "^20.17.24",
"@types/pnpapi": "^0.0.5",
"@typescript-eslint/eslint-plugin": "^8.26.1",
"@typescript-eslint/parser": "^8.26.1",
"@typescript-eslint/rule-tester": "^8.26.1",
Expand Down
7 changes: 7 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
import '@total-typescript/ts-reset'
import type * as pnpapi from 'pnpapi'

declare module 'module' {
namespace Module {
function findPnpApi(source: string): typeof pnpapi
}
}
16 changes: 11 additions & 5 deletions src/node-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBuiltin } from 'node:module'
import module from 'node:module'
import path from 'node:path'

import { ResolverFactory } from 'rspack-resolver'
Expand Down Expand Up @@ -49,13 +49,19 @@
interfaceVersion: 3,
name: 'eslint-plugin-import-x built-in node resolver',
resolve(modulePath, sourceFile) {
if (
isBuiltin(modulePath) ||
(process.versions.pnp && modulePath === 'pnpapi')
) {
if (module.isBuiltin(modulePath)) {
return { found: true, path: null }
}

if (process.versions.pnp && modulePath === 'pnpapi') {
return {

Check warning on line 57 in src/node-resolver.ts

View check run for this annotation

Codecov / codecov/patch

src/node-resolver.ts#L57

Added line #L57 was not covered by tests
found: true,
path: module
.findPnpApi(sourceFile)
.resolveToUnqualified(modulePath, null),
}
}

if (modulePath.startsWith('data:')) {
return { found: true, path: null }
}
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3646,6 +3646,13 @@ __metadata:
languageName: node
linkType: hard

"@types/pnpapi@npm:^0.0.5":
version: 0.0.5
resolution: "@types/pnpapi@npm:0.0.5"
checksum: 10c0/2ade69b20d0ad5d16e6f709b1a40a8c43034ae5e8ca3b979a7fc7c26fbf0cc75791b7e8539f84e98c0e910b9c31d805fb420840e73482c6ed7bba9760ee938be
languageName: node
linkType: hard

"@types/responselike@npm:^1.0.0":
version: 1.0.3
resolution: "@types/responselike@npm:1.0.3"
Expand Down Expand Up @@ -5624,6 +5631,7 @@ __metadata:
"@types/json-schema": "npm:^7.0.15"
"@types/klaw-sync": "npm:^6.0.5"
"@types/node": "npm:^20.17.24"
"@types/pnpapi": "npm:^0.0.5"
"@typescript-eslint/eslint-plugin": "npm:^8.26.1"
"@typescript-eslint/parser": "npm:^8.26.1"
"@typescript-eslint/rule-tester": "npm:^8.26.1"
Expand Down
Loading