Skip to content

Commit c253f93

Browse files
committed
chore: fix Windows compatible issue
1 parent 37de595 commit c253f93

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

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

+22-10
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,42 @@ const dynamicImport = async <T>(id: string): Promise<T> => {
1515
return ('default' in imported && imported.default) || imported;
1616
};
1717

18-
/**
19-
* Fake file name to provide {@link moduleResolve} a filename to resolve from the configuration cwd
20-
*/
21-
const FAKE_FILE_NAME_FOR_RESOLVER = '__';
18+
const pathSuffixes = [
19+
'',
20+
'.js',
21+
'.json',
22+
`${path.sep}index.js`,
23+
`${path.sep}index.json`,
24+
];
25+
26+
const specifierSuffixes = ['', '.js', '.json', '/index.js', '/index.json'];
2227

2328
/**
2429
* @see moduleResolve
2530
*/
26-
export const resolveFrom = (specifier: string, parent?: string): string => {
27-
let resolved: URL;
31+
export const resolveFrom = (lookup: string, parent?: string): string => {
32+
if (path.isAbsolute(lookup)) {
33+
for (const suffix of pathSuffixes) {
34+
const filename = lookup + suffix;
35+
if (fs.existsSync(filename)) {
36+
return filename;
37+
}
38+
}
39+
}
40+
2841
let resolveError: Error | undefined;
2942

3043
const base = pathToFileURL(
3144
parent
3245
? fs.statSync(parent).isDirectory()
33-
? path.join(parent, FAKE_FILE_NAME_FOR_RESOLVER)
46+
? path.join(parent, 'noop.js')
3447
: parent
3548
: import.meta.url
3649
);
3750

38-
for (const suffix of ['', '.js', '.json', '/index.js', '/index.json']) {
51+
for (const suffix of specifierSuffixes) {
3952
try {
40-
resolved = moduleResolve(specifier + suffix, base);
41-
return fileURLToPath(resolved);
53+
return fileURLToPath(moduleResolve(lookup + suffix, base));
4254
} catch (err) {
4355
if (!resolveError) {
4456
resolveError = err as Error;

0 commit comments

Comments
 (0)