diff --git a/src/index.ts b/src/index.ts index ab34a83..d32b5b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { ResolverFactory } from 'oxc-resolver' import { normalizeOptions } from './normalizeOptions' import { hashObject } from './utils' -let cacheOptionsHash: string | undefined +let cachedOptionsHash: string | undefined let cachedResolver: ResolverFactory | undefined export function resolve(source: string, file: string, options?: NapiResolveOptions | null, resolver: ResolverFactory | null = null): { found: boolean, path: string | null | undefined } { @@ -16,10 +16,10 @@ export function resolve(source: string, file: string, options?: NapiResolveOptio options ??= {} const optionsHash = hashObject(options) - if (!cachedResolver || cacheOptionsHash !== optionsHash) { + if (!cachedResolver || cachedOptionsHash !== optionsHash) { options = normalizeOptions(options) cachedResolver = new ResolverFactory(options) - cacheOptionsHash = optionsHash + cachedOptionsHash = optionsHash } resolver = cachedResolver @@ -37,7 +37,7 @@ export function resolve(source: string, file: string, options?: NapiResolveOptio export const interfaceVersion = 2 export function createOxcImportResolver(options?: NapiResolveOptions | null) { - const resolver = new ResolverFactory(options) + const resolver = new ResolverFactory(normalizeOptions(options)) return { interfaceVersion: 3, diff --git a/tests/eslint-plugin/rules/no-extraneous-dependencies.test.ts b/tests/eslint-plugin/rules/no-extraneous-dependencies.test.ts index c7d45b8..0102321 100644 --- a/tests/eslint-plugin/rules/no-extraneous-dependencies.test.ts +++ b/tests/eslint-plugin/rules/no-extraneous-dependencies.test.ts @@ -1,5 +1,4 @@ -import type { NapiResolveOptions } from 'oxc-resolver' -import { oxcResolver, run, testFilePath } from '../utils' +import { createOxcImportResolver, run, testFilePath } from '../utils' run({ rule: 'no-extraneous-dependencies', @@ -13,13 +12,13 @@ run({ { code: 'import "@custom-internal-alias/api/service";', settings: { - 'import-x/resolver': { - [oxcResolver]: { + 'import-x/resolver-next': [ + createOxcImportResolver({ alias: { '@custom-internal-alias': [testFilePath('internal-modules')], }, - } satisfies NapiResolveOptions, - }, + }), + ], }, }, ], @@ -27,13 +26,13 @@ run({ { code: 'import jest from "alias/jest";', settings: { - 'import-x/resolver': { - [oxcResolver]: { + 'import-x/resolver-next': [ + createOxcImportResolver({ alias: { 'alias/jest': ['jest'], }, - } satisfies NapiResolveOptions, - }, + }), + ], }, errors: [ // missing dependency is jest not alias diff --git a/tests/eslint-plugin/rules/no-internal-modules.test.ts b/tests/eslint-plugin/rules/no-internal-modules.test.ts index 3885d0f..f0e92ff 100644 --- a/tests/eslint-plugin/rules/no-internal-modules.test.ts +++ b/tests/eslint-plugin/rules/no-internal-modules.test.ts @@ -1,5 +1,4 @@ -import type { NapiResolveOptions } from 'oxc-resolver' -import { oxcResolver, run, testFilePath } from '../utils' +import { createOxcImportResolver, run, testFilePath } from '../utils' run({ rule: 'no-internal-modules', @@ -19,13 +18,13 @@ run({ }, ], settings: { - 'import-x/resolver': { - [oxcResolver]: { + 'import-x/resolver-next': [ + createOxcImportResolver({ alias: { '@': [testFilePath('internal-modules')], }, - } satisfies NapiResolveOptions, - }, + }), + ], }, }, ], diff --git a/tests/eslint-plugin/rules/order.test.ts b/tests/eslint-plugin/rules/order.test.ts index fc0926f..83083a0 100644 --- a/tests/eslint-plugin/rules/order.test.ts +++ b/tests/eslint-plugin/rules/order.test.ts @@ -1,5 +1,4 @@ -import type { NapiResolveOptions } from 'oxc-resolver' -import { oxcResolver, run, testFilePath } from '../utils' +import { createOxcImportResolver, run, testFilePath } from '../utils' run({ rule: 'order', @@ -54,13 +53,13 @@ run({ }, ], settings: { - 'import-x/resolver': { - [oxcResolver]: { + 'import-x/resolver-next': [ + createOxcImportResolver({ alias: { '@': [testFilePath('internal-modules')], }, - } satisfies NapiResolveOptions, - }, + }), + ], }, }, ], diff --git a/tests/eslint-plugin/utils.ts b/tests/eslint-plugin/utils.ts index b81b953..aa14e2a 100644 --- a/tests/eslint-plugin/utils.ts +++ b/tests/eslint-plugin/utils.ts @@ -1,14 +1,13 @@ import type { RuleTesterInitOptions, TestCasesOptions } from 'eslint-vitest-rule-tester' import path from 'node:path' -import { cwd } from 'node:process' import tsParser from '@typescript-eslint/parser' import { rules } from 'eslint-plugin-import-x' import { run as _run } from 'eslint-vitest-rule-tester' +import { createOxcImportResolver } from '../../src' -import { createOxcResolver } from '../../src' - -export * from 'eslint-vitest-rule-tester' +export { createOxcImportResolver } from '../../src' export { unindent as $ } from 'eslint-vitest-rule-tester' +export * from 'eslint-vitest-rule-tester' export interface ExtendedRuleTesterOptions extends RuleTesterInitOptions, TestCasesOptions { lang?: 'js' | 'ts' @@ -26,8 +25,6 @@ const defaultFilenames = { ts: 'tests/eslint-plugin/fixtures/foo.ts', } -export const oxcResolver = path.resolve(cwd(), 'dist/index.cjs') - export function run(options: ExtendedRuleTesterOptions) { return _run({ recursive: false, @@ -37,7 +34,7 @@ export function run(options: ExtendedRuleTesterOptions) { settings: { ...(options.lang === 'js' ? {} : { 'import-x/parsers': { [require.resolve('@typescript-eslint/parser')]: ['.ts'] } }), 'import-x/resolver-next': [ - createOxcResolver({ + createOxcImportResolver({ tsconfig: { configFile: path.resolve(FIXTURES_PATH, 'tsconfig.json'), references: 'auto',