Skip to content

Commit 55f5c59

Browse files
authored
Merge pull request #14 from chengpeiquan/develop
feat: add an option to turn off verifying content legitimacy
2 parents 683633e + 654513c commit 55f5c59

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BannerPluginOptions|See the type declarations below|[Optional parameter format](
3636
```ts
3737
/**
3838
* Some options from `vite.config.[ts|js]`
39-
* @tips This options type is supported since `0.2.0`
39+
* @since 0.2.0
4040
*/
4141
export interface BannerPluginOptions {
4242
/**
@@ -52,10 +52,19 @@ export interface BannerPluginOptions {
5252

5353
/**
5454
* Whether to print error messages to the console
55-
* @tips This option is supported since `0.4.0`
55+
* @since 0.4.0
5656
* @default `false`
5757
*/
5858
debug?: boolean
59+
60+
/**
61+
* By default, the validity of the content will be verified.
62+
* If set to `false`, no verification will be performed.
63+
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
64+
* @since 0.5.0
65+
* @default `true`
66+
*/
67+
verify?: boolean
5968
}
6069
```
6170

README.zh-CN.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BannerPluginOptions|请参阅下方的类型声明|[可选参数格式](#可选
3636
```ts
3737
/**
3838
* 来自 `vite.config.[ts|js]` 的一些选项
39-
* @tips 从 `0.2.0` 开始支持此选项类型
39+
* @since 0.2.0
4040
*/
4141
export interface BannerPluginOptions {
4242
/**
@@ -52,10 +52,18 @@ export interface BannerPluginOptions {
5252

5353
/**
5454
* 是否将错误信息打印到控制台
55-
* @tips 从 `0.4.0` 开始支持此选项
55+
* @since 0.4.0
5656
* @default `false`
5757
*/
5858
debug?: boolean
59+
60+
/**
61+
* 默认会验证内容的合法性,设置为 `false` 则不验证
62+
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
63+
* @since 0.5.0
64+
* @default `true`
65+
*/
66+
verify?: boolean
5967
}
6068
```
6169

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vite-plugin-banner",
33
"description": "A banner plugin for Vite. Adds a banner to the top of each generated chunk.",
4-
"version": "0.4.0",
4+
"version": "0.5.0",
55
"author": "chengpeiquan <[email protected]>",
66
"license": "MIT",
77
"homepage": "https://github.com/chengpeiquan/vite-plugin-banner",

src/libs/formatConfig.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function formatConfig(
1414
content: '',
1515
outDir: 'dist',
1616
debug: false,
17+
verify: true,
1718
}
1819

1920
// Type of plugin options
@@ -49,13 +50,20 @@ export default function formatConfig(
4950

5051
// Update the `debug` option
5152
config.debug = Boolean(options.debug)
53+
54+
// Update the `verify` option
55+
if (typeof options.verify === 'boolean') {
56+
config.verify = options.verify
57+
}
5258
}
5359

60+
// No verification required
61+
if (!config.verify) return config
62+
5463
// Verify the validity of the incoming comment content
5564
const errMsg: string = verifyBanner(config.content)
5665
if (errMsg) {
5766
throw new Error(`[vite-plugin-banner] ${errMsg}`)
5867
}
59-
6068
return config
6169
}

src/libs/verifyBanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param content - The content of banner
44
* @return The error message, when success, if will be a empty string
55
*/
6-
export default function (content: string): string {
6+
export default function verifyBanner(content: string): string {
77
// illegal type
88
if (typeof content !== 'string') {
99
return 'The banner content must be a string.'

src/types/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Some options from `vite.config.[ts|js]`
3-
* @tips This options type is supported since `0.2.0`
3+
* @since 0.2.0
44
*/
55
export interface BannerPluginOptions {
66
/**
@@ -16,10 +16,19 @@ export interface BannerPluginOptions {
1616

1717
/**
1818
* Whether to print error messages to the console
19-
* @tips This option is supported since `0.4.0`
19+
* @since 0.4.0
2020
* @default `false`
2121
*/
2222
debug?: boolean
23+
24+
/**
25+
* By default, the validity of the content will be verified.
26+
* If set to `false`, no verification will be performed.
27+
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
28+
* @since 0.5.0
29+
* @default `true`
30+
*/
31+
verify?: boolean
2332
}
2433

2534
/**
@@ -29,4 +38,5 @@ export interface PluginConfig {
2938
content: string
3039
outDir: string
3140
debug: boolean
41+
verify: boolean
3242
}

0 commit comments

Comments
 (0)