Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add enable option #2

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
Loading