@rsbuild/plugin-type-check 1.0.0-alpha.2 → 1.0.0-alpha.3

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/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ __export(src_exports, {
36
36
  module.exports = __toCommonJS(src_exports);
37
37
  var import_node_fs = __toESM(require("fs"));
38
38
  var import_core = require("@rsbuild/core");
39
- var import_shared = require("@rsbuild/shared");
39
+ var import_deepmerge = __toESM(require("deepmerge"));
40
40
  var import_reduce_configs = require("reduce-configs");
41
41
  var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
42
42
  var pluginTypeCheck = (options = {}) => {
@@ -45,69 +45,71 @@ var pluginTypeCheck = (options = {}) => {
45
45
  setup(api) {
46
46
  const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
47
47
  const checkedTsconfig = /* @__PURE__ */ new Map();
48
- api.modifyBundlerChain(async (chain, { isProd, environment }) => {
49
- const { enable = true, forkTsCheckerOptions } = options;
50
- const { tsconfigPath } = environment;
51
- if (!tsconfigPath || enable === false) {
52
- return;
53
- }
54
- if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
55
- return;
56
- }
57
- checkedTsconfig.set(tsconfigPath, environment.name);
58
- let typescriptPath;
59
- try {
60
- typescriptPath = require.resolve("typescript", {
61
- paths: [api.context.rootPath]
62
- });
63
- } catch (err) {
64
- import_core.logger.warn(
65
- '"typescript" is not found in current project, Type checker will not work.'
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")
66
74
  );
67
- return;
68
- }
69
- const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
70
- const { default: json5 } = await import("json5");
71
- const { references } = json5.parse(
72
- import_node_fs.default.readFileSync(tsconfigPath, "utf-8")
73
- );
74
- const useReference = Array.isArray(references) && references.length > 0;
75
- const defaultOptions = {
76
- typescript: {
77
- // set 'readonly' to avoid emitting tsbuildinfo,
78
- // as the generated tsbuildinfo will break fork-ts-checker
79
- mode: "readonly",
80
- // enable build when using project reference
81
- build: useReference,
82
- // avoid OOM issue
83
- memoryLimit: 8192,
84
- // use tsconfig of user project
85
- configFile: tsconfigPath,
86
- // use typescript of user project
87
- typescriptPath
88
- },
89
- issue: {
90
- // ignore types errors from node_modules
91
- exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
92
- },
93
- logger: {
94
- log() {
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
95
89
  },
96
- error(message) {
97
- console.error(message.replace(/ERROR/g, "Type Error"));
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
+ }
98
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.");
99
109
  }
100
- };
101
- const typeCheckerOptions = (0, import_reduce_configs.reduceConfigs)({
102
- initial: defaultOptions,
103
- config: forkTsCheckerOptions,
104
- mergeFn: import_shared.deepmerge
105
- });
106
- if (isProd) {
107
- import_core.logger.info("Type checker is enabled. It may take some time.");
110
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
108
111
  }
109
- chain.plugin(import_shared.CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
110
- });
112
+ );
111
113
  }
112
114
  };
113
115
  };
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import path from "path";
16
16
  // src/index.ts
17
17
  import fs from "fs";
18
18
  import { logger } from "@rsbuild/core";
19
- import { CHAIN_ID, deepmerge } from "@rsbuild/shared";
19
+ import deepmerge from "deepmerge";
20
20
  import { reduceConfigs } from "reduce-configs";
21
21
  var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
22
22
  var pluginTypeCheck = (options = {}) => {
@@ -25,69 +25,71 @@ var pluginTypeCheck = (options = {}) => {
25
25
  setup(api) {
26
26
  const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
27
27
  const checkedTsconfig = /* @__PURE__ */ new Map();
28
- api.modifyBundlerChain(async (chain, { isProd, environment }) => {
29
- const { enable = true, forkTsCheckerOptions } = options;
30
- const { tsconfigPath } = environment;
31
- if (!tsconfigPath || enable === false) {
32
- return;
33
- }
34
- if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
35
- return;
36
- }
37
- checkedTsconfig.set(tsconfigPath, environment.name);
38
- let typescriptPath;
39
- try {
40
- typescriptPath = __require.resolve("typescript", {
41
- paths: [api.context.rootPath]
42
- });
43
- } catch (err) {
44
- logger.warn(
45
- '"typescript" is not found in current project, Type checker will not work.'
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")
46
54
  );
47
- return;
48
- }
49
- const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
50
- const { default: json5 } = await import("json5");
51
- const { references } = json5.parse(
52
- fs.readFileSync(tsconfigPath, "utf-8")
53
- );
54
- const useReference = Array.isArray(references) && references.length > 0;
55
- const defaultOptions = {
56
- typescript: {
57
- // set 'readonly' to avoid emitting tsbuildinfo,
58
- // as the generated tsbuildinfo will break fork-ts-checker
59
- mode: "readonly",
60
- // enable build when using project reference
61
- build: useReference,
62
- // avoid OOM issue
63
- memoryLimit: 8192,
64
- // use tsconfig of user project
65
- configFile: tsconfigPath,
66
- // use typescript of user project
67
- typescriptPath
68
- },
69
- issue: {
70
- // ignore types errors from node_modules
71
- exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
72
- },
73
- logger: {
74
- 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
75
69
  },
76
- error(message) {
77
- console.error(message.replace(/ERROR/g, "Type Error"));
70
+ issue: {
71
+ // ignore types errors from node_modules
72
+ exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
73
+ },
74
+ logger: {
75
+ log() {
76
+ },
77
+ error(message) {
78
+ console.error(message.replace(/ERROR/g, "Type Error"));
79
+ }
78
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.");
79
89
  }
80
- };
81
- const typeCheckerOptions = reduceConfigs({
82
- initial: defaultOptions,
83
- config: forkTsCheckerOptions,
84
- mergeFn: deepmerge
85
- });
86
- if (isProd) {
87
- logger.info("Type checker is enabled. It may take some time.");
90
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
88
91
  }
89
- chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
90
- });
92
+ );
91
93
  }
92
94
  };
93
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-type-check",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "TS checker plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -23,19 +23,19 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
+ "deepmerge": "^4.3.1",
26
27
  "fork-ts-checker-webpack-plugin": "9.0.2",
27
28
  "json5": "^2.2.3",
28
29
  "reduce-configs": "^1.0.0",
29
- "webpack": "^5.92.1",
30
- "@rsbuild/shared": "1.0.0-alpha.2"
30
+ "webpack": "^5.92.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "^5.5.2",
34
- "@rsbuild/core": "1.0.0-alpha.2",
35
- "@scripts/test-helper": "1.0.0-alpha.2"
34
+ "@rsbuild/core": "1.0.0-alpha.3",
35
+ "@scripts/test-helper": "1.0.0-alpha.3"
36
36
  },
37
37
  "peerDependencies": {
38
- "@rsbuild/core": "^1.0.0-alpha.2"
38
+ "@rsbuild/core": "^1.0.0-alpha.3"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public",