From 67baff9182854bbe184b6cf71f977920a05c27a3 Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 7 Mar 2024 18:22:10 +0800 Subject: [PATCH] fix: add missing `conditions` param for `moduleResolve` (#3962) * fix: add missing `conditions` param for `moduleResolve` related https://github.com/wooorm/import-meta-resolve/issues/24 * refactor: remove unnecessary `tryResolveId` --- @commitlint/resolve-extends/src/index.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/@commitlint/resolve-extends/src/index.ts b/@commitlint/resolve-extends/src/index.ts index f699e5840f..a8519ffa6d 100644 --- a/@commitlint/resolve-extends/src/index.ts +++ b/@commitlint/resolve-extends/src/index.ts @@ -26,6 +26,8 @@ const pathSuffixes = [ const specifierSuffixes = ['', '.js', '.json', '/index.js', '/index.json']; +const conditions = new Set(['import', 'node']); + /** * @see moduleResolve */ @@ -51,7 +53,7 @@ export const resolveFrom = (lookup: string, parent?: string): string => { for (const suffix of specifierSuffixes) { try { - return fileURLToPath(moduleResolve(lookup + suffix, base)); + return fileURLToPath(moduleResolve(lookup + suffix, base, conditions)); } catch (err) { if (!resolveError) { resolveError = err as Error; @@ -175,7 +177,7 @@ function resolveConfig( raw: string, context: ResolveExtendsContext = {} ): string { - const resolve = context.resolve || tryResolveId; + const resolve = context.resolve || resolveId; const id = getId(raw, context.prefix); let resolved: string; @@ -192,20 +194,6 @@ function resolveConfig( return resolved; } -function tryResolveId(id: string, context: ResolveExtendsContext) { - const cwd = context.cwd || process.cwd(); - - for (const suffix of ['', '.js', '.json', '/index.js', '/index.json']) { - try { - return fileURLToPath( - moduleResolve(id + suffix, pathToFileURL(path.join(cwd, id))) - ); - } catch {} - } - - return resolveId(id, context); -} - function resolveId( specifier: string, context: ResolveExtendsContext = {}