Skip to content

Commit

Permalink
feat: add enable option
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Dec 11, 2024
1 parent 22ce637 commit b222bf1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ Install:
npm add rsbuild-plugin-publint -D
```

Add plugin to your `rsbuild.config.ts`:
Add plugin to your `rslib.config.ts` or `rsbuild.config.ts`:

```ts
// `rslib.config.ts` or `rsbuild.config.ts`
import { pluginPublint } from "rsbuild-plugin-publint";

export default {
Expand All @@ -37,6 +36,21 @@ export default {

## Options

### enable

Whether to enable publint.

- Type: `boolean`
- Default: `true`

For example, only run publint in the CI environment:

```ts
pluginPublint({
enable: Boolean(process.env.CI),
});
```

### publintOptions

Options for publint. See [publint - API](https://github.com/bluwy/publint/blob/master/pkg/README.md#api) for more details.
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import color from 'picocolors';
import type { Options } from 'publint';

export type PluginPublintOptions = {
/**
* Whether to enable publint.
* @default true
*/
enable?: boolean;
/**
* Options for publint.
* @see https://github.com/bluwy/publint/blob/master/pkg/README.md#api
Expand All @@ -18,6 +23,12 @@ export const pluginPublint = (
name: 'plugin-publint',

setup(api) {
const { enable = true } = options;

if (!enable) {
return;
}

api.onAfterBuild(async () => {
const { publint } = await import('publint');
const { formatMessage } = await import('publint/utils');
Expand Down
15 changes: 15 additions & 0 deletions test/basic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ test('should allow to pass publint options', async () => {

restore();
});

test('should allow to disable publint', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [
pluginPublint({
enable: false,
}),
],
},
});

await expect(rsbuild.build()).resolves.toBeTruthy();
});

0 comments on commit b222bf1

Please sign in to comment.