diff --git a/.yarn/cache/@esbuild-win32-arm64-npm-0.19.12-aecceea4ec-10.zip b/.yarn/cache/@esbuild-win32-arm64-npm-0.19.12-aecceea4ec-10.zip new file mode 100644 index 00000000..f785c71d Binary files /dev/null and b/.yarn/cache/@esbuild-win32-arm64-npm-0.19.12-aecceea4ec-10.zip differ diff --git a/.yarn/cache/@esbuild-win32-x64-npm-0.19.12-1bf4cb5f20-10.zip b/.yarn/cache/@esbuild-win32-x64-npm-0.19.12-1bf4cb5f20-10.zip new file mode 100644 index 00000000..2216b683 Binary files /dev/null and b/.yarn/cache/@esbuild-win32-x64-npm-0.19.12-1bf4cb5f20-10.zip differ diff --git a/.yarn/cache/@rollup-rollup-win32-arm64-msvc-npm-4.12.0-c2287b809a-10.zip b/.yarn/cache/@rollup-rollup-win32-arm64-msvc-npm-4.12.0-c2287b809a-10.zip new file mode 100644 index 00000000..d769719b Binary files /dev/null and b/.yarn/cache/@rollup-rollup-win32-arm64-msvc-npm-4.12.0-c2287b809a-10.zip differ diff --git a/.yarn/cache/@rollup-rollup-win32-x64-msvc-npm-4.12.0-b21d4991d2-10.zip b/.yarn/cache/@rollup-rollup-win32-x64-msvc-npm-4.12.0-b21d4991d2-10.zip new file mode 100644 index 00000000..0d03c67c Binary files /dev/null and b/.yarn/cache/@rollup-rollup-win32-x64-msvc-npm-4.12.0-b21d4991d2-10.zip differ diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 2fe5f8dc..974f8621 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -8,6 +8,7 @@ import { readHistory } from "./history.js"; import { readKnownIssues } from "./known.js"; import { FileSystemReportFiles } from "./plugin.js"; import { importWrapper } from "./utils/module.js"; +import { normalizeImportPath } from "./utils/path.js"; export const getPluginId = (key: string) => { return key.replace(/^@.*\//, "").replace(/[/\\]/g, "-"); @@ -19,21 +20,26 @@ const defaultConfig: Config = {}; export const findConfig = async (cwd: string, configPath?: string) => { if (configPath) { const resolved = resolve(cwd, configPath); + try { const stats = await stat(resolved); + if (stats.isFile()) { return resolved; } } catch (e) { console.error(e); } + throw new Error(`invalid config path ${resolved}: not a regular file`); } for (const configName of configNames) { const resolved = resolve(cwd, configName); + try { const stats = await stat(resolved); + if (stats.isFile()) { return resolved; } @@ -61,7 +67,7 @@ export const readConfig = async ( }; export const loadConfig = async (configPath: string): Promise => { - return (await import(configPath)).default; + return (await import(normalizeImportPath(configPath))).default; }; export const resolveConfig = async (config: Config, override: ConfigOverride = {}): Promise => { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2ed53809..f4bf38b7 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,6 +1,7 @@ export type * from "./api.js"; export * from "./utils/misc.js"; export * from "./utils/crypto.js"; +export * from "./utils/path.js"; export * from "./history.js"; export * from "./known.js"; export { resolveConfig, readConfig } from "./config.js"; diff --git a/packages/core/src/utils/module.ts b/packages/core/src/utils/module.ts index d92485fd..fa41dcca 100644 --- a/packages/core/src/utils/module.ts +++ b/packages/core/src/utils/module.ts @@ -1,7 +1,12 @@ +import { createRequire } from "node:module"; +import { normalizeImportPath } from "./path.js"; + +const require = createRequire(import.meta.url); + /** * Dead simple wrapper around import function to make it possible to mock it in the tests * @param path */ export const importWrapper = async (path: string) => { - return import(path); + return import(normalizeImportPath(require.resolve(path))); }; diff --git a/packages/core/src/utils/path.ts b/packages/core/src/utils/path.ts new file mode 100644 index 00000000..e473392a --- /dev/null +++ b/packages/core/src/utils/path.ts @@ -0,0 +1,9 @@ +import { pathToFileURL } from "node:url"; + +/** + * The function appends `file:///` protocol to the absolute paths on Windows due to ES modules imports specifics + * @param path + */ +export const normalizeImportPath = (path: string) => { + return pathToFileURL(path).href; +};