rsbuild-plugin-dts 0.5.3 → 0.5.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/README.md CHANGED
@@ -8,7 +8,7 @@ An [Rsbuild plugin](https://www.npmjs.com/package/rsbuild-plugin-dts) to emit de
8
8
 
9
9
  ## Using in Rslib
10
10
 
11
- Read [DTS](https://lib.rsbuild.dev/guide/advanced/dts) and [lib.dts](https://lib.rsbuild.dev/config/lib/dts) for more details.
11
+ Read [Declaration files](https://lib.rsbuild.dev/guide/advanced/dts) and [lib.dts](https://lib.rsbuild.dev/config/lib/dts) for more details.
12
12
 
13
13
  ## Using in Rsbuild
14
14
 
@@ -36,11 +36,11 @@ export default {
36
36
  - **Type:** `boolean`
37
37
  - **Default:** `false`
38
38
 
39
- Whether to bundle the DTS files.
39
+ Whether to bundle the declaration files.
40
40
 
41
- If you want to [bundle DTS](https://lib.rsbuild.dev/guide/advanced/dts#bundle-dts) files, you should:
41
+ If you want to [bundle declaration files](https://lib.rsbuild.dev/guide/advanced/dts#bundle-declaration-files) files, you should:
42
42
 
43
- 1. Install `@microsoft/api-extractor` as a development dependency, which is the underlying tool used for bundling DTS files.
43
+ 1. Install `@microsoft/api-extractor` as a development dependency, which is the underlying tool used for bundling declaration files.
44
44
 
45
45
  ```bash
46
46
  npm add @microsoft/api-extractor -D
@@ -58,7 +58,7 @@ pluginDts({
58
58
 
59
59
  - **Type:** `string`
60
60
 
61
- The output directory of DTS files. The default value follows the priority below:
61
+ The output directory of declaration files. The default value follows the priority below:
62
62
 
63
63
  1. The `distPath` value of the plugin options.
64
64
  2. The `declarationDir` value in the `tsconfig.json` file.
@@ -75,7 +75,7 @@ pluginDts({
75
75
  - **Type:** `boolean`
76
76
  - **Default:** `false`
77
77
 
78
- Whether to generate DTS files with building the project references. This is equivalent to using the `--build` flag with the `tsc` command. See [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) for more details.
78
+ Whether to generate declaration files with building the project references. This is equivalent to using the `--build` flag with the `tsc` command. See [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) for more details.
79
79
 
80
80
  When this option is enabled, you must explicitly set `declarationDir` or `outDir` in `tsconfig.json` in order to meet the build requirements.
81
81
 
@@ -84,7 +84,7 @@ When this option is enabled, you must explicitly set `declarationDir` or `outDir
84
84
  - **Type:** `boolean`
85
85
  - **Default:** `true`
86
86
 
87
- Whether to abort the build process when an error occurs during DTS generation.
87
+ Whether to abort the build process when an error occurs during declaration files generation.
88
88
 
89
89
  By default, type errors will cause the build to fail.
90
90
 
@@ -101,7 +101,7 @@ pluginDts({
101
101
  - **Type:** `string`
102
102
  - **Default:** `'.d.ts'`
103
103
 
104
- The extension of the DTS file.
104
+ The extension of the declaration file.
105
105
 
106
106
  ```js
107
107
  pluginDts({
@@ -114,7 +114,7 @@ pluginDts({
114
114
  - **Type:** `boolean`
115
115
  - **Default:** `true`
116
116
 
117
- Whether to automatically externalize dependencies of different dependency types and do not bundle them into the DTS file.
117
+ Whether to automatically externalize dependencies of different dependency types and do not bundle them into the declaration file.
118
118
 
119
119
  The default value of `autoExternal` is `true`, which means the following dependency types will not be bundled:
120
120
 
@@ -142,7 +142,7 @@ pluginDts({
142
142
  - **Type:** `string`
143
143
  - **Default:** `undefined`
144
144
 
145
- Inject content into the top of each DTS file.
145
+ Inject content into the top of each declaration file.
146
146
 
147
147
  ```js
148
148
  pluginDts({
@@ -155,7 +155,7 @@ pluginDts({
155
155
  - **Type:** `string`
156
156
  - **Default:** `undefined`
157
157
 
158
- Inject content into the bottom of each DTS file.
158
+ Inject content into the bottom of each declaration file.
159
159
 
160
160
  ```js
161
161
  pluginDts({
@@ -201,7 +201,7 @@ pluginDts({
201
201
 
202
202
  Whether to automatically redirect the import paths of TypeScript declaration output files.
203
203
 
204
- - When set to `true`, Rslib will redirect the import path in the DTS output file to the corresponding relative path based on the [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) configured in `tsconfig.json`.
204
+ - When set to `true`, Rslib will redirect the import path in the declaration output file to the corresponding relative path based on the [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) configured in `tsconfig.json`.
205
205
 
206
206
  ```ts
207
207
  // `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }`
@@ -221,7 +221,7 @@ import { foo } from '../foo'; // expected output './dist/utils/index.d.ts'
221
221
 
222
222
  Whether to automatically redirect the file extension to import paths based on the TypeScript declaration output files.
223
223
 
224
- - When set to `true`, the import paths in DTS files will be redirected to the corresponding JavaScript extension which can be resolved to corresponding DTS file. The extension of the DTS output file is related to the `dtsExtension` configuration.
224
+ - When set to `true`, the import paths in declaration files will be redirected to the corresponding JavaScript extension which can be resolved to corresponding declaration file. The extension of the declaration output file is related to the `dtsExtension` configuration.
225
225
 
226
226
  ```ts
227
227
  // `dtsExtension` is set to `.d.mts`
@@ -32,11 +32,10 @@ async function bundleDts(options) {
32
32
  });
33
33
  if (!extractorResult.succeeded) throw new Error(`API Extractor error. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
34
34
  await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.addBannerAndFooter)(untrimmedFilePath, banner, footer);
35
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(`API Extractor bundle DTS succeeded: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(untrimmedFilePath)} in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
35
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(`bundle declaration files succeeded: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(untrimmedFilePath)} in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
36
36
  }));
37
37
  } catch (e) {
38
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error('API Extractor Error');
39
- throw new Error(`${e}`);
38
+ throw new Error(`API Extractor Error:\n ${e}`);
40
39
  }
41
40
  }
42
41
  export { bundleDts };
package/dist/dts.js CHANGED
@@ -56,7 +56,7 @@ async function generateDts(data) {
56
56
  path: true,
57
57
  extension: false
58
58
  } } = data;
59
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.start(`Generating DTS... ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
59
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.start(`generating declaration files... ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
60
60
  const { options: rawCompilerOptions, fileNames } = tsConfigResult;
61
61
  const rootDir = rawCompilerOptions.rootDir ?? (rawCompilerOptions.composite ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath) : await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.calcLongestCommonPath)(fileNames.filter((fileName)=>!/\.d\.(ts|mts|cts)$/.test(fileName)))) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath);
62
62
  const resolvedDtsEmitPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath), dtsEmitPath));
