New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-import-resolver-typescript

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-import-resolver-typescript - npm Package Compare versions

Comparing version 3.6.3 to 3.7.0

12

lib/index.d.ts

@@ -1,2 +0,2 @@

import type { ResolveOptions } from 'enhanced-resolve';
import type { ResolveOptions, Resolver } from 'enhanced-resolve';
export declare const defaultConditionNames: string[];

@@ -17,5 +17,13 @@ export declare const defaultExtensions: string[];

}
export declare function resolve(source: string, file: string, options?: TsResolverOptions | null): {
export declare function resolve(source: string, file: string, options?: TsResolverOptions | null, resolver?: Resolver | null): {
found: boolean;
path?: string | null;
};
export declare function createTypeScriptImportResolver(options?: TsResolverOptions | null): {
interfaceVersion: number;
name: string;
resolve(source: string, file: string): {
found: boolean;
path?: string | null | undefined;
};
};

38

lib/index.js

@@ -6,3 +6,2 @@ import fs from 'node:fs';

import enhancedResolve from 'enhanced-resolve';
import { hashObject } from 'eslint-module-utils/hash.js';
import fg from 'fast-glob';

@@ -12,3 +11,5 @@ import { createPathsMatcher, getTsconfig } from 'get-tsconfig';

import isGlob from 'is-glob';
import stableHashExports from 'stable-hash';
const { globSync } = fg;
const stableHash = stableHashExports.default || stableHashExports;
const IMPORTER_NAME = 'eslint-import-resolver-typescript';

@@ -70,7 +71,6 @@ const log = debug(IMPORTER_NAME);

let resolverCachedOptions;
let resolver;
const digestHashObject = (value) => hashObject(value ?? {}).digest('hex');
export function resolve(source, file, options) {
let cachedResolver;
export function resolve(source, file, options, resolver = null) {
if (!cachedOptions ||
previousOptionsHash !== (optionsHash = digestHashObject(options))) {
previousOptionsHash !== (optionsHash = stableHash(options))) {
previousOptionsHash = optionsHash;

@@ -87,5 +87,9 @@ cachedOptions = {

}
if (!resolver || resolverCachedOptions !== cachedOptions) {
resolver = enhancedResolve.ResolverFactory.createResolver(cachedOptions);
resolverCachedOptions = cachedOptions;
if (!resolver) {
if (!cachedResolver || resolverCachedOptions !== cachedOptions) {
cachedResolver =
enhancedResolve.ResolverFactory.createResolver(cachedOptions);
resolverCachedOptions = cachedOptions;
}
resolver = cachedResolver;
}

@@ -137,2 +141,20 @@ log('looking for:', source);

}
export function createTypeScriptImportResolver(options) {
const resolver = enhancedResolve.ResolverFactory.createResolver({
...options,
conditionNames: options?.conditionNames ?? defaultConditionNames,
extensions: options?.extensions ?? defaultExtensions,
extensionAlias: options?.extensionAlias ?? defaultExtensionAlias,
mainFields: options?.mainFields ?? defaultMainFields,
fileSystem: new enhancedResolve.CachedInputFileSystem(fileSystem, 5 * 1000),
useSyncFileSystemCalls: true,
});
return {
interfaceVersion: 3,
name: IMPORTER_NAME,
resolve(source, file) {
return resolve(source, file, options, resolver);
},
};
}
function removeQuerystring(id) {

@@ -139,0 +161,0 @@ const querystringIndex = id.lastIndexOf('?');

{
"name": "eslint-import-resolver-typescript",
"version": "3.6.3",
"version": "3.7.0",
"type": "module",

@@ -54,2 +54,3 @@ "description": "This plugin adds `TypeScript` support to `eslint-plugin-import`",

"test": "run-p 'test:*'",
"test:importXResolverV3": "eslint --config=tests/importXResolverV3/eslint.config.js tests/importXResolverV3",
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",

@@ -80,14 +81,15 @@ "test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",

"@nolyfill/is-core-module": "1.0.39",
"debug": "^4.3.5",
"debug": "^4.3.7",
"enhanced-resolve": "^5.15.0",
"eslint-module-utils": "^2.8.1",
"fast-glob": "^3.3.2",
"get-tsconfig": "^4.7.5",
"is-bun-module": "^1.0.2",
"is-glob": "^4.0.3"
"is-glob": "^4.0.3",
"stable-hash": "^0.0.4"
},
"devDependencies": {
"@1stg/eslint-config": "7",
"@1stg/lib-config": "^12.0.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"@changesets/cli": "^2.27.10",
"@commitlint/cli": "^17.8.1",

@@ -98,13 +100,14 @@ "@mozilla/glean": "^3.0.0",

"@types/is-glob": "^4.0.4",
"@types/node": "^18.19.42",
"@types/unist": "^2.0.10",
"@types/node": "^18.19.67",
"@types/unist": "^2.0.11",
"dummy.js": "link:dummy.js",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-import-resolver-typescript": "link:.",
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
"eslint-plugin-import-x": "^4.5.0",
"lint-staged": "^13.3.0",
"npm-run-all2": "^5.0.2",
"prettier": "^2.8.8",
"react": "^18.2.0",
"simple-git-hooks": "^2.9.0",
"react": "^18.3.1",
"simple-git-hooks": "^2.11.1",
"size-limit": "^11.0.0",

@@ -111,0 +114,0 @@ "size-limit-preset-node-lib": "^0.3.0",

@@ -65,2 +65,86 @@ # eslint-import-resolver-typescript

### `eslint.config.js`
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
const {
createTypeScriptImportResolver,
} = require('eslint-import-resolver-typescript')
module.exports = [{
settings: {
"import/resolver-next": [
createTypeScriptImportResolver({
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
// use <root>/path/to/folder/tsconfig.json
project: "path/to/folder",
// Multiple tsconfigs (Useful for monorepos)
// use a glob pattern
project: "packages/*/tsconfig.json",
// use an array
project: [
"packages/module-a/tsconfig.json",
"packages/module-b/tsconfig.json"
],
// use an array of glob patterns
project: [
"packages/*/tsconfig.json",
"other-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:
```js
// eslint.config.js
module.exports = [
{
settings: {
'import/resolvers': {
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
// use <root>/path/to/folder/tsconfig.json
project: 'path/to/folder',
// Multiple tsconfigs (Useful for monorepos)
// use a glob pattern
project: 'packages/*/tsconfig.json',
// use an array
project: [
'packages/module-a/tsconfig.json',
'packages/module-b/tsconfig.json',
],
// use an array of glob patterns
project: [
'packages/*/tsconfig.json',
'other-packages/*/tsconfig.json',
],
},
},
},
},
]
```
### `.eslintrc`
Add the following to your `.eslintrc` config:

@@ -67,0 +151,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc