rsbuild-plugin-dts 0.9.0 → 0.9.1

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
@@ -1,5 +1,5 @@
1
1
  <picture>
2
- <img alt="Rslib Banner" src="https://assets.rspack.dev/rslib/rslib-banner.png">
2
+ <img alt="Rslib Banner" src="https://assets.rspack.rs/rslib/rslib-banner.png">
3
3
  </picture>
4
4
 
5
5
  # rsbuild-plugin-dts
@@ -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 [Declaration files](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://rslib.rs/guide/advanced/dts) and [lib.dts](https://rslib.rs/config/lib/dts) for more details.
12
12
 
13
13
  ## Using in Rsbuild
14
14
 
@@ -38,7 +38,7 @@ export default {
38
38
 
39
39
  Whether to bundle the declaration files.
40
40
 
41
- If you want to [bundle declaration files](https://lib.rsbuild.dev/guide/advanced/dts#bundle-declaration-files) files, you should:
41
+ If you want to [bundle declaration files](https://rslib.rs/guide/advanced/dts#bundle-declaration-files) files, you should:
42
42
 
43
43
  1. Install `@microsoft/api-extractor` as a development dependency, which is the underlying tool used for bundling declaration files.
44
44
 
@@ -54,6 +54,33 @@ pluginDts({
54
54
  });
55
55
  ```
56
56
 
57
+ #### bundle.bundledPackages
58
+
59
+ - **Type:** `string[]`
60
+
61
+ Specifies the dependencies whose declaration files should be bundled. This configuration is passed to the [bundledPackages](https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages) option of `@microsoft/api-extractor`.
62
+
63
+ By default, `rsbuild-plugin-dts` determines externalized dependencies based on the following configurations.
64
+
65
+ - [autoExternal](#autoexternal) configuration
66
+ - [output.externals](https://rsbuild.rs/config/output/externals) configuration
67
+
68
+ Direct dependencies (declared in `package.json`) that are not externalized will be automatically added to `bundledPackages`, and their declaration files will be bundled into the final output.
69
+
70
+ When the default behavior does not meet the requirements, you can explicitly specify the dependencies whose declaration files need to be bundled through `bundle.bundledPackages`. After setting this configuration, the above default behavior will be completely overwritten.
71
+
72
+ This is typically used for bundling transitive dependencies (dependencies of direct dependencies). For example, if the project directly depends on `foo`, and `foo` depends on `bar`, you can bundle both `foo` and `bar`'s declaration files as follows:
73
+
74
+ ```js
75
+ pluginDts({
76
+ bundle: {
77
+ bundledPackages: ['foo', 'bar'],
78
+ },
79
+ });
80
+ ```
81
+
82
+ > `bundledPackages` can be specified with the [minimatch](https://www.npmjs.com/package/minimatch) syntax, but will only match the declared direct dependencies in `package.json`.
83
+
57
84
  ### distPath
58
85
 
59
86
  - **Type:** `string`
@@ -62,7 +89,7 @@ The output directory of declaration files. The default value follows the priorit
62
89
 
63
90
  1. The `distPath` value of the plugin options.
64
91
  2. The `declarationDir` value in the `tsconfig.json` file.
65
- 3. The [output.distPath.root](https://rsbuild.dev/config/output/dist-path) value of Rsbuild configuration.
92
+ 3. The [output.distPath.root](https://rsbuild.rs/config/output/dist-path) value of Rsbuild configuration.
66
93
 
67
94
  ```js
68
95
  pluginDts({
@@ -8,7 +8,7 @@ async function bundleDts(options) {
8
8
  try {
9
9
  apiExtractor = await import("@microsoft/api-extractor");
10
10
  } catch {
11
- throw new Error(`${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('@microsoft/api-extractor')} is required when ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('dts.bundle')} is set to ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('true')}, please make sure it is installed. You could check https://lib.rsbuild.dev/guide/advanced/dts#how-to-generate-declaration-files-in-rslib for more details.`);
11
+ throw new Error(`${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('@microsoft/api-extractor')} is required when ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('dts.bundle')} is set to ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('true')}, please make sure it is installed. You could check https://rslib.rs/guide/advanced/dts#how-to-generate-declaration-files-in-rslib for more details.`);
12
12
  }
13
13
  const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor;
14
14
  const { name, cwd, distPath, dtsExtension, banner, footer, dtsEntry, tsconfigPath = 'tsconfig.json', bundledPackages = [] } = options;
package/dist/dts.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { DtsGenOptions } from './index';
2
2
  export declare const calcBundledPackages: (options: {
3
- autoExternal: DtsGenOptions["autoExternal"];
4
3
  cwd: string;
4
+ autoExternal: DtsGenOptions["autoExternal"];
5
5
  userExternals?: DtsGenOptions["userExternals"];
6
+ overrideBundledPackages?: string[];
6
7
  }) => string[];
7
8
  export declare function generateDts(data: DtsGenOptions): Promise<void>;
package/dist/dts.js CHANGED
@@ -6,7 +6,8 @@ import * as __WEBPACK_EXTERNAL_MODULE__tsc_js_1050029c__ from "./tsc.js";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
7
7
  const isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj);
8
8
  const calcBundledPackages = (options)=>{
9
- const { autoExternal, cwd, userExternals } = options;
9
+ const { cwd, autoExternal, userExternals, overrideBundledPackages } = options;
10
+ if (overrideBundledPackages) return overrideBundledPackages;
10
11
  let pkgJson;
11
12
  try {
12
13
  const content = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, 'package.json'), 'utf-8');
@@ -52,7 +53,7 @@ const calcBundledPackages = (options)=>{
52
53
  return Array.from(new Set(bundledPackages));
53
54
  };
54
55
  async function generateDts(data) {
55
- const { bundle, dtsEntry, dtsEmitPath, tsconfigPath, tsConfigResult, name, cwd, build, isWatch, dtsExtension = '.d.ts', autoExternal = true, userExternals, banner, footer, redirect = {
56
+ const { bundle, dtsEntry, dtsEmitPath, tsconfigPath, tsConfigResult, name, cwd, build, isWatch, dtsExtension = '.d.ts', autoExternal = true, userExternals, apiExtractorOptions, banner, footer, redirect = {
56
57
  path: true,
57
58
  extension: false
58
59
  } } = data;
@@ -93,9 +94,10 @@ async function generateDts(data) {
93
94
  banner,
94
95
  footer,
95
96
  bundledPackages: calcBundledPackages({
96
- autoExternal,
97
97
  cwd,
98
- userExternals
98
+ autoExternal,
99
+ userExternals,
100
+ overrideBundledPackages: apiExtractorOptions?.bundledPackages
99
101
  })
100
102
  });
101
103
  }
package/dist/index.d.ts CHANGED
@@ -4,8 +4,11 @@ export type DtsRedirect = {
4
4
  path?: boolean;
5
5
  extension?: boolean;
6
6
  };
7
+ export type ApiExtractorOptions = {
8
+ bundledPackages?: string[];
9
+ };
7
10
  export type PluginDtsOptions = {
8
- bundle?: boolean;
11
+ bundle?: boolean | ApiExtractorOptions;
9
12
  distPath?: string;
10
13
  build?: boolean;
11
14
  abortOnError?: boolean;
@@ -24,7 +27,8 @@ export type DtsEntry = {
24
27
  name?: string;
25
28
  path?: string;
26
29
  };
27
- export type DtsGenOptions = PluginDtsOptions & {
30
+ export type DtsGenOptions = Omit<PluginDtsOptions, 'bundle'> & {
31
+ bundle: boolean;
28
32
  name: string;
29
33
  cwd: string;
30
34
  isWatch: boolean;
@@ -34,6 +38,7 @@ export type DtsGenOptions = PluginDtsOptions & {
34
38
  tsconfigPath: string;
35
39
  tsConfigResult: ts.ParsedCommandLine;
36
40
  userExternals?: NonNullable<RsbuildConfig['output']>['externals'];
41
+ apiExtractorOptions?: ApiExtractorOptions;
37
42
  };
38
43
  export declare const PLUGIN_DTS_NAME = "rsbuild:dts";
39
44
  export declare const pluginDts: (options?: PluginDtsOptions) => RsbuildPlugin;
package/dist/index.js CHANGED
@@ -11,7 +11,11 @@ const PLUGIN_DTS_NAME = 'rsbuild:dts';
11
11
  const pluginDts = (options = {})=>({
12
12
  name: PLUGIN_DTS_NAME,
13
13
  setup (api) {
14
- options.bundle = options.bundle ?? false;
14
+ let apiExtractorOptions = {};
15
+ if (options.bundle && 'object' == typeof options.bundle) apiExtractorOptions = {
16
+ ...options.bundle
17
+ };
18
+ const bundle = !!options.bundle;
15
19
  options.abortOnError = options.abortOnError ?? true;
16
20
  options.build = options.build ?? false;
17
21
  options.redirect = options.redirect ?? {};
@@ -23,7 +27,7 @@ const pluginDts = (options = {})=>({
23
27
  api.onBeforeEnvironmentCompile(async ({ isWatch, isFirstCompile, environment })=>{
24
28
  if (!isFirstCompile) return;
25
29
  const { config } = environment;
26
- const dtsEntry = (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processSourceEntry)(options.bundle, config.source?.entry);
30
+ const dtsEntry = (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processSourceEntry)(bundle, config.source?.entry);
27
31
  const cwd = api.context.rootPath;
28
32
  const tsconfigPath = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].findConfigFile(cwd, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.fileExists, config.source.tsconfigPath);
29
33
  if (!tsconfigPath) {
@@ -37,7 +41,7 @@ const pluginDts = (options = {})=>({
37
41
  (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.warnIfOutside)(cwd, declarationDir, 'declarationDir');
38
42
  (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.warnIfOutside)(cwd, outDir, 'outDir');
39
43
  if (false !== config.output.cleanDistPath) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.cleanDtsFiles)(dtsEmitPath);
40
- if (options.bundle) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.clearTempDeclarationDir)(cwd);
44
+ if (bundle) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.clearTempDeclarationDir)(cwd);
41
45
  if (composite || incremental || options.build) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.cleanTsBuildInfoFile)(tsconfigPath, rawCompilerOptions);
42
46
  const jsExtension = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(src_filename);
43
47
  const childProcess = (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.fork)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(src_dirname, `./dts${jsExtension}`), [], {
@@ -46,9 +50,11 @@ const pluginDts = (options = {})=>({
46
50
  childProcesses.push(childProcess);
47
51
  const dtsGenOptions = {
48
52
  ...options,
53
+ bundle,
49
54
  dtsEntry,
50
55
  dtsEmitPath,
51
56
  userExternals: config.output.externals,
57
+ apiExtractorOptions,
52
58
  tsconfigPath,
53
59
  tsConfigResult,
54
60
  name: environment.name,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-dts",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Rsbuild plugin that supports emitting declaration files for TypeScript.",
5
- "homepage": "https://lib.rsbuild.dev",
5
+ "homepage": "https://rslib.rs",
6
6
  "bugs": {
7
7
  "url": "https://github.com/web-infra-dev/rslib/issues"
8
8
  },
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@microsoft/api-extractor": "^7.52.8",
36
- "@rsbuild/core": "1.3.21",
36
+ "@rsbuild/core": "~1.3.21",
37
37
  "rsbuild-plugin-publint": "^0.3.2",
38
- "rslib": "npm:@rslib/core@0.8.0",
38
+ "rslib": "npm:@rslib/core@0.9.0",
39
39
  "typescript": "^5.8.3",
40
40
  "@rslib/tsconfig": "0.0.1"
41
41
  },