Skip to content

Commit

Permalink
Merge pull request #14 from chengpeiquan/develop
Browse files Browse the repository at this point in the history
feat: add an option to turn off verifying content legitimacy
  • Loading branch information
chengpeiquan authored Sep 6, 2022
2 parents 683633e + 654513c commit 55f5c59
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BannerPluginOptions|See the type declarations below|[Optional parameter format](
```ts
/**
* Some options from `vite.config.[ts|js]`
* @tips This options type is supported since `0.2.0`
* @since 0.2.0
*/
export interface BannerPluginOptions {
/**
Expand All @@ -52,10 +52,19 @@ export interface BannerPluginOptions {

/**
* Whether to print error messages to the console
* @tips This option is supported since `0.4.0`
* @since 0.4.0
* @default `false`
*/
debug?: boolean

/**
* By default, the validity of the content will be verified.
* If set to `false`, no verification will be performed.
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
* @since 0.5.0
* @default `true`
*/
verify?: boolean
}
```

Expand Down
12 changes: 10 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BannerPluginOptions|请参阅下方的类型声明|[可选参数格式](#可选
```ts
/**
* 来自 `vite.config.[ts|js]` 的一些选项
* @tips 从 `0.2.0` 开始支持此选项类型
* @since 0.2.0
*/
export interface BannerPluginOptions {
/**
Expand All @@ -52,10 +52,18 @@ export interface BannerPluginOptions {

/**
* 是否将错误信息打印到控制台
* @tips 从 `0.4.0` 开始支持此选项
* @since 0.4.0
* @default `false`
*/
debug?: boolean

/**
* 默认会验证内容的合法性,设置为 `false` 则不验证
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
* @since 0.5.0
* @default `true`
*/
verify?: boolean
}
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-banner",
"description": "A banner plugin for Vite. Adds a banner to the top of each generated chunk.",
"version": "0.4.0",
"version": "0.5.0",
"author": "chengpeiquan <chengpeiquan@chengpeiquan.com>",
"license": "MIT",
"homepage": "https://github.com/chengpeiquan/vite-plugin-banner",
Expand Down
10 changes: 9 additions & 1 deletion src/libs/formatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function formatConfig(
content: '',
outDir: 'dist',
debug: false,
verify: true,
}

// Type of plugin options
Expand Down Expand Up @@ -49,13 +50,20 @@ export default function formatConfig(

// Update the `debug` option
config.debug = Boolean(options.debug)

// Update the `verify` option
if (typeof options.verify === 'boolean') {
config.verify = options.verify
}
}

// No verification required
if (!config.verify) return config

// Verify the validity of the incoming comment content
const errMsg: string = verifyBanner(config.content)
if (errMsg) {
throw new Error(`[vite-plugin-banner] ${errMsg}`)
}

return config
}
2 changes: 1 addition & 1 deletion src/libs/verifyBanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param content - The content of banner
* @return The error message, when success, if will be a empty string
*/
export default function (content: string): string {
export default function verifyBanner(content: string): string {
// illegal type
if (typeof content !== 'string') {
return 'The banner content must be a string.'
Expand Down
14 changes: 12 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Some options from `vite.config.[ts|js]`
* @tips This options type is supported since `0.2.0`
* @since 0.2.0
*/
export interface BannerPluginOptions {
/**
Expand All @@ -16,10 +16,19 @@ export interface BannerPluginOptions {

/**
* Whether to print error messages to the console
* @tips This option is supported since `0.4.0`
* @since 0.4.0
* @default `false`
*/
debug?: boolean

/**
* By default, the validity of the content will be verified.
* If set to `false`, no verification will be performed.
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
* @since 0.5.0
* @default `true`
*/
verify?: boolean
}

/**
Expand All @@ -29,4 +38,5 @@ export interface PluginConfig {
content: string
outDir: string
debug: boolean
verify: boolean
}

0 comments on commit 55f5c59

Please sign in to comment.