diff --git a/lib/config-resolution.ts b/lib/config-resolution.ts index c2559223..f12cbf85 100644 --- a/lib/config-resolution.ts +++ b/lib/config-resolution.ts @@ -1,4 +1,5 @@ import { existsSync } from 'node:fs'; +import { importAbs } from './import.js'; import type { Plugin, Config, Rules, ConfigsToRules } from './types.js'; /** @@ -31,7 +32,7 @@ async function resolveConfigRules(config: Config): Promise { continue; } - const { default: config } = await import(extend); + const { default: config } = await importAbs(extend); const nestedRules = await resolveConfigRules(config); Object.assign(rules, nestedRules); } diff --git a/lib/import.ts b/lib/import.ts new file mode 100644 index 00000000..5f14358e --- /dev/null +++ b/lib/import.ts @@ -0,0 +1,10 @@ +import { pathToFileURL } from 'node:url'; + +/** + * Ensure that we import absolute paths correctly in Windows. + * https://github.com/nodejs/node/issues/31710 + */ +export function importAbs(path: string) { + const urlHref = pathToFileURL(path).href; + return import(urlHref); +} diff --git a/lib/package-json.ts b/lib/package-json.ts index fe066c07..1ca75f63 100644 --- a/lib/package-json.ts +++ b/lib/package-json.ts @@ -1,5 +1,6 @@ import { join } from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; +import { importAbs } from './import.js'; import type { Plugin } from './types.js'; import type { PackageJson } from 'type-fest'; @@ -28,7 +29,7 @@ export async function loadPlugin(path: string): Promise { pluginPackageJson.main ?? 'index.js', // This is NPM's default value for this field. pluginPackageJson.main?.endsWith('/') ? 'index.js' : '' ); - const { default: plugin } = await import(pluginEntryPoint); + const { default: plugin } = await importAbs(pluginEntryPoint); if (!plugin.rules) { throw new Error('Could not find exported `rules` object in ESLint plugin.'); }