Skip to content

Commit

Permalink
feat: customErrorMessage option add duplicatedDeps param
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed Sep 11, 2023
1 parent 1f9e731 commit cd64734
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export interface Options {
* ```
*/
whitelist?: Record<string, string[]>;
customErrorMessage?: (issuePackagesMap: Map<string, string[]>) => string;
customErrorMessage?: (
issuePackagesMap: Map<string, string[]>,
duplicatedDeps: Record<string, string[]>,
) => string;
logLevel?: 'debug' | 'error';
}

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

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

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

0 comments on commit cd64734

Please sign in to comment.