package/dist/index.js CHANGED
@@ -63,7 +63,7 @@ const pluginDts = (options = {})=>({
63
63
  });
64
64
  else if ('error' === message) resolve({
65
65
  status: 'error',
66
- errorMessage: `Error occurred in ${environment.name} DTS generation`
66
+ errorMessage: `Error occurred in ${environment.name} declaration files generation.`
67
67
  });
68
68
  });
69
69
  }));
@@ -80,7 +80,7 @@ const pluginDts = (options = {})=>({
80
80
  for (const result of promisesResult)if ('error' === result.status) {
81
81
  if (options.abortOnError) throw new Error(result.errorMessage);
82
82
  result.errorMessage && __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(result.errorMessage);
83
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn('With the `abortOnError` configuration currently turned off, type errors do not cause build failures, but they do not guarantee proper type file output.');
83
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn('With `abortOnError` configuration currently disabled, type errors will not fail the build, but proper type declaration output cannot be guaranteed.');
84
84
  }
85
85
  });
86
86
  const killProcesses = ()=>{
package/dist/tsc.js CHANGED
@@ -2,6 +2,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/co
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
5
+ const logPrefix = __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].dim('[tsc]');
5
6
  async function handleDiagnosticsAndProcessFiles(diagnostics, configPath, host, bundle, declarationDir, dtsExtension, redirect, rootDir, banner, footer, name) {
6
7
  const diagnosticMessages = [];
7
8
  for (const diagnostic of diagnostics){
@@ -11,9 +12,8 @@ async function handleDiagnosticsAndProcessFiles(diagnostics, configPath, host, b
11
12
  }
12
13
  await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
13
14
  if (diagnosticMessages.length) {
14
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Failed to emit declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
15
- for (const message of diagnosticMessages)__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(message);
16
- throw new Error('DTS generation failed');
15
+ for (const message of diagnosticMessages)__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefix, message);
16
+ throw new Error(`Failed to generate declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
17
17
  }
18
18
  }
19
19
  async function emitDts(options, onComplete, bundle = false, isWatch = false, build = false) {
@@ -36,21 +36,21 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false, bui
36
36
  };
37
37
  const reportDiagnostic = (diagnostic)=>{
38
38
  const fileLoc = (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getFileLoc)(diagnostic, configPath);
39
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`${fileLoc} - ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red('error')} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`TS${diagnostic.code}:`)}`, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));
39
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefix, `${fileLoc} - ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red('error')} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`TS${diagnostic.code}:`)}`, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));
40
40
  };
41
41
  const reportWatchStatusChanged = async (diagnostic, _newLine, _options, errorCount)=>{
42
42
  const message = `${__WEBPACK_EXTERNAL_MODULE_typescript__["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`;
43
- if (6031 === diagnostic.code || 6032 === diagnostic.code) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(message);
43
+ if (6031 === diagnostic.code || 6032 === diagnostic.code) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(logPrefix, message);
44
44
  if (6194 === diagnostic.code) {
45
- if (0 !== errorCount && errorCount) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(message);
45
+ if (0 !== errorCount && errorCount) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefix, message);
46
46
  else {
47
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(message);
47
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(logPrefix, message);
48
48
  onComplete(true);
49
49
  }
50
50
  await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
51
51
  }
52
52
  if (6193 === diagnostic.code) {
53
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(message);
53
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefix, message);
54
54
  await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
55
55
  }
