rsbuild-plugin-dts 0.1.1 → 0.1.3

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/dts.js CHANGED
@@ -55,9 +55,16 @@ const calcBundledPackages = (options)=>{
55
55
  return Array.from(new Set(bundledPackages));
56
56
  };
57
57
  async function generateDts(data) {
58
- const { bundle, dtsEmitPath, dtsEntry, tsconfigPath, tsConfigResult, name, cwd, build, isWatch, dtsExtension = '.d.ts', autoExternal = true, userExternals, banner, footer } = data;
58
+ const { bundle, dtsEntry, tsconfigPath, tsConfigResult, distPath, rootDistPath, cleanDistPath, name, cwd, build, isWatch, dtsExtension = '.d.ts', autoExternal = true, userExternals, banner, footer } = data;
59
59
  __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.start(`Generating DTS... ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
60
60
  const { options: rawCompilerOptions, fileNames } = tsConfigResult;
61
+ const dtsEmitPath = distPath ?? rawCompilerOptions.declarationDir ?? rootDistPath;
62
+ // clean dts files
63
+ if (false !== cleanDistPath) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.cleanDtsFiles)(dtsEmitPath);
64
+ // clean .rslib temp folder
65
+ if (bundle) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.clearTempDeclarationDir)(cwd);
66
+ // clean tsbuildinfo file
67
+ if (rawCompilerOptions.composite || rawCompilerOptions.incremental || build) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.cleanTsBuildInfoFile)(tsconfigPath, rawCompilerOptions);
61
68
  // The longest common path of all non-declaration input files.
62
69
  // If composite is set, the default is instead the directory containing the tsconfig.json file.
63
70
  // see https://www.typescriptlang.org/tsconfig/#rootDir
package/dist/index.d.ts CHANGED
@@ -23,10 +23,11 @@ export type DtsGenOptions = PluginDtsOptions & {
23
23
  cwd: string;
24
24
  isWatch: boolean;
25
25
  dtsEntry: DtsEntry;
26
- dtsEmitPath: string;
27
26
  build?: boolean;
28
27
  tsconfigPath: string;
29
28
  tsConfigResult: ts.ParsedCommandLine;
29
+ rootDistPath: string;
30
+ cleanDistPath: NonNullable<RsbuildConfig['output']>['cleanDistPath'];
30
31
  userExternals?: NonNullable<RsbuildConfig['output']>['externals'];
31
32
  };
32
33
  export declare const PLUGIN_DTS_NAME = "rsbuild:dts";
package/dist/index.js CHANGED
@@ -32,26 +32,19 @@ const pluginDts = (options = {})=>({
32
32
  throw new Error();
33
33
  }
34
34
  const tsConfigResult = (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.loadTsconfig)(tsconfigPath);
35
- const dtsEmitPath = options.distPath ?? tsConfigResult.options.declarationDir ?? config.output?.distPath?.root;
36
35
  const jsExtension = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.extname)(src_rslib_entry_filename);
37
36
  const childProcess = (0, __WEBPACK_EXTERNAL_MODULE_node_child_process__.fork)((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(src_rslib_entry_dirname, `./dts${jsExtension}`), [], {
38
37
  stdio: 'inherit'
39
38
  });
40
39
  childProcesses.push(childProcess);
41
- const { cleanDistPath } = config.output;
42
- // clean dts files
43
- if (false !== cleanDistPath) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.cleanDtsFiles)(dtsEmitPath);
44
- // clean .rslib temp folder
45
- if (options.bundle) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.clearTempDeclarationDir)(cwd);
46
- // clean tsbuildinfo file
47
- await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.cleanTsBuildInfoFile)(tsconfigPath, tsConfigResult);
48
40
  const dtsGenOptions = {
49
41
  ...options,
50
42
  dtsEntry,
51
- dtsEmitPath,
43
+ rootDistPath: config.output?.distPath?.root,
52
44
  userExternals: config.output.externals,
53
45
  tsconfigPath,
54
46
  tsConfigResult,
47
+ cleanDistPath: config.output.cleanDistPath,
55
48
  name: environment.name,
56
49
  cwd,
57
50
  isWatch
@@ -85,7 +78,11 @@ const pluginDts = (options = {})=>({
85
78
  order: 'post'
86
79
  });
87
80
  const killProcesses = ()=>{
88
- for (const childProcess of childProcesses)if (!childProcess.killed) childProcess.kill();
81
+ for (const childProcess of childProcesses)if (!childProcess.killed) try {
82
+ childProcess.kill();
83
+ // mute kill error, such as: kill EPERM error on windows
84
+ // https://github.com/nodejs/node/issues/51766
85
+ } catch (_err) {}
89
86
  childProcesses = [];
90
87
  };
91
88
  api.onCloseBuild(killProcesses);
package/dist/utils.d.ts CHANGED
@@ -16,4 +16,4 @@ export declare function processDtsFiles(bundle: boolean, dir: string, dtsExtensi
16
16
  export declare function processSourceEntry(bundle: boolean, entryConfig: NonNullable<RsbuildConfig['source']>['entry']): DtsEntry;
17
17
  export declare function calcLongestCommonPath(absPaths: string[]): Promise<string | null>;
18
18
  export declare function cleanDtsFiles(dir: string): Promise<void>;
19
- export declare function cleanTsBuildInfoFile(tsconfigPath: string, tsConfigResult: ts.ParsedCommandLine): Promise<void>;
19
+ export declare function cleanTsBuildInfoFile(tsconfigPath: string, compilerOptions: ts.CompilerOptions): Promise<void>;
package/dist/utils.js CHANGED
@@ -137,12 +137,12 @@ async function cleanDtsFiles(dir) {
137
137
  force: true
138
138
  })));
139
139
  }
140
- async function cleanTsBuildInfoFile(tsconfigPath, tsConfigResult) {
140
+ async function cleanTsBuildInfoFile(tsconfigPath, compilerOptions) {
141
141
  const tsconfigDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(tsconfigPath);
142
- const { outDir, rootDir, tsBuildInfoFile } = tsConfigResult.options;
142
+ const { outDir, rootDir, tsBuildInfoFile } = compilerOptions;
143
143
  let tsbuildInfoFilePath = `${(0, __WEBPACK_EXTERNAL_MODULE_node_path__.basename)(tsconfigPath, '.json')}${tsBuildInfoFile ?? '.tsbuildinfo'}`;
144
144
  if (outDir) tsbuildInfoFilePath = rootDir ? (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(outDir, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.relative)((0, __WEBPACK_EXTERNAL_MODULE_node_path__.resolve)(tsconfigDir, rootDir), tsconfigDir), tsbuildInfoFilePath) : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(outDir, tsbuildInfoFilePath);
145
- await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].rm(tsbuildInfoFilePath, {
145
+ if (await pathExists(tsbuildInfoFilePath)) await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].rm(tsbuildInfoFilePath, {
146
146
  force: true
147
147
  });
148
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-dts",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Rsbuild plugin that supports emitting declaration files for TypeScript.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@microsoft/api-extractor": "^7.48.0",
34
- "@rsbuild/core": "~1.1.6",
35
- "rslib": "npm:@rslib/core@0.1.0",
34
+ "@rsbuild/core": "~1.1.8",
35
+ "rslib": "npm:@rslib/core@0.1.2",
36
36
  "typescript": "^5.6.3",
37
37
  "@rslib/tsconfig": "0.0.1"
38
38
  },