@rsbuild/plugin-type-check 0.6.14 → 0.7.0-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/dist/index.cjs ADDED
@@ -0,0 +1,109 @@
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
+ pluginTypeCheck: () => pluginTypeCheck
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_core = require("@rsbuild/core");
37
+ var import_shared = require("@rsbuild/shared");
38
+ var pluginTypeCheck = (options = {}) => {
39
+ return {
40
+ name: "rsbuild:type-check",
41
+ setup(api) {
42
+ api.modifyBundlerChain(async (chain, { target, isProd }) => {
43
+ const { enable = true, forkTsCheckerOptions } = options;
44
+ if (!api.context.tsconfigPath || enable === false) {
45
+ return;
46
+ }
47
+ if (target !== api.context.targets[0]) {
48
+ return;
49
+ }
50
+ let typescriptPath;
51
+ try {
52
+ typescriptPath = require.resolve("typescript", {
53
+ paths: [api.context.rootPath]
54
+ });
55
+ } catch (err) {
56
+ import_core.logger.warn(
57
+ '"typescript" is not found in current project, Type checker will not work.'
58
+ );
59
+ return;
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;
67
+ const defaultOptions = {
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,
74
+ // avoid OOM issue
75
+ memoryLimit: 8192,
76
+ // use tsconfig of user project
77
+ configFile: api.context.tsconfigPath,
78
+ // use typescript of user project
79
+ typescriptPath
80
+ },
81
+ issue: {
82
+ // ignore types errors from node_modules
83
+ exclude: [({ file = "" }) => import_shared.NODE_MODULES_REGEX.test(file)]
84
+ },
85
+ logger: {
86
+ log() {
87
+ },
88
+ error(message) {
89
+ console.error(message.replace(/ERROR/g, "Type Error"));
90
+ }
91
+ }
92
+ };
93
+ const typeCheckerOptions = (0, import_shared.mergeChainedOptions)({
94
+ defaults: defaultOptions,
95
+ options: forkTsCheckerOptions,
96
+ mergeFn: import_shared.deepmerge
97
+ });
98
+ if (isProd) {
99
+ import_core.logger.info("Type checker is enabled. It may take some time.");
100
+ }
101
+ chain.plugin(import_shared.CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
102
+ });
103
+ }
104
+ };
105
+ };
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ pluginTypeCheck
109
+ });
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import { ChainedConfig } from '@rsbuild/shared';
3
- import ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
4
-
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
+ import { type ChainedConfig } from '@rsbuild/shared';
3
+ import type ForkTSCheckerPlugin from 'fork-ts-checker-webpack-plugin';
5
4
  type ForkTsCheckerOptions = NonNullable<ConstructorParameters<typeof ForkTSCheckerPlugin>[0]>;
