@rsbuild/plugin-type-check 1.0.0 → 1.0.1-beta.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
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Rsbuild
6
6
 
7
- Unleash the power of Rspack with the out-of-the-box build tool.
7
+ The Rspack-based build tool. It's fast, out-of-the-box and extensible.
8
8
 
9
9
  ## Documentation
10
10
 
package/dist/index.cjs ADDED
@@ -0,0 +1,120 @@
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
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_node_fs = __toESM(require("fs"));
38
+ var import_core = require("@rsbuild/core");
39
+ var import_deepmerge = __toESM(require("deepmerge"));
40
+ var import_reduce_configs = require("reduce-configs");
41
+ var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
42
+ var pluginTypeCheck = (options = {}) => {
43
+ return {
44
+ name: PLUGIN_TYPE_CHECK_NAME,
45
+ setup(api) {
46
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
47
+ const checkedTsconfig = /* @__PURE__ */ new Map();
48
+ api.modifyBundlerChain(
49
+ async (chain, { isProd, environment, CHAIN_ID }) => {
50
+ const { enable = true, forkTsCheckerOptions } = options;
51
+ const { tsconfigPath } = environment;
52
+ if (!tsconfigPath || enable === false) {
53
+ return;
54
+ }
55
+ if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
56
+ return;
57
+ }
58
+ checkedTsconfig.set(tsconfigPath, environment.name);
59
+ let typescriptPath;
60
+ try {
61
+ typescriptPath = require.resolve("typescript", {
62
+ paths: [api.context.rootPath]
63
+ });
64
+ } catch (err) {
65
+ import_core.logger.warn(
66
+ '"typescript" is not found in current project, Type checker will not work.'
67
+ );
68
+ return;
69
+ }
70
+ const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
71
+ const { default: json5 } = await import("json5");
72
+ const { references } = json5.parse(
73
+ import_node_fs.default.readFileSync(tsconfigPath, "utf-8")
74
+ );
75
+ const useReference = Array.isArray(references) && references.length > 0;
76
+ const defaultOptions = {
77
+ typescript: {
78
+ // set 'readonly' to avoid emitting tsbuildinfo,
79
+ // as the generated tsbuildinfo will break fork-ts-checker
80
+ mode: "readonly",
81
+ // enable build when using project reference
82
+ build: useReference,
83
+ // avoid OOM issue
84
+ memoryLimit: 8192,
85
+ // use tsconfig of user project
86
+ configFile: tsconfigPath,
87
+ // use typescript of user project
88
+ typescriptPath
89
+ },
90
+ issue: {
91
+ // ignore types errors from node_modules
92
+ exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
93
+ },
94
+ logger: {
95
+ log() {
96
+ },
97
+ error(message) {
98
+ console.error(message.replace(/ERROR/g, "Type Error"));
99
+ }
100
+ }
101
+ };
102
+ const typeCheckerOptions = (0, import_reduce_configs.reduceConfigs)({
103
+ initial: defaultOptions,
104
+ config: forkTsCheckerOptions,
105
+ mergeFn: import_deepmerge.default
106
+ });
107
+ if (isProd) {
108
+ import_core.logger.info("Type checker is enabled. It may take some time.");
109
+ }
110
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
111
+ }
112
+ );
113
+ }
114
+ };
115
+ };
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ PLUGIN_TYPE_CHECK_NAME,
119
+ pluginTypeCheck
120
+ });
package/dist/index.d.ts CHANGED
@@ -1,12 +1,19 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import { ChainedConfig } from '@rsbuild/shared';
3
- import ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
4
-
5
- type ForkTsCheckerOptions = ConstructorParameters<typeof ForkTSCheckerPlugin>[0];
6
- type PluginTypeCheckerOptions = {
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
+ import type ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
3
+ import { type ConfigChain } from 'reduce-configs';
4
+ type ForkTsCheckerOptions = NonNullable<ConstructorParameters<typeof ForkTSCheckerPlugin>[0]>;
5
+ export type PluginTypeCheckerOptions = {
6
+ /**
7
+ * Whether to enable TypeScript type checking.
8
+ * @default true
9
+ */
7
10
  enable?: boolean;
8
- forkTsCheckerOptions?: ChainedConfig<ForkTsCheckerOptions>;
11
+ /**
12
+ * To modify the options of `fork-ts-checker-webpack-plugin`.
13
+ * @see https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#readme
14
+ */
15
+ forkTsCheckerOptions?: ConfigChain<ForkTsCheckerOptions>;
9
16
  };
10
- declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
11
-
12
- export { PluginTypeCheckerOptions, pluginTypeCheck };
17
+ export declare const PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
18
+ export declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
19
+ export {};
package/dist/index.js CHANGED
@@ -1,102 +1,99 @@
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);
1
+ import { createRequire } from 'module';
2
+ var require = createRequire(import.meta['url']);
29
3
 
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- pluginTypeCheck: () => pluginTypeCheck
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined")
8
+ return require.apply(this, arguments);
9
+ throw Error('Dynamic require of "' + x + '" is not supported');
34
10
  });
