Skip to content

Commit 61d2c19

Browse files
committed
feat: integrate eslint-import-context to get correct context.cwd
1 parent c45039e commit 61d2c19

File tree

85 files changed

+2004
-2326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2004
-2326
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343
PARSER_NO_WATCH: true
4444

4545
- name: Codecov
46-
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
46+
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
4747
with:
4848
token: ${{ secrets.CODECOV_TOKEN }}

index.d.cts

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"node": "^16.17.0 || >=18.6.0"
1616
},
1717
"main": "lib/index.cjs",
18-
"types": "lib/index.d.ts",
18+
"types": "lib/index.d.cts",
1919
"module": "lib/index.js",
2020
"exports": {
2121
".": {
@@ -24,14 +24,13 @@
2424
"default": "./lib/index.js"
2525
},
2626
"require": {
27-
"types": "./index.d.cts",
27+
"types": "./lib/index.d.cts",
2828
"default": "./lib/index.cjs"
2929
}
3030
},
3131
"./package.json": "./package.json"
3232
},
3333
"files": [
34-
"index.d.cts",
3534
"lib",
3635
"!**/*.tsbuildinfo"
3736
],
@@ -44,8 +43,8 @@
4443
],
4544
"scripts": {
4645
"build": "run-p -c 'build:*'",
47-
"build:r": "r -f cjs",
4846
"build:ts": "tsc -b",
47+
"build:tsdown": "tsdown --no-clean -d lib -f cjs src/index.ts",
4948
"format": "prettier --write .",
5049
"lint": "run-p 'lint:*'",
5150
"lint:es": "eslint . --cache",
@@ -69,45 +68,46 @@
6968
}
7069
},
7170
"dependencies": {
72-
"debug": "^4.4.0",
73-
"get-tsconfig": "^4.10.0",
71+
"debug": "^4.4.1",
72+
"eslint-import-context": "^0.1.3",
73+
"get-tsconfig": "^4.10.1",
7474
"is-bun-module": "^2.0.0",
7575
"stable-hash": "^0.0.5",
7676
"tinyglobby": "^0.2.13",
77-
"unrs-resolver": "^1.6.3"
77+
"unrs-resolver": "^1.7.2"
7878
},
7979
"devDependencies": {
80-
"@1stg/common-config": "^13.0.1",
80+
"@1stg/common-config": "^14.0.0",
8181
"@changesets/changelog-github": "^0.5.1",
82-
"@changesets/cli": "^2.29.2",
83-
"@commitlint/cli": "^19.8.0",
82+
"@changesets/cli": "^2.29.4",
83+
"@commitlint/cli": "^19.8.1",
8484
"@mozilla/glean": "^5.0.4",
8585
"@pkgr/core": "^0.2.4",
86-
"@pkgr/rollup": "^6.0.3",
8786
"@total-typescript/ts-reset": "^0.6.1",
8887
"@types/debug": "^4.1.12",
89-
"@types/node": "^22.14.1",
88+
"@types/node": "^22.15.21",
9089
"@types/pnpapi": "^0.0.5",
9190
"@types/unist": "^3.0.3",
92-
"@vitest/coverage-v8": "3.1.2",
93-
"@vitest/eslint-plugin": "^1.1.43",
91+
"@vitest/coverage-v8": "3.1.4",
92+
"@vitest/eslint-plugin": "^1.2.1",
9493
"clean-pkg-json": "^1.3.0",
9594
"dummy.js": "link:dummy.js",
96-
"eslint": "^9.25.0",
95+
"eslint": "^9.27.0",
9796
"eslint-import-resolver-typescript": "workspace:*",
98-
"eslint-plugin-import-x": "^4.10.6",
97+
"eslint-plugin-import-x": "^4.13.0",
9998
"nano-staged": "^0.8.0",
100-
"npm-run-all2": "^7.0.2",
101-
"path-serializer": "^0.3.4",
99+
"npm-run-all2": "^8.0.3",
100+
"path-serializer": "^0.4.0",
102101
"prettier": "^3.5.3",
103102
"react": "^19.1.0",
104-
"simple-git-hooks": "^2.12.1",
103+
"simple-git-hooks": "^2.13.0",
105104
"size-limit": "^11.2.0",
106-
"size-limit-preset-node-lib": "^0.3.0",
105+
"size-limit-preset-node-lib": "^0.4.0",
107106
"tinyexec": "^1.0.1",
107+
"tsdown": "^0.12.3",
108108
"type-coverage": "^2.29.7",
109109
"typescript": "^5.8.3",
110-
"vitest": "^3.1.2",
110+
"vitest": "^3.1.4",
111111
"yarn-berry-deduplicate": "^6.1.3"
112112
},
113113
"resolutions": {

src/index.ts

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

4-
import type { ResolvedResult } from 'eslint-plugin-import-x/types'
4+
import { useRuleContext, type ResolvedResult } from 'eslint-import-context'
55
import {
66
type FileMatcher,
77
type TsConfigJsonResolved,
@@ -65,8 +65,8 @@ const isBun = !!process.versions.bun
6565
export const resolve = (
6666
source: string,
6767
file: string,
68-
options?: TypeScriptResolverOptions | null,
69-
resolver?: ResolverFactory | null,
68+
options?: TypeScriptResolverOptions,
69+
resolver?: ResolverFactory,
7070
// eslint-disable-next-line sonarjs/cognitive-complexity
7171
): ResolvedResult => {
7272
options ||= {}
@@ -81,10 +81,11 @@ export const resolve = (
8181

8282
if (!resolver) {
8383
const optionsHash = stableHash(options)
84-
const cwd = process.cwd()
84+
const context = useRuleContext()
85+
const cwd = context?.cwd || process.cwd()
8586
options = normalizeOptions(options, cwd)
8687
// take `cwd` into account -- #217
87-
const cacheKey = `${optionsHash}:${cwd}`
88+
const cacheKey = `${optionsHash}\0${cwd}`
8889
let cached = resolverCache.get(cacheKey)
8990
if (!cached && !options.project) {
9091
resolverCache.set(cacheKey, (cached = new ResolverFactory(options)))
@@ -205,12 +206,18 @@ export const resolve = (
205206
export const createTypeScriptImportResolver = (
206207
options?: TypeScriptResolverOptions | null,
207208
) => {
208-
options = normalizeOptions(options)
209-
const resolver = options.project ? null : new ResolverFactory(options)
209+
let cwd = process.cwd()
210+
options = normalizeOptions(options, cwd)
211+
let resolver = options.project ? undefined : new ResolverFactory(options)
210212
return {
211213
interfaceVersion: 3,
212214
name: IMPORT_RESOLVER_NAME,
213215
resolve(source: string, file: string) {
216+
const context = useRuleContext()
217+
if (context && cwd !== context.cwd) {
218+
cwd = context.cwd
219+
resolver = resolver?.cloneWithOptions(normalizeOptions(options, cwd))
220+
}
214221
return resolve(source, file, options, resolver)
215222
},
216223
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)