6
- type PluginTypeCheckerOptions = {
5
+ export type PluginTypeCheckerOptions = {
7
6
  /**
8
7
  * Whether to enable TypeScript type checking.
9
8
  * @default true
@@ -15,6 +14,5 @@ type PluginTypeCheckerOptions = {
15
14
  */
16
15
  forkTsCheckerOptions?: ChainedConfig<ForkTsCheckerOptions>;
17
16
  };
18
- declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
19
-
20
- export { type PluginTypeCheckerOptions, pluginTypeCheck };
17
+ export declare const pluginTypeCheck: (options?: PluginTypeCheckerOptions) => RsbuildPlugin;
18
+ export {};
package/dist/index.js CHANGED
@@ -1,40 +1,27 @@
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_core = require("@rsbuild/core");
37
- var import_shared = require("@rsbuild/shared");
11
+
12
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.49.3_eslint@8.57.0_typescript@5.4.5/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 { logger } from "@rsbuild/core";
18
+ import {
19
+ CHAIN_ID,
20
+ NODE_MODULES_REGEX,
21
+ deepmerge,
22
+ fse,
23
+ mergeChainedOptions
24
+ } from "@rsbuild/shared";
38
25
  var pluginTypeCheck = (options = {}) => {
39
26
  return {
40
27
  name: "rsbuild:type-check",
@@ -49,11 +36,11 @@ var pluginTypeCheck = (options = {}) => {
49
36
  }
50
37
  let typescriptPath;
51
38
  try {
52
- typescriptPath = require.resolve("typescript", {
39
+ typescriptPath = __require.resolve("typescript", {
53
40
  paths: [api.context.rootPath]
54
41
  });
55
42
  } catch (err) {
56
- import_core.logger.warn(
43
+ logger.warn(
57
44
  '"typescript" is not found in current project, Type checker will not work.'
58
45
  );
59
46
  return;
@@ -61,7 +48,7 @@ var pluginTypeCheck = (options = {}) => {
61
48
  const { default: ForkTsCheckerWebpackPlugin } = await import("fork-ts-checker-webpack-plugin");
62
49
  const { default: json5 } = await import("@rsbuild/shared/json5");
63
50
  const { references } = json5.parse(
64
- import_shared.fse.readFileSync(api.context.tsconfigPath, "utf-8")
51
+ fse.readFileSync(api.context.tsconfigPath, "utf-8")
65
52
  );
66
53
  const useReference = Array.isArray(references) && references.length > 0;
67
54
  const defaultOptions = {
@@ -80,7 +67,7 @@ var pluginTypeCheck = (options = {}) => {
80
67
  },
81
68
  issue: {
82
69
  // ignore types errors from node_modules
83
- exclude: [({ file = "" }) => import_shared.NODE_MODULES_REGEX.test(file)]
70
+ exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
84
71
  },
85
72
  logger: {
86
73
  log() {
@@ -90,20 +77,19 @@ var pluginTypeCheck = (options = {}) => {
90
77
  }
91
78
  }
92
79
  };
93
- const typeCheckerOptions = (0, import_shared.mergeChainedOptions)({
80
+ const typeCheckerOptions = mergeChainedOptions({
94
81
  defaults: defaultOptions,
95
82
  options: forkTsCheckerOptions,
96
- mergeFn: import_shared.deepmerge
83
+ mergeFn: deepmerge
97
84
  });
98
85
  if (isProd) {
99
- import_core.logger.info("Type checker is enabled. It may take some time.");
86
+ logger.info("Type checker is enabled. It may take some time.");
100
87
  }
101
- chain.plugin(import_shared.CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
88
+ chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
102
89
  });
103
90
  }
104
91
  };
105
92
  };
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
93
+ export {
108
94
  pluginTypeCheck
109
- });
95
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-type-check",
3
- "version": "0.6.14",
3
+ "version": "0.7.0-beta.0",
4
4
  "description": "TS checker plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -9,15 +9,15 @@
9
9
  "directory": "packages/plugin-type-check"
10
10
  },
11
11
  "license": "MIT",
12
- "type": "commonjs",
12
+ "type": "module",
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
- "import": "./dist/index.mjs",
17
- "default": "./dist/index.js"
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
18
  }
19
19
  },
20
- "main": "./dist/index.js",
20
+ "main": "./dist/index.cjs",
21
21
  "types": "./dist/index.d.ts",
22
22
  "files": [
23
23
  "dist"
@@ -25,15 +25,15 @@
25
25
  "dependencies": {
26
26
  "fork-ts-checker-webpack-plugin": "9.0.2",
27
27
  "webpack": "^5.91.0",
28
- "@rsbuild/shared": "0.6.14"
28
+ "@rsbuild/shared": "0.7.0-beta.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.4.2",
32
- "@rsbuild/core": "0.6.14",
33
- "@scripts/test-helper": "0.6.14"
32
+ "@rsbuild/core": "0.7.0-beta.0",
33
+ "@scripts/test-helper": "0.7.0-beta.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@rsbuild/core": "^0.6.14"
36
+ "@rsbuild/core": "^0.7.0-beta.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public",
package/dist/index.mjs DELETED
@@ -1,95 +0,0 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
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');
10
- });
11
-
12
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.49.2_eslint@8.57.0_typescript@5.4.5/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 { logger } from "@rsbuild/core";
18
- import {
19
- CHAIN_ID,
20
- NODE_MODULES_REGEX,
21
- deepmerge,
22
- fse,
23
- mergeChainedOptions
24
- } from "@rsbuild/shared";
25
- var pluginTypeCheck = (options = {}) => {
26
- return {
27
- name: "rsbuild:type-check",
28
- setup(api) {
29
- api.modifyBundlerChain(async (chain, { target, isProd }) => {
30
- const { enable = true, forkTsCheckerOptions } = options;
31
- if (!api.context.tsconfigPath || enable === false) {
32
- return;
33
- }
34
- if (target !== api.context.targets[0]) {
35
- return;
36
- }
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 { 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;
54
- const defaultOptions = {
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,
61
- // avoid OOM issue
62
- memoryLimit: 8192,
63
- // use tsconfig of user project
64
- configFile: api.context.tsconfigPath,
65
- // use typescript of user project
66
- typescriptPath
67
- },
68
- issue: {
69
- // ignore types errors from node_modules
70
- exclude: [({ file = "" }) => NODE_MODULES_REGEX.test(file)]
71
- },
72
- logger: {
73
- log() {
74
- },
75
- error(message) {
76
- console.error(message.replace(/ERROR/g, "Type Error"));
77
- }
78
- }
79
- };
80
- const typeCheckerOptions = mergeChainedOptions({
81
- defaults: defaultOptions,
82
- options: forkTsCheckerOptions,
83
- mergeFn: deepmerge
84
- });
85
- if (isProd) {
86
- logger.info("Type checker is enabled. It may take some time.");
87
- }
88
- chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [typeCheckerOptions]);
89
- });
90
- }
91
- };
92
- };
93
- export {
94
- pluginTypeCheck
95
- };