@rsbuild/plugin-type-check 0.2.3 → 0.2.4

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.js CHANGED
@@ -39,7 +39,7 @@ var pluginTypeCheck = (options = {}) => {
39
39
  return {
40
40
  name: "rsbuild:type-check",
41
41
  setup(api) {
42
- api.modifyBundlerChain(async (chain, { target }) => {
42
+ api.modifyBundlerChain(async (chain, { target, isProd }) => {
43
43
  const { enable = true, forkTsCheckerOptions } = options;
44
44
  if (!api.context.tsconfigPath || enable === false) {
45
45
  return;
@@ -47,7 +47,6 @@ var pluginTypeCheck = (options = {}) => {
47
47
  if (target !== api.context.targets[0]) {
48
48
  return;
49
49
  }
50
- const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
51
50
  let typescriptPath;
52
51
  try {
53
52
  typescriptPath = require.resolve("typescript", {
@@ -59,12 +58,24 @@ var pluginTypeCheck = (options = {}) => {
59
58
  );
60
59
  return;
61
60
  }
61
+ const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
62
+ const { default: json5 } = await import("@rsbuild/shared/json5");
63
+ const { references } = json5.parse(
64
+ import_shared.fse.readFileSync(api.context.tsconfigPath, "utf-8")
65
+ );
66
+ const useReference = Array.isArray(references) && references.length > 0;
62
67
  const defaultOptions = {
63
68
  typescript: {
69
+ // set 'readonly' to avoid emitting tsbuildinfo,
70
+ // as the generated tsbuildinfo will break fork-ts-checker
71
+ mode: "readonly",
72
+ // enable build when using project reference
73
+ build: useReference,
64
74
  // avoid OOM issue
65
75
  memoryLimit: 8192,
66
76
  // use tsconfig of user project
67
77
  configFile: api.context.tsconfigPath,
78
+ // use typescript of user project
68
79
  typescriptPath
69
80
  },
70
81
  issue: {
@@ -86,7 +97,7 @@ var pluginTypeCheck = (options = {}) => {
86
97
  options: forkTsCheckerOptions,
87
98
  mergeFn: import_shared.deepmerge
88
99
  });
89
- if (api.context.bundlerType === "rspack" && chain.get("mode") === "production") {
100
+ if (api.context.bundlerType === "rspack" && isProd) {
90
101
  import_core.logger.info("Ts checker running...");
91
102
  import_core.logger.info(
92
103
  "Ts checker is running slowly and will block builds until it is complete, please be patient and wait."
package/dist/index.mjs CHANGED
@@ -17,6 +17,7 @@ global.require = createRequire(import.meta.url);
17
17
  // src/index.ts
18
18
  import { logger } from "@rsbuild/core";
19
19
  import {
20
+ fse,
20
21
  CHAIN_ID,
21
22
  deepmerge,
22
23
  mergeChainedOptions
@@ -25,7 +26,7 @@ var pluginTypeCheck = (options = {}) => {
25
26
  return {
26
27
  name: "rsbuild:type-check",
27
28
  setup(api) {
28
- api.modifyBundlerChain(async (chain, { target }) => {
29
+ api.modifyBundlerChain(async (chain, { target, isProd }) => {
29
30
  const { enable = true, forkTsCheckerOptions } = options;
30
31
  if (!api.context.tsconfigPath || enable === false) {
31
32
  return;
@@ -33,7 +34,6 @@ var pluginTypeCheck = (options = {}) => {
33
34
  if (target !== api.context.targets[0]) {
34
35
  return;
35
36
  }
36
- const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
37
37
  let typescriptPath;
38
38
  try {
39
39
  typescriptPath = __require.resolve("typescript", {
@@ -45,12 +45,24 @@ var pluginTypeCheck = (options = {}) => {
45
45
  );
46
46
  return;
47
47
  }
48
+ const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
49
+ const { default: json5 } = await import("@rsbuild/shared/json5");
50
+ const { references } = json5.parse(
51
+ fse.readFileSync(api.context.tsconfigPath, "utf-8")
52
+ );
53
+ const useReference = Array.isArray(references) && references.length > 0;
48
54
  const defaultOptions = {
49
55
  typescript: {
56
+ // set 'readonly' to avoid emitting tsbuildinfo,
57
+ // as the generated tsbuildinfo will break fork-ts-checker
58
+ mode: "readonly",
59
+ // enable build when using project reference
60
+ build: useReference,
50
61
  // avoid OOM issue
51
62
  memoryLimit: 8192,
52
63
  // use tsconfig of user project
53
64
  configFile: api.context.tsconfigPath,
65
+ // use typescript of user project
54
66
  typescriptPath
55
67
  },
56
68
  issue: {
@@ -72,7 +84,7 @@ var pluginTypeCheck = (options = {}) => {
72
84
  options: forkTsCheckerOptions,
73
85
  mergeFn: deepmerge
74
86
  });
75
- if (api.context.bundlerType === "rspack" && chain.get("mode") === "production") {
87
+ if (api.context.bundlerType === "rspack" && isProd) {
76
88
  logger.info("Ts checker running...");
77
89
  logger.info(
78
90
  "Ts checker is running slowly and will block builds until it is complete, please be patient and wait."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-type-check",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "TS checker plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -24,12 +24,12 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "fork-ts-checker-webpack-plugin": "9.0.0",
27
- "@rsbuild/shared": "0.2.3"
27
+ "@rsbuild/shared": "0.2.4"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "^5.3.0",
31
- "@rsbuild/core": "0.2.3",
32
- "@rsbuild/test-helper": "0.2.3"
31
+ "@rsbuild/core": "0.2.4",
32
+ "@rsbuild/test-helper": "0.2.4"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@rsbuild/core": "0.x"