TypeScript resolver plugin for eslint-plugin-import that enables TypeScript module resolution with path mapping and @types/* support
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Option normalization and TypeScript project configuration management for handling various project structures and settings.
Normalizes and validates TypeScript resolver options, handles project detection, and manages configuration caching.
/**
* Normalizes TypeScript resolver options and handles project detection
* @param options - Raw TypeScript resolver options
* @param cwd - Current working directory (defaults to process.cwd())
* @returns Normalized and validated options
*/
function normalizeOptions(
options?: TypeScriptResolverOptions | null,
cwd?: string
): TypeScriptResolverOptions;Usage Examples:
import { normalizeOptions } from "eslint-import-resolver-typescript";
// Basic normalization
const normalized = normalizeOptions({
project: "./tsconfig.json",
alwaysTryTypes: true
});
// With custom working directory
const normalizedWithCwd = normalizeOptions(
{ project: "configs/tsconfig.json" },
"/path/to/project"
);
// Normalize empty options (uses defaults)
const defaults = normalizeOptions();
console.log(defaults.extensions); // ['.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json', '.node']The normalization process handles several complex scenarios:
interface TypeScriptResolverOptions extends NapiResolveOptions {
/** TypeScript project configuration paths (file path, directory, or glob patterns) */
project?: string[] | string;
/** Whether to always try to resolve @types packages (default: true) */
alwaysTryTypes?: boolean;
/** Whether Bun core modules should be accounted for */
bun?: boolean;
/** Suppress multiple projects warning */
noWarnOnMultipleProjects?: boolean;
// Configuration object for TypeScript compiler
tsconfig?: {
/** Path to TypeScript configuration file */
configFile?: string;
/** TypeScript project references handling */
references?: 'auto' | boolean;
};
}Single Configuration File:
const options = normalizeOptions({
project: "./tsconfig.json"
});Directory-based Configuration:
const options = normalizeOptions({
project: "path/to/folder" // Will look for tsconfig.json or jsconfig.json
});Multiple Configurations:
const options = normalizeOptions({
project: [
"packages/module-a/tsconfig.json",
"packages/module-b/jsconfig.json"
]
});Glob Pattern Configurations:
// Single glob pattern
const globOptions = normalizeOptions({
project: "packages/*/tsconfig.json"
});
// Multiple glob patterns
const multiGlobOptions = normalizeOptions({
project: [
"packages/*/tsconfig.json",
"other-packages/*/jsconfig.json"
]
});
// Complex glob pattern
const complexGlobOptions = normalizeOptions({
project: "packages/*/{ts,js}config.json"
});The normalization process applies these default values:
// Mutable variable holding the default configuration file path
declare let defaultConfigFile: string;
// Default condition names for package.json exports
declare const defaultConditionNames: string[];
// ['types', 'import', 'esm2020', 'es2020', 'es2015', 'require', 'node', 'node-addons', 'browser', 'default']
// Default file extensions to resolve
declare const defaultExtensions: string[];
// ['.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json', '.node']
// Default extension aliases for TypeScript compilation
declare const defaultExtensionAlias: Record<string, string[]>;
/* {
'.js': ['.ts', '.tsx', '.d.ts', '.js'],
'.ts': ['.ts', '.d.ts', '.js'],
'.jsx': ['.tsx', '.d.ts', '.jsx'],
'.tsx': ['.tsx', '.d.ts', '.jsx', '.js'],
'.cjs': ['.cts', '.d.cts', '.cjs'],
'.cts': ['.cts', '.d.cts', '.cjs'],
'.mjs': ['.mts', '.d.mts', '.mjs'],
'.mts': ['.mts', '.d.mts', '.mjs']
} */
// Default package.json main fields priority
declare const defaultMainFields: string[];
// ['types', 'typings', 'fesm2020', 'fesm2015', 'esm2020', 'es2020', 'module', 'jsnext:main', 'main']The normalization process follows this detection algorithm:
project is specified, use those pathsproject points to directories, scan for config files// Detection priority order:
const DEFAULT_CONFIGS = ['tsconfig.json', 'jsconfig.json'];
const DEFAULT_TRY_PATHS = ['', ...DEFAULT_CONFIGS];For projects with multiple TypeScript configurations:
const options = normalizeOptions({
project: [
"frontend/tsconfig.json",
"backend/tsconfig.json",
"shared/tsconfig.json"
],
noWarnOnMultipleProjects: true // Suppress warning about multiple projects
});Without noWarnOnMultipleProjects, the resolver will warn:
"Multiple projects found, consider using a single
tsconfigwithreferencesto speed up"
The normalization process implements intelligent caching:
Cache keys are generated using stable hashing of the configuration:
import { stableHash } from 'stable-hash-x';
const optionsHash = stableHash(options);
const cacheKey = `${configFile}\0${optionsHash}`;The normalization process handles various error conditions:
Several optimizations improve normalization performance:
Install with Tessl CLI
npx tessl i tessl/npm-eslint-import-resolver-typescript