Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing conditions param for moduleResolve #3962

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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