Skip to content

Commit d529c60

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

File tree

103 files changed

+2891
-2351
lines changed

Some content is hidden

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

103 files changed

+2891
-2351
lines changed

.changeset/olive-turkeys-go.md

Lines changed: 5 additions & 0 deletions

.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: 25 additions & 23 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,12 +43,13 @@
4443
],
4544
"scripts": {
4645
"build": "run-p -c 'build:*'",
47-
"build:r": "r -f cjs",
48-
"build:ts": "tsc -b",
46+
"build:ts": "tsc -p src",
47+
"build:tsdown": "tsdown --no-clean -d lib -f cjs src/index.ts",
48+
"clean": "premove coverage lib .eslintcache",
4949
"format": "prettier --write .",
5050
"lint": "run-p 'lint:*'",
5151
"lint:es": "eslint . --cache",
52-
"lint:tsc": "tsc -b --noEmit",
52+
"lint:tsc": "tsc --noEmit",
5353
"prepare": "simple-git-hooks && yarn-berry-deduplicate || exit 0",
5454
"release": "clean-pkg-json && changeset publish",
5555
"test": "node tests/e2e/withJsExtension/test.cjs && vitest run",
@@ -69,45 +69,47 @@
6969
}
7070
},
7171
"dependencies": {
72-
"debug": "^4.4.0",
73-
"get-tsconfig": "^4.10.0",
72+
"debug": "^4.4.1",
73+
"eslint-import-context": "^0.1.3",
74+
"get-tsconfig": "^4.10.1",
7475
"is-bun-module": "^2.0.0",
7576
"stable-hash": "^0.0.5",
7677
"tinyglobby": "^0.2.13",
77-
"unrs-resolver": "^1.6.3"
78+
"unrs-resolver": "^1.7.2"
7879
},
7980
"devDependencies": {
80-
"@1stg/common-config": "^13.0.1",
81+
"@1stg/common-config": "^14.0.0",
8182
"@changesets/changelog-github": "^0.5.1",
82-
"@changesets/cli": "^2.29.2",
83-
"@commitlint/cli": "^19.8.0",
83+
"@changesets/cli": "^2.29.4",
84+
"@commitlint/cli": "^19.8.1",
8485
"@mozilla/glean": "^5.0.4",
8586
"@pkgr/core": "^0.2.4",
86-
"@pkgr/rollup": "^6.0.3",
8787
"@total-typescript/ts-reset": "^0.6.1",
8888
"@types/debug": "^4.1.12",
89-
"@types/node": "^22.14.1",
89+
"@types/node": "^22.15.21",
9090
"@types/pnpapi": "^0.0.5",
9191
"@types/unist": "^3.0.3",
92-
"@vitest/coverage-v8": "3.1.2",
93-
"@vitest/eslint-plugin": "^1.1.43",
92+
"@vitest/coverage-v8": "3.1.4",
93+
"@vitest/eslint-plugin": "^1.2.1",
9494
"clean-pkg-json": "^1.3.0",
9595
"dummy.js": "link:dummy.js",
96-
"eslint": "^9.25.0",
96+
"eslint": "^9.27.0",
9797
"eslint-import-resolver-typescript": "workspace:*",
98-
"eslint-plugin-import-x": "^4.10.6",
98+
"eslint-plugin-import-x": "^4.13.0",
9999
"nano-staged": "^0.8.0",
100-
"npm-run-all2": "^7.0.2",
101-
"path-serializer": "^0.3.4",
100+
"npm-run-all2": "^8.0.3",
101+
"path-serializer": "^0.4.0",
102+
"premove": "^4.0.0",
102103
"prettier": "^3.5.3",
103104
"react": "^19.1.0",
104-
"simple-git-hooks": "^2.12.1",
105+
"simple-git-hooks": "^2.13.0",
105106
"size-limit": "^11.2.0",
106-
"size-limit-preset-node-lib": "^0.3.0",
107+
"size-limit-preset-node-lib": "^0.4.0",
107108
"tinyexec": "^1.0.1",
109+
"tsdown": "^0.12.3",
108110
"type-coverage": "^2.29.7",
109111
"typescript": "^5.8.3",
110-
"vitest": "^3.1.2",
112+
"vitest": "^3.1.4",
111113
"yarn-berry-deduplicate": "^6.1.3"
112114
},
113115
"resolutions": {

src/index.ts

Lines changed: 17 additions & 5 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,
@@ -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,23 @@ 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+
options = normalizeOptions(options, cwd)
220+
if (options.project) {
221+
resolver = resolver
222+
? resolver.cloneWithOptions(options)
223+
: new ResolverFactory(options)
224+
}
225+
}
214226
return resolve(source, file, options, resolver)
215227
},
216228
}

src/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.lib",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"outDir": "../lib"
6+
},
7+
"include": ["."]
8+
}

tests/e2e/absoluteAlias/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base",
2+
"extends": "../../../tsconfig.lib",
33
"compilerOptions": {
44
"paths": {
55
"/*": ["./public/*"]

tests/e2e/withJsExtension/test.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const assert = require('node:assert')
22
const path = require('node:path')
33

4+
// eslint-disable-next-line import-x/extensions
45
const { resolve } = require('../../..')
56

67
const config = {

tests/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"extends": "../tsconfig.base",
2+
"extends": "../tsconfig.lib",
33
"compilerOptions": {
44
"rootDir": "."
55
},
6-
"include": [".", "../auto-imports.d.ts"]
6+
"include": ["."]
77
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/unit/pnp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "module",
44
"packageManager": "[email protected]",
55
"devDependencies": {
6-
"@atlaskit/pragmatic-drag-and-drop": "^1.5.2",
6+
"@atlaskit/pragmatic-drag-and-drop": "^1.7.0",
77
"lodash.zip": "^4.2.0"
88
}
99
}

0 commit comments

Comments
 (0)