Skip to content

Commit cd64734

Browse files
committed
feat: customErrorMessage option add duplicatedDeps param
1 parent 1f9e731 commit cd64734

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export interface Options {
2929
* ```
3030
*/
3131
whitelist?: Record<string, string[]>;
32-
customErrorMessage?: (issuePackagesMap: Map<string, string[]>) => string;
32+
customErrorMessage?: (
33+
issuePackagesMap: Map<string, string[]>,
34+
duplicatedDeps: Record<string, string[]>,
35+
) => string;
3336
logLevel?: 'debug' | 'error';
3437
}
3538

@@ -216,9 +219,13 @@ export default createUnplugin<Options | undefined>((options) => {
216219

217220
if (throwErrorWhenDuplicated) {
218221
const issuePackagesMap = new Map<string, string[]>();
222+
const duplicatedDeps: Record<string, string[]> = {};
219223
for (const [packageName, versionsMap] of packageToVersionsMap.entries()) {
220224
if (versionsMap.size < 2) continue;
221225

226+
duplicatedDeps[packageName] = [...versionsMap.keys()].sort((a, b) =>
227+
gt(a, b) ? 1 : -1,
228+
);
222229
for (const version of versionsMap.keys()) {
223230
const pass =
224231
packageName in whiteList && whiteList[packageName].includes(version);
@@ -239,7 +246,7 @@ export default createUnplugin<Options | undefined>((options) => {
239246
if (issuePackagesMap.size > 0) {
240247
throw new Error(
241248
customErrorMessage
242-
? customErrorMessage(issuePackagesMap)
249+
? customErrorMessage(issuePackagesMap, duplicatedDeps)
243250
: `You can add following duplicated deps to whitelist option to suppress this error:\n${duplicatedDepsList}`,
244251
);
245252
}

0 commit comments

Comments
 (0)