Skip to content

Commit 9128685

Browse files
committed
feat: add more option jsdoc
1 parent ab45551 commit 9128685

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ export interface Options {
1616
* disable show package size can improve build speed because we get package size by api of https://bundlephobia.com/
1717
*/
1818
showPkgSize?: boolean;
19+
/**
20+
* useful in ci check
21+
*/
1922
throwErrorWhenDuplicated?: boolean;
20-
whiteList?: Record<string, string[]>;
21-
customErrorMessage?: (issuePackages: Map<string, string[]>) => string;
23+
/**
24+
* @example
25+
* ```javascript
26+
* {
27+
* axios: ['0.17.4', '1.4.0']
28+
* }
29+
* ```
30+
*/
31+
whitelist?: Record<string, string[]>;
32+
customErrorMessage?: (issuePackagesMap: Map<string, string[]>) => string;
2233
logLevel?: 'debug' | 'error';
2334
}
2435

@@ -48,11 +59,12 @@ function colorizeSize(kb: number) {
4859

4960
export default createUnplugin<Options | undefined>((options) => {
5061
const name = 'unplugin-detect-duplicated-deps';
62+
5163
let isVitePlugin = false;
5264
const {
5365
showPkgSize = true,
5466
throwErrorWhenDuplicated = false,
55-
whiteList = {},
67+
whitelist: whiteList = {},
5668
customErrorMessage,
5769
logLevel = 'debug',
5870
} = options ?? {};
@@ -215,7 +227,7 @@ export default createUnplugin<Options | undefined>((options) => {
215227
}
216228
}
217229
}
218-
const issueString = [...issuePackagesMap.entries()]
230+
const duplicatedDepsList = [...issuePackagesMap.entries()]
219231
.map(([packageName, _versions]) => {
220232
const versions = _versions.map((version) => `v${version}`).join(', ');
221233
return ` - ${packageName}: ${versions}`;
@@ -226,7 +238,7 @@ export default createUnplugin<Options | undefined>((options) => {
226238
throw new Error(
227239
customErrorMessage
228240
? customErrorMessage(issuePackagesMap)
229-
: `You can add following duplicated deps to whiteList to pass the check:\n${issueString}`,
241+
: `You can add following duplicated deps to whitelist option to suppress this error:\n${duplicatedDepsList}`,
230242
);
231243
}
232244
}

tests/fixtures/mono/app/vite.config.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineConfig({
55
plugins: [
66
UnpluginDetectDuplicatedDeps({
77
throwErrorWhenDuplicated: true,
8-
whiteList: {
8+
whitelist: {
99
axios: ['0.27.2', '1.4.0'],
1010
},
1111
}),

0 commit comments

Comments
 (0)