Skip to content

Commit

Permalink
fix: add missing conditions param for moduleResolve (#3962)
Browse files Browse the repository at this point in the history
* fix: add missing `conditions` param for `moduleResolve`

related wooorm/import-meta-resolve#24

* refactor: remove unnecessary `tryResolveId`
  • Loading branch information
JounQin authored Mar 7, 2024
1 parent c085cff commit 67baff9
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const pathSuffixes = [

const specifierSuffixes = ['', '.js', '.json', '/index.js', '/index.json'];

const conditions = new Set(['import', 'node']);

/**
* @see moduleResolve
*/
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 = {}
Expand Down

0 comments on commit 67baff9

Please sign in to comment.