Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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