@rsbuild/plugin-type-check 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,9 +12,9 @@ An Rsbuild plugin to run TypeScript type checker in a separate process.
12
12
 
13
13
  ## Introduction
14
14
 
15
- This plugin internally integrates with [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin).
15
+ This plugin internally integrates with [ts-checker-rspack-plugin](https://github.com/rspack-contrib/ts-checker-rspack-plugin).
16
16
 
17
- The type checking logic of `fork-ts-checker-webpack-plugin` is similar to the native `tsc` command of TypeScript. It automatically reads the configuration options from `tsconfig.json` and can also be modified via the configuration options provided by the Type Check plugin.
17
+ The type checking logic of `ts-checker-rspack-plugin` is similar to the native `tsc` command of TypeScript. It automatically reads the configuration options from `tsconfig.json` and can also be modified via the configuration options provided by the Type Check plugin.
18
18
 
19
19
  The behavior of the plugin differs in the development and production builds:
20
20
 
@@ -96,9 +96,9 @@ pluginTypeCheck({
96
96
  });
97
97
  ```
98
98
 
99
- ### forkTsCheckerOptions
99
+ ### tsCheckerOptions
100
100
 
101
- To modify the options of `fork-ts-checker-webpack-plugin`, please refer to [fork-ts-checker-webpack-plugin - README](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#readme) to learn about available options.
101
+ 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.
102
102
 
103
103
  - **Type:** `Object | Function`
104
104
  - **Default:**
@@ -107,7 +107,7 @@ To modify the options of `fork-ts-checker-webpack-plugin`, please refer to [fork
107
107
  const defaultOptions = {
108
108
  typescript: {
109
109
  // set 'readonly' to avoid emitting tsbuildinfo,
110
- // as the generated tsbuildinfo will break fork-ts-checker
110
+ // as the generated tsbuildinfo will break ts-checker-rspack-plugin
111
111
  mode: "readonly",
112
112
  // enable build when using project reference
113
113
  build: useReference,
@@ -136,11 +136,11 @@ const defaultOptions = {
136
136
 
137
137
  #### Object Type
138
138
 
139
- When the value of `forkTsCheckerOptions` is an object, it will be deeply merged with the default configuration.
139
+ When the value of `tsCheckerOptions` is an object, it will be deeply merged with the default configuration.
140
140
 
141
141
  ```ts
142
142
  pluginTypeCheck({
143
- forkTsCheckerOptions: {
143
+ tsCheckerOptions: {
144
144
  issue: {
145
145
  exclude: [({ file = "" }) => /[\\/]some-folder[\\/]/.test(file)],
146
146
  },
@@ -150,11 +150,11 @@ pluginTypeCheck({
150
150
 
151
151
  #### Function Type
152
152
 
153
- When the value of `forkTsCheckerOptions` is a function, the default configuration will be passed as the first argument. You can directly modify the configuration object or return an object as the final configuration.
153
+ When the value of `tsCheckerOptions` is a function, the default configuration will be passed as the first argument. You can directly modify the configuration object or return an object as the final configuration.
154
154
 
155
155
  ```ts
156
156
  pluginTypeCheck({
157
- forkTsCheckerOptions(options) {
157
+ tsCheckerOptions(options) {
158
158
  options.async = false;
159
159
  return options;
160
160
  },
@@ -169,7 +169,7 @@ For example, the type mismatch error can be excluded using `code: 'TS2345'`:
169
169
 
170
170
  ```ts
171
171
  pluginTypeCheck({
172
- forkTsCheckerOptions: {
172
+ tsCheckerOptions: {
173
173
  issue: {
174
174
  // Ignore "Argument of type 'string' is not assignable to parameter of type 'number'.ts(2345)"
175
175
  exclude: [{ code: "TS2345" }],
@@ -182,7 +182,7 @@ Or exclude files under `/some-folder/` using `file`:
182
182
 
183
183
  ```ts
184
184
  pluginTypeCheck({
185
- forkTsCheckerOptions: {
185
+ tsCheckerOptions: {
186
186
  issue: {
187
187
  exclude: [({ file = "" }) => /[\\/]some-folder[\\/]/.test(file)],
188
188
  },
@@ -193,7 +193,7 @@ pluginTypeCheck({
193
193
  ## Notes
194
194
 
195
195
  - If you have enabled `ts-loader` in your project and manually configured `compileOnly: false`, please disable the Type Check plugin to avoid duplicate type checking.
196
- - Some errors will be displayed as warnings in IDEs such as VS Code, but they will still be displayed as errors in the `fork-ts-checker-webpack-plugin` check. For details, please refer to: [Why are some errors reported as warnings?](https://code.visualstudio.com/docs/typescript/typescript-compiling#_why-are-some-errors-reported-as-warnings).
196
+ - Some errors will be displayed as warnings in IDEs such as VS Code, but they will still be displayed as errors in the `ts-checker-rspack-plugin` check. For details, please refer to: [Why are some errors reported as warnings?](https://code.visualstudio.com/docs/typescript/typescript-compiling#_why-are-some-errors-reported-as-warnings).
197
197
 
198
198
  ## Performance Optimization
199
199
 
@@ -210,7 +210,7 @@ For example, properly configuring the `include` and `exclude` scopes in `tsconfi
210
210
 
211
211
  ## Vue Components
212
212
 
213
- `fork-ts-checker-webpack-plugin` does not support checking TypeScript code in `.vue` components. You can check for type issues in `.vue` files in the following ways:
213
+ `ts-checker-rspack-plugin` does not support checking TypeScript code in `.vue` components. You can check for type issues in `.vue` files in the following ways:
214
214
 
215
215
  1. Install the [vue-tsc](https://github.com/vuejs/language-tools/tree/master/packages/tsc) package, which provides the ability to check types in `.vue` files.
216
216
 
package/dist/index.cjs CHANGED
@@ -1,128 +1,145 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- PLUGIN_TYPE_CHECK_NAME: () => PLUGIN_TYPE_CHECK_NAME,
34
- pluginTypeCheck: () => pluginTypeCheck
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
+ return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
+ }();
5
+ // The require scope
6
+ var __webpack_require__ = {};
7
+ /************************************************************************/ // webpack/runtime/compat_get_default_export
8
+ (()=>{
9
+ // getDefaultExport function for compatibility with non-ESM modules
10
+ __webpack_require__.n = function(module) {
11
+ var getter = module && module.__esModule ? function() {
12
+ return module['default'];
13
+ } : function() {
14
+ return module;
15
+ };
16
+ __webpack_require__.d(getter, {
17
+ a: getter
18
+ });
19
+ return getter;
20
+ };
21
+ })();
22
+ // webpack/runtime/define_property_getters
23
+ (()=>{
24
+ __webpack_require__.d = function(exports1, definition) {
25
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
26
+ enumerable: true,
27
+ get: definition[key]
28
+ });
29
+ };
30
+ })();
31
+ // webpack/runtime/has_own_property
32
+ (()=>{
33
+ __webpack_require__.o = function(obj, prop) {
34
+ return Object.prototype.hasOwnProperty.call(obj, prop);
35
+ };
36
+ })();
37
+ // webpack/runtime/make_namespace_object
38
+ (()=>{
39
+ // define __esModule on exports
40
+ __webpack_require__.r = function(exports1) {
41
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
42
+ value: 'Module'
43
+ });
44
+ Object.defineProperty(exports1, '__esModule', {
45
+ value: true
46
+ });
47
+ };
48
+ })();
49
+ /************************************************************************/ var __webpack_exports__ = {};
50
+ // ESM COMPAT FLAG
51
+ __webpack_require__.r(__webpack_exports__);
52
+ // EXPORTS
53
+ __webpack_require__.d(__webpack_exports__, {
54
+ PLUGIN_TYPE_CHECK_NAME: ()=>/* binding */ PLUGIN_TYPE_CHECK_NAME,
55
+ pluginTypeCheck: ()=>/* binding */ pluginTypeCheck
35
56
  });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
- // node_modules/.pnpm/tsup@8.2.4_postcss@8.4.38_typescript@5.5.4/node_modules/tsup/assets/cjs_shims.js
39
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
40
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
41
-
42
- // src/index.ts
43
- var import_node_fs = __toESM(require("fs"), 1);
44
- var import_node_module = require("module");
45
- var import_core = require("@rsbuild/core");
46
- var import_deepmerge = __toESM(require("deepmerge"), 1);
47
- var import_fork_ts_checker_webpack_plugin = __toESM(require("fork-ts-checker-webpack-plugin"), 1);
48
- var import_json5 = __toESM(require("json5"), 1);
49
- var import_reduce_configs = require("reduce-configs");
50
- var require2 = (0, import_node_module.createRequire)(importMetaUrl);
51
- var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
52
- var pluginTypeCheck = (options = {}) => {
53
- return {
54
- name: PLUGIN_TYPE_CHECK_NAME,
55
- setup(api) {
56
- const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
57
- const checkedTsconfig = /* @__PURE__ */ new Map();
58
- api.modifyBundlerChain(
59
- async (chain, { isProd, environment, CHAIN_ID }) => {
60
- const { enable = true, forkTsCheckerOptions } = options;
61
- const { tsconfigPath } = environment;
62
- if (!tsconfigPath || enable === false) {
63
- return;
64
- }
65
- if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
66
- return;
67
- }
68
- checkedTsconfig.set(tsconfigPath, environment.name);
69
- let typescriptPath;
70
- try {
71
- typescriptPath = require2.resolve("typescript", {
72
- paths: [api.context.rootPath]
57
+ const external_node_fs_namespaceObject = require("node:fs");
58
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
59
+ const external_node_module_namespaceObject = require("node:module");
60
+ const core_namespaceObject = require("@rsbuild/core");
61
+ const external_deepmerge_namespaceObject = require("deepmerge");
62
+ var external_deepmerge_default = /*#__PURE__*/ __webpack_require__.n(external_deepmerge_namespaceObject);
63
+ const external_json5_namespaceObject = require("json5");
64
+ var external_json5_default = /*#__PURE__*/ __webpack_require__.n(external_json5_namespaceObject);
65
+ const external_reduce_configs_namespaceObject = require("reduce-configs");
66
+ const external_ts_checker_rspack_plugin_namespaceObject = require("ts-checker-rspack-plugin");
67
+ const src_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
68
+ const PLUGIN_TYPE_CHECK_NAME = 'rsbuild:type-check';
69
+ const pluginTypeCheck = (options = {})=>({
70
+ name: PLUGIN_TYPE_CHECK_NAME,
71
+ setup (api) {
72
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
73
+ const checkedTsconfig = new Map();
74
+ api.modifyBundlerChain(async (chain, { isProd, environment, CHAIN_ID })=>{
75
+ const { enable = true, forkTsCheckerOptions } = options;
76
+ let { tsCheckerOptions } = options;
77
+ const { tsconfigPath } = environment;
78
+ // compatible with the legacy option
79
+ if (void 0 === tsCheckerOptions && void 0 !== forkTsCheckerOptions) tsCheckerOptions = forkTsCheckerOptions;
80
+ if (!tsconfigPath || false === enable) return;
81
+ // If there are identical tsconfig.json files,
82
+ // apply type checker only once to avoid duplicate checks.
83
+ if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) return;
84
+ checkedTsconfig.set(tsconfigPath, environment.name);
85
+ // use typescript of user project
86
+ let typescriptPath;
87
+ try {
88
+ typescriptPath = src_require.resolve('typescript', {
89
+ paths: [
90
+ api.context.rootPath
91
+ ]
92
+ });
93
+ } catch (err) {
94
+ core_namespaceObject.logger.warn('"typescript" is not found in current project, Type checker will not work.');
95
+ return;
96
+ }
97
+ const { references } = external_json5_default().parse(external_node_fs_default().readFileSync(tsconfigPath, 'utf-8'));
98
+ const useReference = Array.isArray(references) && references.length > 0;
99
+ const defaultOptions = {
100
+ typescript: {
101
+ // set 'readonly' to avoid emitting tsbuildinfo,
102
+ // as the generated tsbuildinfo will break ts-checker-rspack-plugin
103
+ mode: 'readonly',
104
+ // enable build when using project reference
105
+ build: useReference,
106
+ // avoid OOM issue
107
+ memoryLimit: 8192,
108
+ // use tsconfig of user project
109
+ configFile: tsconfigPath,
110
+ // use typescript of user project
111
+ typescriptPath
112
+ },
113
+ issue: {
114
+ // ignore types errors from node_modules
115
+ exclude: [
116
+ ({ file = '' })=>NODE_MODULES_REGEX.test(file)
117
+ ]
118
+ },
119
+ logger: {
120
+ log () {
121
+ // do nothing
122
+ // we only want to display error messages
123
+ },
124
+ error (message) {
125
+ console.error(message.replace(/ERROR/g, 'Type Error'));
126
+ }
127
+ }
128
+ };
129
+ const mergedOptions = (0, external_reduce_configs_namespaceObject.reduceConfigs)({
130
+ initial: defaultOptions,
131
+ config: tsCheckerOptions,
132
+ mergeFn: external_deepmerge_default()
133
+ });
134
+ if (isProd) core_namespaceObject.logger.info('Type checker is enabled. It may take some time.');
135
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(external_ts_checker_rspack_plugin_namespaceObject.TsCheckerRspackPlugin, [
136
+ mergedOptions
137
+ ]);
73
138
  });
74
- } catch (err) {
75
- import_core.logger.warn(
76
- '"typescript" is not found in current project, Type checker will not work.'
77
- );
78
- return;
79
- }
80
- const { references } = import_json5.default.parse(
81
- import_node_fs.default.readFileSync(tsconfigPath, "utf-8")
82
- );
83
- const useReference = Array.isArray(references) && references.length > 0;
84
- const defaultOptions = {
85
- typescript: {
86
- // set 'readonly' to avoid emitting tsbuildinfo,
87
- // as the generated tsbuildinfo will break fork-ts-checker
88
- mode: "readonly",
89
- // enable build when using project reference
90
- build: useReference,
91
- // avoid OOM issue
92
- memoryLimit: 8192,
93
- // use tsconfig of user project
94
- configFile: tsconfigPath,
95
- // use typescript of user project
96
- typescriptPath
97
- },
98
- issue: {
99
- // ignore types errors from node_modules
100
- exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
101
- },
102
- logger: {
103
- log() {
104
- },
105
- error(message) {
106
- console.error(message.replace(/ERROR/g, "Type Error"));
107
- }
108
- }
109
- };
110
- const typeCheckerOptions = (0, import_reduce_configs.reduceConfigs)({
111
- initial: defaultOptions,
112
- config: forkTsCheckerOptions,
113
- mergeFn: import_deepmerge.default
114
- });
115
- if (isProd) {
116
- import_core.logger.info("Type checker is enabled. It may take some time.");
117
- }
118
- chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(import_fork_ts_checker_webpack_plugin.default, [typeCheckerOptions]);
119
139
  }
120
- );
121
- }
122
- };
123
- };
124
- // Annotate the CommonJS export names for ESM import in node:
125
- 0 && (module.exports = {
126
- PLUGIN_TYPE_CHECK_NAME,
127
- pluginTypeCheck
140
+ });
141
+ var __webpack_export_target__ = exports;
142
+ for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
143
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
144
+ value: true
128
145
  });
package/dist/index.d.ts CHANGED
@@ -1,21 +1,23 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
3
- import { ConfigChain } from 'reduce-configs';
4
-
5
- type ForkTsCheckerOptions = NonNullable<ConstructorParameters<typeof ForkTSCheckerPlugin>[0]>;
6
- type PluginTypeCheckerOptions = {
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
+ import { type ConfigChain } from 'reduce-configs';
3
+ import { TsCheckerRspackPlugin } from 'ts-checker-rspack-plugin';
4
+ type TsCheckerOptions = NonNullable<ConstructorParameters<typeof TsCheckerRspackPlugin>[0]>;
5
+ export type PluginTypeCheckerOptions = {
7
6
  /**
8
7
  * Whether to enable TypeScript type checking.
9
8
  * @default true
10
9
  */
11
10
  enable?: boolean;
12
11
  /**
13
- * To modify the options of `fork-ts-checker-webpack-plugin`.
14
- * @see https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#readme
12
+ * To modify the options of `ts-checker-rspack-plugin`.
13
+ * @see https://github.com/rspack-contrib/ts-checker-rspack-plugin#readme
15
14
  */
16
- forkTsCheckerOptions?: ConfigChain<ForkTsCheckerOptions>;
15
+ tsCheckerOptions?: ConfigChain<TsCheckerOptions>;
16
+ /**
17
+ * @deprecated use `tsCheckerOptions` instead.
18
+ */
19
+ forkTsCheckerOptions?: ConfigChain<TsCheckerOptions>;
17
20
  };
18
- declare const PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
19
- declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
20
-
21
- export { PLUGIN_TYPE_CHECK_NAME, type PluginTypeCheckerOptions, pluginTypeCheck };
21
+ export declare const PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
22
+ export declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
23
+ export {};
package/dist/index.js CHANGED
@@ -1,86 +1,82 @@
1
- // src/index.ts
2
- import fs from "node:fs";
3
- import { createRequire } from "node:module";
4
- import { logger } from "@rsbuild/core";
5
- import deepmerge from "deepmerge";
6
- import ForkTSCheckerPlugin from "fork-ts-checker-webpack-plugin";
7
- import json5 from "json5";
8
- import { reduceConfigs } from "reduce-configs";
9
- var require2 = createRequire(import.meta.url);
10
- var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
11
- var pluginTypeCheck = (options = {}) => {
12
- return {
13
- name: PLUGIN_TYPE_CHECK_NAME,
14
- setup(api) {
15
- const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
16
- const checkedTsconfig = /* @__PURE__ */ new Map();
17
- api.modifyBundlerChain(
18
- async (chain, { isProd, environment, CHAIN_ID }) => {
19
- const { enable = true, forkTsCheckerOptions } = options;
20
- const { tsconfigPath } = environment;
21
- if (!tsconfigPath || enable === false) {
22
- return;
23
- }
24
- if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
25
- return;
26
- }
27
- checkedTsconfig.set(tsconfigPath, environment.name);
28
- let typescriptPath;
29
- try {
30
- typescriptPath = require2.resolve("typescript", {
31
- paths: [api.context.rootPath]
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_deepmerge__ from "deepmerge";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_json5__ from "json5";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs__ from "reduce-configs";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_ts_checker_rspack_plugin__ from "ts-checker-rspack-plugin";
8
+ const src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
9
+ const PLUGIN_TYPE_CHECK_NAME = 'rsbuild:type-check';
10
+ const pluginTypeCheck = (options = {})=>({
11
+ name: PLUGIN_TYPE_CHECK_NAME,
12
+ setup (api) {
13
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
14
+ const checkedTsconfig = new Map();
15
+ api.modifyBundlerChain(async (chain, { isProd, environment, CHAIN_ID })=>{
16
+ const { enable = true, forkTsCheckerOptions } = options;
17
+ let { tsCheckerOptions } = options;
18
+ const { tsconfigPath } = environment;
19
+ // compatible with the legacy option
20
+ if (void 0 === tsCheckerOptions && void 0 !== forkTsCheckerOptions) tsCheckerOptions = forkTsCheckerOptions;
21
+ if (!tsconfigPath || false === enable) return;
22
+ // If there are identical tsconfig.json files,
23
+ // apply type checker only once to avoid duplicate checks.
24
+ if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) return;
25
+ checkedTsconfig.set(tsconfigPath, environment.name);
26
+ // use typescript of user project
27
+ let typescriptPath;
28
+ try {
29
+ typescriptPath = src_require.resolve('typescript', {
30
+ paths: [
31
+ api.context.rootPath
32
+ ]
33
+ });
34
+ } catch (err) {
35
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.warn('"typescript" is not found in current project, Type checker will not work.');
36
+ return;
37
+ }
38
+ const { references } = __WEBPACK_EXTERNAL_MODULE_json5__["default"].parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(tsconfigPath, 'utf-8'));
39
+ const useReference = Array.isArray(references) && references.length > 0;
40
+ const defaultOptions = {
41
+ typescript: {
42
+ // set 'readonly' to avoid emitting tsbuildinfo,
43
+ // as the generated tsbuildinfo will break ts-checker-rspack-plugin
44
+ mode: 'readonly',
45
+ // enable build when using project reference
46
+ build: useReference,
47
+ // avoid OOM issue
48
+ memoryLimit: 8192,
49
+ // use tsconfig of user project
50
+ configFile: tsconfigPath,
51
+ // use typescript of user project
52
+ typescriptPath
53
+ },
54
+ issue: {
55
+ // ignore types errors from node_modules
56
+ exclude: [
57
+ ({ file = '' })=>NODE_MODULES_REGEX.test(file)
58
+ ]
59
+ },
60
+ logger: {
61
+ log () {
62
+ // do nothing
63
+ // we only want to display error messages
64
+ },
65
+ error (message) {
66
+ console.error(message.replace(/ERROR/g, 'Type Error'));
67
+ }
68
+ }
69
+ };
70
+ const mergedOptions = (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs__.reduceConfigs)({
71
+ initial: defaultOptions,
72
+ config: tsCheckerOptions,
73
+ mergeFn: __WEBPACK_EXTERNAL_MODULE_deepmerge__["default"]
74
+ });
75
+ if (isProd) __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.info('Type checker is enabled. It may take some time.');
76
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(__WEBPACK_EXTERNAL_MODULE_ts_checker_rspack_plugin__.TsCheckerRspackPlugin, [
77
+ mergedOptions
78
+ ]);
32
79
  });
33
- } catch (err) {
34
- logger.warn(
35
- '"typescript" is not found in current project, Type checker will not work.'
36
- );
37
- return;
38
- }
39
- const { references } = json5.parse(
40
- fs.readFileSync(tsconfigPath, "utf-8")
41
- );
42
- const useReference = Array.isArray(references) && references.length > 0;
43
- const defaultOptions = {
44
- typescript: {
45
- // set 'readonly' to avoid emitting tsbuildinfo,
46
- // as the generated tsbuildinfo will break fork-ts-checker
47
- mode: "readonly",
48
- // enable build when using project reference
49
- build: useReference,
50
- // avoid OOM issue
51
- memoryLimit: 8192,
52
- // use tsconfig of user project
53
- configFile: tsconfigPath,
54
- // use typescript of user project
55
- typescriptPath
56
- },
57
- issue: {
58
- // ignore types errors from node_modules
59
- exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
60
- },
61
- logger: {
62
- log() {
63
- },
64
- error(message) {
65
- console.error(message.replace(/ERROR/g, "Type Error"));
66
- }
67
- }
68
- };
69
- const typeCheckerOptions = reduceConfigs({
70
- initial: defaultOptions,
71
- config: forkTsCheckerOptions,
72
- mergeFn: deepmerge
73
- });
74
- if (isProd) {
75
- logger.info("Type checker is enabled. It may take some time.");
76
- }
77
- chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTSCheckerPlugin, [typeCheckerOptions]);
78
80
  }
79
- );
80
- }
81
- };
82
- };
83
- export {
84
- PLUGIN_TYPE_CHECK_NAME,
85
- pluginTypeCheck
86
- };
81
+ });
82
+ export { PLUGIN_TYPE_CHECK_NAME, pluginTypeCheck };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-type-check",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "repository": "https://github.com/rspack-contrib/rsbuild-plugin-type-check",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,6 +17,15 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
+ "scripts": {
21
+ "build": "rslib build",
22
+ "dev": "rslib build --watch",
23
+ "lint": "biome check .",
24
+ "lint:write": "biome check . --write",
25
+ "prepare": "simple-git-hooks && npm run build",
26
+ "test": "playwright test",
27
+ "bump": "npx bumpp"
28
+ },
20
29
  "simple-git-hooks": {
21
30
  "pre-commit": "npx nano-staged"
22
31
  },
@@ -27,41 +36,34 @@
27
36
  },
28
37
  "dependencies": {
29
38
  "deepmerge": "^4.3.1",
30
- "fork-ts-checker-webpack-plugin": "9.0.2",
39
+ "ts-checker-rspack-plugin": "^1.0.1",
31
40
  "json5": "^2.2.3",
32
- "reduce-configs": "^1.0.0",
33
- "webpack": "^5.94.0"
41
+ "reduce-configs": "^1.0.0"
34
42
  },
35
43
  "devDependencies": {
36
- "@biomejs/biome": "^1.8.3",
37
- "@playwright/test": "^1.46.1",
38
- "@rsbuild/core": "^1.0.1-rc.5",
44
+ "@biomejs/biome": "^1.9.4",
45
+ "@playwright/test": "^1.48.2",
46
+ "@rsbuild/core": "^1.1.5",
47
+ "@rslib/core": "^0.1.0",
39
48
  "@types/fs-extra": "^11.0.4",
40
- "@types/node": "^20.16.2",
49
+ "@types/node": "^22.8.6",
41
50
  "fs-extra": "^11.2.0",
42
51
  "nano-staged": "^0.8.0",
43
- "playwright": "^1.46.1",
52
+ "playwright": "^1.48.2",
44
53
  "simple-git-hooks": "^2.11.1",
45
- "tsup": "^8.2.4",
46
- "typescript": "^5.5.4"
54
+ "typescript": "^5.6.3"
47
55
  },
48
56
  "peerDependencies": {
49
- "@rsbuild/core": "1.x || ^1.0.1-beta.0"
57
+ "@rsbuild/core": "1.x"
50
58
  },
51
59
  "peerDependenciesMeta": {
52
60
  "@rsbuild/core": {
53
61
  "optional": true
54
62
  }
55
63
  },
64
+ "packageManager": "pnpm@9.12.3",
56
65
  "publishConfig": {
57
66
  "access": "public",
58
67
  "registry": "https://registry.npmjs.org/"
59
- },
60
- "scripts": {
61
- "build": "tsup",
62
- "dev": "tsup --watch",
63
- "lint": "biome check .",
64
- "lint:write": "biome check . --write",
65
- "test": "playwright test"
66
68
  }
67
- }
69
+ }
package/dist/index.d.cts DELETED
@@ -1,21 +0,0 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
3
- import { ConfigChain } from 'reduce-configs';
4
-
5
- type ForkTsCheckerOptions = NonNullable<ConstructorParameters<typeof ForkTSCheckerPlugin>[0]>;
6
- type PluginTypeCheckerOptions = {
7
- /**
8
- * Whether to enable TypeScript type checking.
9
- * @default true
10
- */
11
- enable?: boolean;
12
- /**
13
- * To modify the options of `fork-ts-checker-webpack-plugin`.
14
- * @see https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#readme
15
- */
16
- forkTsCheckerOptions?: ConfigChain<ForkTsCheckerOptions>;
17
- };
18
- declare const PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
19
- declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
20
-
21
- export { PLUGIN_TYPE_CHECK_NAME, type PluginTypeCheckerOptions, pluginTypeCheck };