56
56
  };
@@ -96,10 +96,7 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false, bui
96
96
  ], compilerOptions);
97
97
  solutionBuilder.build();
98
98
  await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
99
- if (errorNumber > 0) {
100
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Failed to emit declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
101
- throw new Error('DTS generation failed');
102
- }
99
+ if (errorNumber > 0) throw new Error(`Failed to generate declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
103
100
  }
104
101
  } else {
105
102
  const host = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createCompilerHost(compilerOptions);
@@ -114,7 +111,7 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false, bui
114
111
  const allDiagnostics = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
115
112
  await handleDiagnosticsAndProcessFiles(allDiagnostics, configPath, host, bundle, declarationDir, dtsExtension, redirect, rootDir, banner, footer, name);
116
113
  }
117
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.ready(`DTS generated in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
114
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.ready(`declaration files generated in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
118
115
  }
119
116
  }
120
117
  export { emitDts };
package/dist/utils.js CHANGED
@@ -216,7 +216,7 @@ async function processDtsFiles(bundle, dir, dtsExtension, redirect, tsconfigPath
216
216
  const newFile = file.replace('.d.ts', dtsExtension);
217
217
  __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].renameSync(file, newFile);
218
218
  } catch (error) {
219
- __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Error renaming DTS file ${file}: ${error}`);
219
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Failed to rename declaration file ${file}: ${error}`);
220
220
  }
221
221
  }
222
222
  function processSourceEntry(bundle, entryConfig) {
@@ -225,7 +225,7 @@ function processSourceEntry(bundle, entryConfig) {
225
225
  name,
226
226
  path
227
227
  }));
228
- throw new Error('@microsoft/api-extractor only support entry of Record<string, string> type to bundle DTS, please check your entry config.');
228
+ throw new Error('@microsoft/api-extractor only support entry of Record<string, string> type to bundle declaration files, please check your entry config.');
229
229
  }
230
230
  async function calcLongestCommonPath(absPaths) {
231
231
  if (0 === absPaths.length) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-dts",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Rsbuild plugin that supports emitting declaration files for TypeScript.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -25,17 +25,17 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@ast-grep/napi": "^0.35.0",
28
+ "@ast-grep/napi": "^0.36.0",
29
29
  "magic-string": "^0.30.17",
30
30
  "picocolors": "1.1.1",
31
31
  "tinyglobby": "^0.2.12",
32
32
  "tsconfig-paths": "^4.2.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@microsoft/api-extractor": "^7.51.0",
36
- "@rsbuild/core": "~1.2.13",
35
+ "@microsoft/api-extractor": "^7.51.1",
36
+ "@rsbuild/core": "~1.2.16",
37
37
  "rsbuild-plugin-publint": "^0.3.0",
38
- "rslib": "npm:@rslib/core@0.5.2",
38
+ "rslib": "npm:@rslib/core@0.5.3",
39
39
  "typescript": "^5.8.2",
40
40
  "@rslib/tsconfig": "0.0.1"
41
41
  },