35
- module.exports = __toCommonJS(src_exports);
36
- var import_shared = require("@rsbuild/shared");
11
+
12
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.54.6_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
13
+ import { fileURLToPath } from "url";
14
+ import path from "path";
15
+
16
+ // src/index.ts
17
+ import fs from "fs";
18
+ import { logger } from "@rsbuild/core";
19
+ import deepmerge from "deepmerge";
20
+ import { reduceConfigs } from "reduce-configs";
21
+ var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
37
22
  var pluginTypeCheck = (options = {}) => {
38
23
  return {
39
- name: "rsbuild:type-check",
24
+ name: PLUGIN_TYPE_CHECK_NAME,
40
25
  setup(api) {
41
- api.modifyBundlerChain(async (chain, { target }) => {
42
- const { enable = true, forkTsCheckerOptions } = options;
43
- if (!api.context.tsconfigPath || enable === false) {
44
- return;
45
- }
46
- if (Array.isArray(api.context.target) && target !== api.context.target[0]) {
47
- return;
48
- }
49
- const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
50
- let typescriptPath;
51
- try {
52
- typescriptPath = require.resolve("typescript", {
53
- paths: [api.context.rootPath]
54
- });
55
- } catch (err) {
56
- import_shared.logger.warn(
57
- '"typescript" is not found in current project, Type checker will not work.'
26
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
27
+ const checkedTsconfig = /* @__PURE__ */ new Map();
28
+ api.modifyBundlerChain(
29
+ async (chain, { isProd, environment, CHAIN_ID }) => {
30
+ const { enable = true, forkTsCheckerOptions } = options;
31
+ const { tsconfigPath } = environment;
32
+ if (!tsconfigPath || enable === false) {
33
+ return;
34
+ }
35
+ if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
36
+ return;
37
+ }
38
+ checkedTsconfig.set(tsconfigPath, environment.name);
39
+ let typescriptPath;
40
+ try {
41
+ typescriptPath = __require.resolve("typescript", {
42
+ paths: [api.context.rootPath]
43
+ });
44
+ } catch (err) {
45
+ logger.warn(
46
+ '"typescript" is not found in current project, Type checker will not work.'
47
+ );
48
+ return;
49
+ }
50
+ const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
51
+ const { default: json5 } = await import("json5");
52
+ const { references } = json5.parse(
53
+ fs.readFileSync(tsconfigPath, "utf-8")
58
54
  );
59
- return;
60
- }
61
- const defaultOptions = {
62
- typescript: {
63
- // avoid OOM issue
64
- memoryLimit: 8192,
65
- // use tsconfig of user project
66
- configFile: api.context.tsconfigPath,
67
- typescriptPath
68
- },
69
- issue: {
70
- exclude: [
71
- { file: "**/*.(spec|test).ts" },
72
- { file: "**/node_modules/**/*" }
73
- ]
74
- },
75
- logger: {
76
- log() {
55
+ const useReference = Array.isArray(references) && references.length > 0;
56
+ const defaultOptions = {
57
+ typescript: {
58
+ // set 'readonly' to avoid emitting tsbuildinfo,
59
+ // as the generated tsbuildinfo will break fork-ts-checker
60
+ mode: "readonly",
61
+ // enable build when using project reference
62
+ build: useReference,
63
+ // avoid OOM issue
64
+ memoryLimit: 8192,
65
+ // use tsconfig of user project
66
+ configFile: tsconfigPath,
67
+ // use typescript of user project
68
+ typescriptPath
69
+ },
70
+ issue: {
71
+ // ignore types errors from node_modules
72
+ exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
77
73
  },
78
- error(message) {
79
- console.error(message.replace(/ERROR/g, "Type Error"));
74
+ logger: {
75
+ log() {
76
+ },
77
+ error(message) {
78
+ console.error(message.replace(/ERROR/g, "Type Error"));
79
+ }
80
80
  }
81
+ };
82
+ const typeCheckerOptions = reduceConfigs({
83
+ initial: defaultOptions,
84
+ config: forkTsCheckerOptions,
85
+ mergeFn: deepmerge
86
+ });
87
+ if (isProd) {
88
+ logger.info("Type checker is enabled. It may take some time.");
81
89
  }
82
- };
83
- const typeCheckerOptions = (0, import_shared.mergeChainedOptions)({
84
- defaults: defaultOptions,
85
- options: forkTsCheckerOptions,
86
- mergeFn: import_shared.deepmerge
87
- });
88
- if (api.context.bundlerType === "rspack" && chain.get("mode") === "production") {
89
- import_shared.logger.info("Ts checker running...");
90
- import_shared.logger.info(
91
- "Ts checker is running slowly and will block builds until it is complete, please be patient and wait."
92
- );
90
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
93
91
  }
94
- chain.plugin(import_shared.CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
95
- });
92
+ );
96
93
  }
97
94
  };
98
95
  };
99
- // Annotate the CommonJS export names for ESM import in node:
100
- 0 && (module.exports = {
96
+ export {
97
+ PLUGIN_TYPE_CHECK_NAME,
101
98
  pluginTypeCheck
102
- });
99
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-type-check",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-beta.0",
4
4
  "description": "TS checker plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -9,29 +9,33 @@
9
9
  "directory": "packages/plugin-type-check"
10
10
  },
11
11
  "license": "MIT",
12
+ "type": "module",
12
13
  "exports": {
13
14
  ".": {
14
15
  "types": "./dist/index.d.ts",
15
- "import": "./dist/index.mjs",
16
- "default": "./dist/index.js"
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
17
18
  }
18
19
  },
19
- "main": "./dist/index.js",
20
+ "main": "./dist/index.cjs",
20
21
  "types": "./dist/index.d.ts",
21
22
  "files": [
22
23
  "dist"
23
24
  ],
24
25
  "dependencies": {
25
- "fork-ts-checker-webpack-plugin": "9.0.0",
26
- "@rsbuild/shared": "1.0.0"
26
+ "deepmerge": "^4.3.1",
27
+ "fork-ts-checker-webpack-plugin": "9.0.2",
28
+ "json5": "^2.2.3",
29
+ "reduce-configs": "^1.0.0",
30
+ "webpack": "^5.93.0"
27
31
  },
28
32
  "devDependencies": {
29
- "typescript": "^5.3.0",
30
- "@rsbuild/core": "1.0.0",
31
- "@rsbuild/test-helper": "1.0.0"
33
+ "typescript": "^5.5.2",
34
+ "@rsbuild/core": "1.0.1-beta.0",
35
+ "@scripts/test-helper": "1.0.1-beta.0"
32
36
  },
33
37
  "peerDependencies": {
34
- "@rsbuild/core": "^1.0.0"
38
+ "@rsbuild/core": "^1.0.1-beta.0"
35
39
  },
36
40
  "publishConfig": {
37
41
  "access": "public",
package/dist/index.mjs DELETED
@@ -1,88 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.40.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
10
- import { fileURLToPath } from "url";
11
- import path from "path";
12
-
13
- // ../../scripts/require_shims.js
14
- import { createRequire } from "module";
15
- global.require = createRequire(import.meta.url);
16
-
17
- // src/index.ts
18
- import {
19
- logger,
20
- CHAIN_ID,
21
- deepmerge,
22
- mergeChainedOptions
23
- } from "@rsbuild/shared";
24
- var pluginTypeCheck = (options = {}) => {
25
- return {
26
- name: "rsbuild:type-check",
27
- setup(api) {
28
- api.modifyBundlerChain(async (chain, { target }) => {
29
- const { enable = true, forkTsCheckerOptions } = options;
30
- if (!api.context.tsconfigPath || enable === false) {
31
- return;
32
- }
33
- if (Array.isArray(api.context.target) && target !== api.context.target[0]) {
34
- return;
35
- }
36
- const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
37
- let typescriptPath;
38
- try {
39
- typescriptPath = __require.resolve("typescript", {
40
- paths: [api.context.rootPath]
41
- });
42
- } catch (err) {
43
- logger.warn(
44
- '"typescript" is not found in current project, Type checker will not work.'
45
- );
46
- return;
47
- }
48
- const defaultOptions = {
49
- typescript: {
50
- // avoid OOM issue
51
- memoryLimit: 8192,
52
- // use tsconfig of user project
53
- configFile: api.context.tsconfigPath,
54
- typescriptPath
55
- },
56
- issue: {
57
- exclude: [
58
- { file: "**/*.(spec|test).ts" },
59
- { file: "**/node_modules/**/*" }
60
- ]
61
- },
62
- logger: {
63
- log() {
64
- },
65
- error(message) {
66
- console.error(message.replace(/ERROR/g, "Type Error"));
67
- }
68
- }
69
- };
70
- const typeCheckerOptions = mergeChainedOptions({
71
- defaults: defaultOptions,
72
- options: forkTsCheckerOptions,
73
- mergeFn: deepmerge
74
- });
75
- if (api.context.bundlerType === "rspack" && chain.get("mode") === "production") {
76
- logger.info("Ts checker running...");
77
- logger.info(
78
- "Ts checker is running slowly and will block builds until it is complete, please be patient and wait."
79
- );
80
- }
81
- chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
82
- });
83
- }
84
- };
85
- };
86
- export {
87
- pluginTypeCheck
88
- };