Skip to content

Commit 1eb9b5f

Browse files
authored
fix: fallback to resolve-from for Yarn P'n'P (#3941)
* fix: fallback to `require.resolve` for Yarn P'n'P close #3936 * refactor: use `resolve-from` package
1 parent 9351b8e commit 1eb9b5f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

@commitlint/resolve-extends/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"@commitlint/types": "^19.0.0",
4545
"global-directory": "^4.0.1",
4646
"import-meta-resolve": "^4.0.0",
47-
"lodash.mergewith": "^4.6.2"
47+
"lodash.mergewith": "^4.6.2",
48+
"resolve-from": "^5.0.0"
4849
},
4950
"gitHead": "d829bf6260304ca8d6811f329fcdd1b6c50e9749"
5051
}

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {pathToFileURL, fileURLToPath} from 'url';
55
import globalDirectory from 'global-directory';
66
import {moduleResolve} from 'import-meta-resolve';
77
import mergeWith from 'lodash.mergewith';
8+
import resolveFrom_ from 'resolve-from';
89
import {validateConfig} from '@commitlint/config-validator';
910
import type {ParserPreset, UserConfig} from '@commitlint/types';
1011

@@ -58,7 +59,15 @@ export const resolveFrom = (lookup: string, parent?: string): string => {
5859
}
5960
}
6061

61-
throw resolveError;
62+
try {
63+
/**
64+
* Yarn P'n'P does not support pure ESM well, this is only a workaround for
65+
* @see https://github.com/conventional-changelog/commitlint/issues/3936
66+
*/
67+
return resolveFrom_(path.dirname(fileURLToPath(base)), lookup);
68+
} catch {
69+
throw resolveError;
70+
}
6271
};
6372

6473
/**

0 commit comments

Comments
 (0)