eslint-import-resolver-typescript
Advanced tools
Comparing version
@@ -0,1 +1,2 @@ | ||
import { stableHash } from 'stable-hash-x'; | ||
import { globSync, isDynamicPattern } from 'tinyglobby'; | ||
@@ -49,6 +50,8 @@ import { DEFAULT_CONFIGS, DEFAULT_IGNORE, DEFAULT_TRY_PATHS, defaultConditionNames, defaultExtensionAlias, defaultExtensions, defaultMainFields, } from './constants.js'; | ||
} | ||
const optionsHash = stableHash(options); | ||
const cacheKey = `${configFile}\0${optionsHash}`; | ||
if (configFile) { | ||
const cachedOptions = configFileMapping.get(configFile); | ||
const cachedOptions = configFileMapping.get(cacheKey); | ||
if (cachedOptions) { | ||
log('using cached options for', configFile); | ||
log('using cached options for', configFile, 'with options', options); | ||
return cachedOptions; | ||
@@ -72,3 +75,3 @@ } | ||
if (configFile) { | ||
configFileMapping.set(configFile, options); | ||
configFileMapping.set(cacheKey, options); | ||
} | ||
@@ -75,0 +78,0 @@ return options; |
{ | ||
"name": "eslint-import-resolver-typescript", | ||
"version": "4.4.3", | ||
"version": "4.4.4", | ||
"type": "module", | ||
@@ -61,3 +61,3 @@ "description": "This plugin adds `TypeScript` support to `eslint-plugin-import`", | ||
"is-bun-module": "^2.0.0", | ||
"stable-hash-x": "^0.1.1", | ||
"stable-hash-x": "^0.2.0", | ||
"tinyglobby": "^0.2.14", | ||
@@ -64,0 +64,0 @@ "unrs-resolver": "^1.7.11" |
@@ -15,3 +15,3 @@ # eslint-import-resolver-typescript | ||
This is a resolver for `eslint-plugin-import(-x)` plugin, not an ESLint plugin itself, it adds [`TypeScript`][] support to [`eslint-plugin-import`][] (Or maybe you want to try [`eslint-plugin-import-x`][] for faster speed) | ||
This is a resolver for `eslint-plugin-import(-x)` plugin, not an ESLint plugin itself, it adds [`TypeScript`][] support to [`eslint-plugin-import`][]. (Or maybe you want to try [`eslint-plugin-import-x`][] for faster speed) | ||
@@ -23,3 +23,3 @@ This means you can: | ||
- Prefer resolving `@types/*` definitions over plain `.js`/`.jsx` | ||
- Multiple tsconfigs support just like normal | ||
- Multiple tsconfigs support, just like normal | ||
- `imports/exports` fields support in `package.json` | ||
@@ -55,5 +55,5 @@ | ||
After version 2.0.0, `.d.ts` will take higher priority then normal `.js`/`.jsx` files on resolving `node_modules` packages in favor of `@types/*` definitions or its own definition. | ||
After version 2.0.0, `.d.ts` will take higher priority than normal `.js`/`.jsx` files on resolving `node_modules` packages in favor of `@types/*` definitions or its own definition. | ||
If you're facing some problems on rules `import/default` or `import/named` from [`eslint-plugin-import`][], do not post any issue here, because they are just working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our sides, take [import-js/eslint-plugin-import#1525](https://github.com/import-js/eslint-plugin-import/issues/1525) as reference or post a new issue to [`eslint-plugin-import`][] instead. | ||
If you're facing some problems with rules `import/default` or `import/named` from [`eslint-plugin-import`][], do not post any issue here, because they are working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our side. Take [import-js/eslint-plugin-import#1525](https://github.com/import-js/eslint-plugin-import/issues/1525) as reference or post a new issue on [`eslint-plugin-import`][] instead. | ||
@@ -73,2 +73,5 @@ ## Installation | ||
yarn add -D eslint-plugin-import-x eslint-import-resolver-typescript | ||
# bun | ||
bun add -d eslint-plugin-import-x eslint-import-resolver-typescript | ||
``` | ||
@@ -87,2 +90,5 @@ | ||
yarn add -D eslint-plugin-import eslint-import-resolver-typescript | ||
# bun | ||
bun add -d eslint-plugin-import eslint-import-resolver-typescript | ||
``` | ||
@@ -94,6 +100,6 @@ | ||
If you are using `eslint-plugin-import-x@>=4.5.0`, you can use import/require to reference `eslint-import-resolver-typescript` directly in your ESLint flat config: | ||
If you are using `eslint-plugin-import-x@>=4.5.0`, you can use `import`/`require` to reference `eslint-import-resolver-typescript` directly in your ESLint flat config: | ||
```js | ||
// eslint.config.js, CommonJS is also supported | ||
// eslint.config.js (CommonJS is also supported) | ||
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript' | ||
@@ -106,9 +112,9 @@ | ||
createTypeScriptImportResolver({ | ||
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist` | ||
alwaysTryTypes: true, // Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist` | ||
bun: true, // resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun | ||
bun: true, // Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun) | ||
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default | ||
// use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json | ||
// Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json | ||
project: 'path/to/folder', | ||
@@ -118,6 +124,6 @@ | ||
// use a glob pattern | ||
// Use a glob pattern | ||
project: 'packages/*/{ts,js}config.json', | ||
// use an array | ||
// Use an array | ||
project: [ | ||
@@ -128,3 +134,3 @@ 'packages/module-a/tsconfig.json', | ||
// use an array of glob patterns | ||
// Use an array of glob patterns | ||
project: [ | ||
@@ -141,6 +147,6 @@ 'packages/*/tsconfig.json', | ||
But if you are using `eslint-plugin-import` or the older version of `eslint-plugin-import-x`, you can't use require/import: | ||
But if you are using `eslint-plugin-import` or the older version of `eslint-plugin-import-x`, you can't use `require`/`import`: | ||
```js | ||
// eslint.config.js, CommonJS is also supported | ||
// eslint.config.js (CommonJS is also supported) | ||
export default [ | ||
@@ -151,9 +157,9 @@ { | ||
typescript: { | ||
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist` | ||
alwaysTryTypes: true, // Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist` | ||
bun: true, // resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun | ||
bun: true, // Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun) | ||
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default | ||
// use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json | ||
// Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json | ||
project: 'path/to/folder', | ||
@@ -163,6 +169,6 @@ | ||
// use a glob pattern | ||
// Use a glob pattern | ||
project: 'packages/*/{ts,js}config.json', | ||
// use an array | ||
// Use an array | ||
project: [ | ||
@@ -173,3 +179,3 @@ 'packages/module-a/tsconfig.json', | ||
// use an array of glob patterns | ||
// Use an array of glob patterns | ||
project: [ | ||
@@ -194,3 +200,3 @@ 'packages/*/tsconfig.json', | ||
"rules": { | ||
// turn on errors for missing imports | ||
// Turn on errors for missing imports | ||
"import/no-unresolved": "error", | ||
@@ -204,9 +210,9 @@ }, | ||
"typescript": { | ||
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist` | ||
"alwaysTryTypes": true, // Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist` | ||
"bun": true, // resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun | ||
"bun": true, // Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun) | ||
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default | ||
// use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json | ||
// Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json | ||
"project": "path/to/folder", | ||
@@ -216,6 +222,6 @@ | ||
// use a glob pattern | ||
// Use a glob pattern | ||
"project": "packages/*/{ts,js}config.json", | ||
// use an array | ||
// Use an array | ||
"project": [ | ||
@@ -226,3 +232,3 @@ "packages/module-a/tsconfig.json", | ||
// use an array of glob patterns | ||
// Use an array of glob patterns | ||
"project": [ | ||
@@ -246,5 +252,5 @@ "packages/*/tsconfig.json", | ||
- Set the `bun: true` option, as shown in [Configuration](#configuration) above | ||
- Run ESLint with `bun --bun eslint` | ||
- [Configure `run.bun` in `bunfig.toml`](https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun) | ||
- Set the `bun: true` option, as shown in [Configuration](#configuration) above. | ||
- Run ESLint with `bun --bun eslint`. | ||
- [Configure `run.bun` in `bunfig.toml`](https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun). | ||
@@ -345,7 +351,7 @@ ## Options from [`unrs-resolver`][] | ||
You can pass through other options of [`unrs-resolver`][] directly | ||
You can pass through other options of [`unrs-resolver`][] directly. | ||
### Default options | ||
You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAlias` and `defaultMainFields` by `require/import` them directly | ||
You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAlias`, and `defaultMainFields` by directly using `require`/`import`. | ||
@@ -359,3 +365,3 @@ ## Contributing | ||
We have [GitHub Actions](https://github.com/import-js/eslint-import-resolver-typescript/actions) which will run the above commands on your PRs. | ||
We have [GitHub Actions](https://github.com/import-js/eslint-import-resolver-typescript/actions), which will run the above commands on your PRs. | ||
@@ -362,0 +368,0 @@ If either fails, we won't be able to merge your PR until it's fixed. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
59971
1.07%785
0.64%389
1.57%- Removed
Updated