Skip to content
Closed
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ pluginTypeCheck({
});
```

### suppressEnabledInfo

Whether to suppress the "Type checker is enabled. It may take some time." info message in production builds.

- **Type:** `boolean`
- **Default:** `false`
- **Example:**

Suppress the info message:

```js
pluginTypeCheck({
suppressEnabledInfo: true,
});
```

### tsCheckerOptions

Modify the options of `ts-checker-rspack-plugin`, please refer to [ts-checker-rspack-plugin - README](https://github.com/rspack-contrib/ts-checker-rspack-plugin#readme) to learn about available options.
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export type PluginTypeCheckerOptions = {
* @default true
*/
enable?: boolean;
/**
* Whether to suppress the "Type checker is enabled" info message.
* @default false
*/
suppressEnabledInfo?: boolean;
/**
* To modify the options of `ts-checker-rspack-plugin`.
* @see https://github.com/rspack-contrib/ts-checker-rspack-plugin#readme
Expand Down Expand Up @@ -51,7 +56,11 @@ export const pluginTypeCheck = (

api.modifyBundlerChain(
async (chain, { isProd, environment, CHAIN_ID }) => {
const { enable = true, forkTsCheckerOptions } = options;
const {
enable = true,
suppressEnabledInfo = false,
forkTsCheckerOptions,
} = options;
let { tsCheckerOptions } = options;
const { tsconfigPath } = environment;

Expand Down Expand Up @@ -135,7 +144,7 @@ export const pluginTypeCheck = (
mergeFn: deepmerge,
});

if (isProd) {
if (isProd && !suppressEnabledInfo) {
logger.info('Type checker is enabled. It may take some time.');
}

Expand Down
79 changes: 79 additions & 0 deletions test/suppress-enabled-info/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild } from '@rsbuild/core';
import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
import { proxyConsole } from '../helper';

const __dirname = dirname(fileURLToPath(import.meta.url));

test('should show "Type checker is enabled" message by default in production', async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [pluginTypeCheck()],
},
});

await rsbuild.build();

expect(
logs.find((log) =>
log.includes('Type checker is enabled. It may take some time.'),
),
).toBeTruthy();

restore();
});

test('should not show "Type checker is enabled" message when suppressEnabledInfo is true', async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [
pluginTypeCheck({
suppressEnabledInfo: true,
}),
],
},
});

await rsbuild.build();

expect(
logs.find((log) =>
log.includes('Type checker is enabled. It may take some time.'),
),
).toBeFalsy();

restore();
});

test('should show "Type checker is enabled" message when suppressEnabledInfo is false', async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [
pluginTypeCheck({
suppressEnabledInfo: false,
}),
],
},
});

await rsbuild.build();

expect(
logs.find((log) =>
log.includes('Type checker is enabled. It may take some time.'),
),
).toBeTruthy();

restore();
});
3 changes: 3 additions & 0 deletions test/suppress-enabled-info/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const num: number = 1;

console.log(num);
10 changes: 10 additions & 0 deletions test/suppress-enabled-info/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"skipLibCheck": true
},
"include": ["src"]
}