Skip to content

Commit 67baff9

Browse files
authored
fix: add missing conditions param for moduleResolve (#3962)
* fix: add missing `conditions` param for `moduleResolve` related wooorm/import-meta-resolve#24 * refactor: remove unnecessary `tryResolveId`
1 parent c085cff commit 67baff9

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

@commitlint/resolve-extends/src/index.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const pathSuffixes = [
2626

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

29+
const conditions = new Set(['import', 'node']);
30+
2931
/**
3032
* @see moduleResolve
3133
*/
@@ -51,7 +53,7 @@ export const resolveFrom = (lookup: string, parent?: string): string => {
5153

5254
for (const suffix of specifierSuffixes) {
5355
try {
54-
return fileURLToPath(moduleResolve(lookup + suffix, base));
56+
return fileURLToPath(moduleResolve(lookup + suffix, base, conditions));
5557
} catch (err) {
5658
if (!resolveError) {
5759
resolveError = err as Error;
@@ -175,7 +177,7 @@ function resolveConfig(
175177
raw: string,
176178
context: ResolveExtendsContext = {}
177179
): string {
178-
const resolve = context.resolve || tryResolveId;
180+
const resolve = context.resolve || resolveId;
179181
const id = getId(raw, context.prefix);
180182

181183
let resolved: string;
@@ -192,20 +194,6 @@ function resolveConfig(
192194
return resolved;
193195
}
194196

195-
function tryResolveId(id: string, context: ResolveExtendsContext) {
196-
const cwd = context.cwd || process.cwd();
197-
198-
for (const suffix of ['', '.js', '.json', '/index.js', '/index.json']) {
199-
try {
200-
return fileURLToPath(
201-
moduleResolve(id + suffix, pathToFileURL(path.join(cwd, id)))
202-
);
203-
} catch {}
204-
}
205-
206-
return resolveId(id, context);
207-
}
208-
209197
function resolveId(
210198
specifier: string,
211199
context: ResolveExtendsContext = {}

0 commit comments

Comments
 (0)