@rsbuild/plugin-type-check 0.7.9 → 1.0.0-alpha.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/dist/index.cjs +12 -7
- package/dist/index.d.ts +6 -8
- package/dist/index.js +14 -12
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
pluginTypeCheck: () => pluginTypeCheck
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var import_node_fs = __toESM(require("fs"));
|
|
37
38
|
var import_core = require("@rsbuild/core");
|
|
38
39
|
var import_shared = require("@rsbuild/shared");
|
|
39
40
|
var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
|
|
@@ -41,14 +42,18 @@ var pluginTypeCheck = (options = {}) => {
|
|
|
41
42
|
return {
|
|
42
43
|
name: PLUGIN_TYPE_CHECK_NAME,
|
|
43
44
|
setup(api) {
|
|
44
|
-
|
|
45
|
+
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
46
|
+
const checkedTsconfig = /* @__PURE__ */ new Map();
|
|
47
|
+
api.modifyBundlerChain(async (chain, { isProd, environment }) => {
|
|
45
48
|
const { enable = true, forkTsCheckerOptions } = options;
|
|
46
|
-
|
|
49
|
+
const { tsconfigPath } = environment;
|
|
50
|
+
if (!tsconfigPath || enable === false) {
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
|
-
if (
|
|
53
|
+
if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
56
|
+
checkedTsconfig.set(tsconfigPath, environment.name);
|
|
52
57
|
let typescriptPath;
|
|
53
58
|
try {
|
|
54
59
|
typescriptPath = require.resolve("typescript", {
|
|
@@ -63,7 +68,7 @@ var pluginTypeCheck = (options = {}) => {
|
|
|
63
68
|
const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
|
|
64
69
|
const { default: json5 } = await import("json5");
|
|
65
70
|
const { references } = json5.parse(
|
|
66
|
-
|
|
71
|
+
import_node_fs.default.readFileSync(tsconfigPath, "utf-8")
|
|
67
72
|
);
|
|
68
73
|
const useReference = Array.isArray(references) && references.length > 0;
|
|
69
74
|
const defaultOptions = {
|
|
@@ -76,13 +81,13 @@ var pluginTypeCheck = (options = {}) => {
|
|
|
76
81
|
// avoid OOM issue
|
|
77
82
|
memoryLimit: 8192,
|
|
78
83
|
// use tsconfig of user project
|
|
79
|
-
configFile:
|
|
84
|
+
configFile: tsconfigPath,
|
|
80
85
|
// use typescript of user project
|
|
81
86
|
typescriptPath
|
|
82
87
|
},
|
|
83
88
|
issue: {
|
|
84
89
|
// ignore types errors from node_modules
|
|
85
|
-
exclude: [({ file = "" }) =>
|
|
90
|
+
exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
|
|
86
91
|
},
|
|
87
92
|
logger: {
|
|
88
93
|
log() {
|
|
@@ -92,7 +97,7 @@ var pluginTypeCheck = (options = {}) => {
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
};
|
|
95
|
-
const typeCheckerOptions = (0,
|
|
100
|
+
const typeCheckerOptions = (0, import_core.reduceConfigs)({
|
|
96
101
|
initial: defaultOptions,
|
|
97
102
|
config: forkTsCheckerOptions,
|
|
98
103
|
mergeFn: import_shared.deepmerge
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ConfigChain, RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
|
|
3
|
-
|
|
1
|
+
import { type ConfigChain, type RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import type ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
|
|
4
3
|
type ForkTsCheckerOptions = NonNullable<ConstructorParameters<typeof ForkTSCheckerPlugin>[0]>;
|
|
5
|
-
type PluginTypeCheckerOptions = {
|
|
4
|
+
export type PluginTypeCheckerOptions = {
|
|
6
5
|
/**
|
|
7
6
|
* Whether to enable TypeScript type checking.
|
|
8
7
|
* @default true
|
|
@@ -14,7 +13,6 @@ type PluginTypeCheckerOptions = {
|
|
|
14
13
|
*/
|
|
15
14
|
forkTsCheckerOptions?: ConfigChain<ForkTsCheckerOptions>;
|
|
16
15
|
};
|
|
17
|
-
declare const PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
|
|
18
|
-
declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
|
|
19
|
-
|
|
20
|
-
export { PLUGIN_TYPE_CHECK_NAME, type PluginTypeCheckerOptions, pluginTypeCheck };
|
|
16
|
+
export declare const PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
|
|
17
|
+
export declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
|
|
18
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -9,32 +9,34 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
12
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
import path from "path";
|
|
15
15
|
|
|
16
16
|
// src/index.ts
|
|
17
|
-
import
|
|
17
|
+
import fs from "fs";
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
NODE_MODULES_REGEX,
|
|
21
|
-
deepmerge,
|
|
22
|
-
fse,
|
|
19
|
+
logger,
|
|
23
20
|
reduceConfigs
|
|
24
|
-
} from "@rsbuild/
|
|
21
|
+
} from "@rsbuild/core";
|
|
22
|
+
import { CHAIN_ID, deepmerge } from "@rsbuild/shared";
|
|
25
23
|
var PLUGIN_TYPE_CHECK_NAME = "rsbuild:type-check";
|
|
26
24
|
var pluginTypeCheck = (options = {}) => {
|
|
27
25
|
return {
|
|
28
26
|
name: PLUGIN_TYPE_CHECK_NAME,
|
|
29
27
|
setup(api) {
|
|
30
|
-
|
|
28
|
+
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
29
|
+
const checkedTsconfig = /* @__PURE__ */ new Map();
|
|
30
|
+
api.modifyBundlerChain(async (chain, { isProd, environment }) => {
|
|
31
31
|
const { enable = true, forkTsCheckerOptions } = options;
|
|
32
|
-
|
|
32
|
+
const { tsconfigPath } = environment;
|
|
33
|
+
if (!tsconfigPath || enable === false) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
if (
|
|
36
|
+
if (checkedTsconfig.has(tsconfigPath) && checkedTsconfig.get(tsconfigPath) !== environment.name) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
39
|
+
checkedTsconfig.set(tsconfigPath, environment.name);
|
|
38
40
|
let typescriptPath;
|
|
39
41
|
try {
|
|
40
42
|
typescriptPath = __require.resolve("typescript", {
|
|
@@ -49,7 +51,7 @@ var pluginTypeCheck = (options = {}) => {
|
|
|
49
51
|
const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
|
|
50
52
|
const { default: json5 } = await import("json5");
|
|
51
53
|
const { references } = json5.parse(
|
|
52
|
-
|
|
54
|
+
fs.readFileSync(tsconfigPath, "utf-8")
|
|
53
55
|
);
|
|
54
56
|
const useReference = Array.isArray(references) && references.length > 0;
|
|
55
57
|
const defaultOptions = {
|
|
@@ -62,7 +64,7 @@ var pluginTypeCheck = (options = {}) => {
|
|
|
62
64
|
// avoid OOM issue
|
|
63
65
|
memoryLimit: 8192,
|
|
64
66
|
// use tsconfig of user project
|
|
65
|
-
configFile:
|
|
67
|
+
configFile: tsconfigPath,
|
|
66
68
|
// use typescript of user project
|
|
67
69
|
typescriptPath
|
|
68
70
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-type-check",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
4
|
"description": "TS checker plugin of Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"fork-ts-checker-webpack-plugin": "9.0.2",
|
|
27
27
|
"json5": "^2.2.3",
|
|
28
|
-
"webpack": "^5.92.
|
|
29
|
-
"@rsbuild/shared": "0.
|
|
28
|
+
"webpack": "^5.92.1",
|
|
29
|
+
"@rsbuild/shared": "1.0.0-alpha.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"@rsbuild/core": "0.
|
|
34
|
-
"@scripts/test-helper": "0.
|
|
32
|
+
"typescript": "^5.5.2",
|
|
33
|
+
"@rsbuild/core": "1.0.0-alpha.0",
|
|
34
|
+
"@scripts/test-helper": "1.0.0-alpha.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@rsbuild/core": "^0.
|
|
37
|
+
"@rsbuild/core": "^1.0.0-alpha.0"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public",
|