rsbuild-plugin-dts 0.0.5 → 0.0.7

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
@@ -6,9 +6,9 @@
6
6
 
7
7
  Rslib is a library build tool powered by [Rsbuild](https://rsbuild.dev). It allows library developers to leverage the knowledge and ecosystem of webpack and Rspack.
8
8
 
9
- <!-- ## Documentation
9
+ ## Documentation
10
10
 
11
- https://rslib.dev/ -->
11
+ https://lib.rsbuild.dev/
12
12
 
13
13
  ## Contributing
14
14
 
@@ -3,11 +3,6 @@ import * as __WEBPACK_EXTERNAL_MODULE__microsoft_api_extractor__ from "@microsof
3
3
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
6
- var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
7
- var api_extractor_namespaceObject = __WEBPACK_EXTERNAL_MODULE__microsoft_api_extractor__;
8
- var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
9
- var external_picocolors_namespaceObject = __WEBPACK_EXTERNAL_MODULE_picocolors__;
10
- var external_utils_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__utils_js__;
11
6
  async function bundleDts(options) {
12
7
  const { name, cwd, outDir, dtsExtension, banner, footer, dtsEntry = {
13
8
  name: 'index',
@@ -15,7 +10,7 @@ async function bundleDts(options) {
15
10
  }, tsconfigPath = 'tsconfig.json', bundledPackages = [] } = options;
16
11
  try {
17
12
  const start = Date.now();
18
- const untrimmedFilePath = (0, external_node_path_namespaceObject.join)(cwd, (0, external_node_path_namespaceObject.relative)(cwd, outDir), `${dtsEntry.name}${dtsExtension}`);
13
+ const untrimmedFilePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(cwd, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.relative)(cwd, outDir), `${dtsEntry.name}${dtsExtension}`);
19
14
  const mainEntryPointFilePath = dtsEntry.path;
20
15
  const internalConfig = {
21
16
  mainEntryPointFilePath,
@@ -25,23 +20,23 @@ async function bundleDts(options) {
25
20
  untrimmedFilePath
26
21
  },
27
22
  compiler: {
28
- tsconfigFilePath: tsconfigPath.includes(cwd) ? tsconfigPath : (0, external_node_path_namespaceObject.join)(cwd, tsconfigPath)
23
+ tsconfigFilePath: tsconfigPath.includes(cwd) ? tsconfigPath : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(cwd, tsconfigPath)
29
24
  },
30
25
  projectFolder: cwd
31
26
  };
32
- const extractorConfig = api_extractor_namespaceObject.ExtractorConfig.prepare({
27
+ const extractorConfig = __WEBPACK_EXTERNAL_MODULE__microsoft_api_extractor__.ExtractorConfig.prepare({
33
28
  configObject: internalConfig,
34
29
  configObjectFullPath: void 0,
35
- packageJsonFullPath: (0, external_node_path_namespaceObject.join)(cwd, 'package.json')
30
+ packageJsonFullPath: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(cwd, 'package.json')
36
31
  });
37
- const extractorResult = api_extractor_namespaceObject.Extractor.invoke(extractorConfig, {
32
+ const extractorResult = __WEBPACK_EXTERNAL_MODULE__microsoft_api_extractor__.Extractor.invoke(extractorConfig, {
38
33
  localBuild: true
39
34
  });
40
- if (!extractorResult.succeeded) throw new Error(`API Extractor error. ${external_picocolors_namespaceObject["default"].gray(`(${name})`)}`);
41
- await (0, external_utils_js_namespaceObject.addBannerAndFooter)(untrimmedFilePath, banner, footer);
42
- core_namespaceObject.logger.info(`API Extractor bundle DTS succeeded: ${external_picocolors_namespaceObject["default"].cyan(untrimmedFilePath)} in ${(0, external_utils_js_namespaceObject.getTimeCost)(start)} ${external_picocolors_namespaceObject["default"].gray(`(${name})`)}`);
35
+ if (!extractorResult.succeeded) throw new Error(`API Extractor error. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
36
+ await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.addBannerAndFooter)(untrimmedFilePath, banner, footer);
37
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.info(`API Extractor bundle DTS succeeded: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(untrimmedFilePath)} in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
43
38
  } catch (e) {
44
- core_namespaceObject.logger.error('API Extractor Error');
39
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error('API Extractor Error');
45
40
  throw new Error(`${e}`);
46
41
  }
47
42
  }
package/dist/dts.js CHANGED
@@ -5,44 +5,16 @@ import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE__tsc_js__ from "./tsc.js";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
8
- var __webpack_modules__ = {
9
- "./apiExtractor": function(module) {
10
- module.exports = import("./apiExtractor.js");
11
- }
12
- };
13
- /************************************************************************/ // The module cache
14
- var __webpack_module_cache__ = {};
15
- // The require function
16
- function __webpack_require__(moduleId) {
17
- // Check if module is in cache
18
- var cachedModule = __webpack_module_cache__[moduleId];
19
- if (void 0 !== cachedModule) return cachedModule.exports;
20
- // Create a new module (and put it into the cache)
21
- var module = __webpack_module_cache__[moduleId] = {
22
- exports: {}
23
- };
24
- // Execute the module function
25
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
26
- // Return the exports of the module
27
- return module.exports;
28
- } /************************************************************************/
29
- var external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs__;
30
- var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
31
- var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
32
- var external_picocolors_namespaceObject = __WEBPACK_EXTERNAL_MODULE_picocolors__;
33
- var external_typescript_namespaceObject = __WEBPACK_EXTERNAL_MODULE_typescript__;
34
- var external_tsc_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__tsc_js__;
35
- var external_utils_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__utils_js__;
36
8
  const isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj);
37
9
  // use !externals
38
10
  const calcBundledPackages = (options)=>{
39
11
  const { autoExternal, cwd, userExternals } = options;
40
12
  let pkgJson;
41
13
  try {
42
- const content = external_node_fs_namespaceObject["default"].readFileSync((0, external_node_path_namespaceObject.join)(cwd, 'package.json'), 'utf-8');
14
+ const content = __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(cwd, 'package.json'), 'utf-8');
43
15
  pkgJson = JSON.parse(content);
44
16
  } catch (err) {
45
- core_namespaceObject.logger.warn('The type of third-party packages will not be bundled due to read package.json failed');
17
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.warn('The type of third-party packages will not be bundled due to read package.json failed');
46
18
  return [];
47
19
  }
48
20
  const externalOptions = autoExternal ? {
@@ -84,30 +56,30 @@ const calcBundledPackages = (options)=>{
84
56
  };
85
57
  async function generateDts(data) {
86
58
  const { bundle, distPath, dtsEntry, tsconfigPath, name, cwd, isWatch, dtsExtension = '.d.ts', autoExternal = true, userExternals, banner, footer } = data;
87
- core_namespaceObject.logger.start(`Generating DTS... ${external_picocolors_namespaceObject["default"].gray(`(${name})`)}`);
88
- const configPath = external_typescript_namespaceObject["default"].findConfigFile(cwd, external_typescript_namespaceObject["default"].sys.fileExists, tsconfigPath);
59
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.start(`Generating DTS... ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
60
+ const configPath = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].findConfigFile(cwd, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.fileExists, tsconfigPath);
89
61
  if (!configPath) {
90
- core_namespaceObject.logger.error(`tsconfig.json not found in ${cwd}`);
62
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(`tsconfig.json not found in ${cwd}`);
91
63
  throw new Error();
92
64
  }
93
- const { options: rawCompilerOptions, fileNames } = (0, external_utils_js_namespaceObject.loadTsconfig)(configPath);
94
- const rootDir = rawCompilerOptions.rootDir ?? await (0, external_utils_js_namespaceObject.calcLongestCommonPath)(fileNames) ?? (0, external_node_path_namespaceObject.dirname)(configPath);
65
+ const { options: rawCompilerOptions, fileNames } = (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.loadTsconfig)(configPath);
66
+ const rootDir = rawCompilerOptions.rootDir ?? await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.calcLongestCommonPath)(fileNames) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath);
95
67
  const outDir = distPath ? distPath : rawCompilerOptions.declarationDir || './dist';
96
68
  const getDeclarationDir = (bundle, distPath)=>{
97
- if (bundle) return (0, external_utils_js_namespaceObject.ensureTempDeclarationDir)(cwd);
69
+ if (bundle) return (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.ensureTempDeclarationDir)(cwd);
98
70
  return distPath ? distPath : rawCompilerOptions.declarationDir ?? './dist';
99
71
  };
100
72
  const declarationDir = getDeclarationDir(bundle, distPath);
101
73
  const { name: entryName, path: entryPath } = dtsEntry;
102
74
  let entry = '';
103
75
  if (true === bundle && entryPath) {
104
- const entrySourcePath = (0, external_node_path_namespaceObject.isAbsolute)(entryPath) ? entryPath : (0, external_node_path_namespaceObject.join)(cwd, entryPath);
105
- const relativePath = (0, external_node_path_namespaceObject.relative)(rootDir, (0, external_node_path_namespaceObject.dirname)(entrySourcePath));
106
- entry = (0, external_node_path_namespaceObject.join)(declarationDir, relativePath, (0, external_node_path_namespaceObject.basename)(entrySourcePath)).replace(/\.(js|mjs|jsx|ts|mts|tsx|cjs|cts|cjsx|ctsx|mjsx|mtsx)$/, '.d.ts');
76
+ const entrySourcePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(entryPath) ? entryPath : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(cwd, entryPath);
77
+ const relativePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.relative)(rootDir, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(entrySourcePath));
78
+ entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(declarationDir, relativePath, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.basename)(entrySourcePath)).replace(/\.(js|mjs|jsx|ts|mts|tsx|cjs|cts|cjsx|ctsx|mjsx|mtsx)$/, '.d.ts');
107
79
  }
108
80
  const bundleDtsIfNeeded = async ()=>{
109
81
  if (true === bundle) {
110
- const { bundleDts } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "./apiExtractor"));
82
+ const { bundleDts } = await import("./apiExtractor.js");
111
83
  await bundleDts({
112
84
  name,
113
85
  cwd,
@@ -131,7 +103,7 @@ async function generateDts(data) {
131
103
  const onComplete = async (isSuccess)=>{
132
104
  if (isSuccess) await bundleDtsIfNeeded();
133
105
  };
134
- await (0, external_tsc_js_namespaceObject.emitDts)({
106
+ await (0, __WEBPACK_EXTERNAL_MODULE__tsc_js__.emitDts)({
135
107
  name,
136
108
  cwd,
137
109
  configPath,
@@ -147,7 +119,7 @@ process.on('message', async (data)=>{
147
119
  try {
148
120
  await generateDts(data);
149
121
  } catch (e) {
150
- core_namespaceObject.logger.error(e);
122
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(e);
151
123
  process.send('error');
152
124
  process.exit(1);
153
125
  }
package/dist/index.js CHANGED
@@ -4,10 +4,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_child_process__ from "node:child_proc
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
7
- var external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_child_process__;
8
- var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
9
- var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
10
- var external_utils_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__utils_js__;
11
7
  var src_filename = __webpack_fileURLToPath__(import.meta.url);
12
8
  var src_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
13
9
  const PLUGIN_DTS_NAME = 'rsbuild:dts';
@@ -26,13 +22,13 @@ const pluginDts = (options)=>({
26
22
  if (!isFirstCompile) return;
27
23
  const { config } = environment;
28
24
  options.distPath = options.distPath ?? config.output?.distPath?.root;
29
- const jsExtension = (0, external_node_path_namespaceObject.extname)(src_filename);
30
- const childProcess = (0, external_node_child_process_namespaceObject.fork)((0, external_node_path_namespaceObject.join)(src_dirname, `./dts${jsExtension}`), [], {
25
+ const jsExtension = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.extname)(src_filename);
26
+ const childProcess = (0, __WEBPACK_EXTERNAL_MODULE_node_child_process__.fork)((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(src_dirname, `./dts${jsExtension}`), [], {
31
27
  stdio: 'inherit'
32
28
  });
33
29
  // TODO: @microsoft/api-extractor only support single entry to bundle DTS
34
30
  // use first element of Record<string, string> type entry config
35
- const dtsEntry = (0, external_utils_js_namespaceObject.processSourceEntry)(options.bundle, config.source?.entry);
31
+ const dtsEntry = (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.processSourceEntry)(options.bundle, config.source?.entry);
36
32
  const dtsGenOptions = {
37
33
  ...options,
38
34
  dtsEntry,
@@ -64,8 +60,8 @@ const pluginDts = (options)=>({
64
60
  if (!isFirstCompile) return;
65
61
  for (const result of promisesResult)if ('error' === result.status) {
66
62
  if (options.abortOnError) throw new Error(result.errorMessage);
67
- result.errorMessage && core_namespaceObject.logger.error(result.errorMessage);
68
- core_namespaceObject.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.');
63
+ result.errorMessage && __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(result.errorMessage);
64
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.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.');
69
65
  }
70
66
  },
71
67
  order: 'post'
package/dist/tsc.js CHANGED
@@ -2,14 +2,10 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
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__ from "./utils.js";
5
- var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
6
- var external_picocolors_namespaceObject = __WEBPACK_EXTERNAL_MODULE_picocolors__;
7
- var external_typescript_namespaceObject = __WEBPACK_EXTERNAL_MODULE_typescript__;
8
- var external_utils_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__utils_js__;
9
5
  async function emitDts(options, onComplete, bundle = false, isWatch = false) {
10
6
  const start = Date.now();
11
7
  const { configPath, declarationDir, name, dtsExtension, banner, footer } = options;
12
- const { options: rawCompilerOptions, fileNames } = (0, external_utils_js_namespaceObject.loadTsconfig)(configPath);
8
+ const { options: rawCompilerOptions, fileNames } = (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.loadTsconfig)(configPath);
13
9
  const compilerOptions = {
14
10
  ...rawCompilerOptions,
15
11
  noEmit: false,
@@ -18,58 +14,58 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false) {
18
14
  emitDeclarationOnly: true
19
15
  };
20
16
  if (isWatch) {
21
- const createProgram = external_typescript_namespaceObject["default"].createSemanticDiagnosticsBuilderProgram;
17
+ const createProgram = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createSemanticDiagnosticsBuilderProgram;
22
18
  const formatHost = {
23
19
  getCanonicalFileName: (path)=>path,
24
- getCurrentDirectory: external_typescript_namespaceObject["default"].sys.getCurrentDirectory,
25
- getNewLine: ()=>external_typescript_namespaceObject["default"].sys.newLine
20
+ getCurrentDirectory: __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.getCurrentDirectory,
21
+ getNewLine: ()=>__WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.newLine
26
22
  };
27
23
  const reportDiagnostic = (diagnostic)=>{
28
- const fileLoc = (0, external_utils_js_namespaceObject.getFileLoc)(diagnostic);
29
- core_namespaceObject.logger.error(`${fileLoc} - ${external_picocolors_namespaceObject["default"].red('error')} ${external_picocolors_namespaceObject["default"].gray(`TS${diagnostic.code}:`)}`, external_typescript_namespaceObject["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));
24
+ const fileLoc = (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.getFileLoc)(diagnostic);
25
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.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()));
30
26
  };
31
27
  const reportWatchStatusChanged = async (diagnostic, _newLine, _options, errorCount)=>{
32
- const message = `${external_typescript_namespaceObject["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())} ${external_picocolors_namespaceObject["default"].gray(`(${name})`)}`;
28
+ const message = `${__WEBPACK_EXTERNAL_MODULE_typescript__["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`;
33
29
  // 6031: File change detected. Starting incremental compilation...
34
30
  // 6032: Starting compilation in watch mode...
35
- if (6031 === diagnostic.code || 6032 === diagnostic.code) core_namespaceObject.logger.info(message);
31
+ if (6031 === diagnostic.code || 6032 === diagnostic.code) __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.info(message);
36
32
  // 6194: 0 errors or 2+ errors!
37
33
  if (6194 === diagnostic.code) {
38
34
  if (0 === errorCount) {
39
- core_namespaceObject.logger.info(message);
35
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.info(message);
40
36
  onComplete(true);
41
- } else core_namespaceObject.logger.error(message);
42
- await (0, external_utils_js_namespaceObject.processDtsFiles)(bundle, declarationDir, dtsExtension, banner, footer);
37
+ } else __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(message);
38
+ await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.processDtsFiles)(bundle, declarationDir, dtsExtension, banner, footer);
43
39
  }
44
40
  // 6193: 1 error
45
41
  if (6193 === diagnostic.code) {
46
- core_namespaceObject.logger.error(message);
47
- await (0, external_utils_js_namespaceObject.processDtsFiles)(bundle, declarationDir, dtsExtension, banner, footer);
42
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(message);
43
+ await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.processDtsFiles)(bundle, declarationDir, dtsExtension, banner, footer);
48
44
  }
49
45
  };
50
46
  const system = {
51
- ...external_typescript_namespaceObject["default"].sys
47
+ ...__WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys
52
48
  };
53
- const host = external_typescript_namespaceObject["default"].createWatchCompilerHost(configPath, compilerOptions, system, createProgram, reportDiagnostic, reportWatchStatusChanged);
54
- external_typescript_namespaceObject["default"].createWatchProgram(host);
49
+ const host = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createWatchCompilerHost(configPath, compilerOptions, system, createProgram, reportDiagnostic, reportWatchStatusChanged);
50
+ __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createWatchProgram(host);
55
51
  } else {
56
- const host = external_typescript_namespaceObject["default"].createCompilerHost(compilerOptions);
57
- const program = external_typescript_namespaceObject["default"].createProgram(fileNames, compilerOptions, host);
52
+ const host = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createCompilerHost(compilerOptions);
53
+ const program = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createProgram(fileNames, compilerOptions, host);
58
54
  const emitResult = program.emit();
59
- const allDiagnostics = external_typescript_namespaceObject["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
55
+ const allDiagnostics = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
60
56
  const diagnosticMessages = [];
61
57
  for (const diagnostic of allDiagnostics){
62
- const fileLoc = (0, external_utils_js_namespaceObject.getFileLoc)(diagnostic);
63
- const message = `${fileLoc} - ${external_picocolors_namespaceObject["default"].red('error')} ${external_picocolors_namespaceObject["default"].gray(`TS${diagnostic.code}:`)} ${external_typescript_namespaceObject["default"].flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine())}`;
58
+ const fileLoc = (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.getFileLoc)(diagnostic);
59
+ const message = `${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, host.getNewLine())}`;
64
60
  diagnosticMessages.push(message);
65
61
  }
66
- await (0, external_utils_js_namespaceObject.processDtsFiles)(bundle, declarationDir, dtsExtension, banner, footer);
62
+ await (0, __WEBPACK_EXTERNAL_MODULE__utils_js__.processDtsFiles)(bundle, declarationDir, dtsExtension, banner, footer);
67
63
  if (diagnosticMessages.length) {
68
- core_namespaceObject.logger.error(`Failed to emit declaration files. ${external_picocolors_namespaceObject["default"].gray(`(${name})`)}`);
69
- for (const message of diagnosticMessages)core_namespaceObject.logger.error(message);
64
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(`Failed to emit declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
65
+ for (const message of diagnosticMessages)__WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(message);
70
66
  throw new Error('DTS generation failed');
71
67
  }
72
- core_namespaceObject.logger.ready(`DTS generated in ${(0, external_utils_js_namespaceObject.getTimeCost)(start)} ${external_picocolors_namespaceObject["default"].gray(`(${name})`)}`);
68
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.ready(`DTS generated in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
73
69
  }
74
70
  }
75
71
  export { emitDts };
package/dist/utils.js CHANGED
@@ -7,42 +7,33 @@ import * as __WEBPACK_EXTERNAL_MODULE_fast_glob__ from "fast-glob";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE_magic_string__ from "magic-string";
8
8
  import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
10
- var external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs__;
11
- var promises_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs_promises__;
12
- var external_node_os_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_os__;
13
- var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
14
- var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
15
- var external_fast_glob_namespaceObject = __WEBPACK_EXTERNAL_MODULE_fast_glob__;
16
- var external_magic_string_namespaceObject = __WEBPACK_EXTERNAL_MODULE_magic_string__;
17
- var external_picocolors_namespaceObject = __WEBPACK_EXTERNAL_MODULE_picocolors__;
18
- var external_typescript_namespaceObject = __WEBPACK_EXTERNAL_MODULE_typescript__;
19
- const { convertPathToPattern } = external_fast_glob_namespaceObject["default"];
10
+ const { convertPathToPattern } = __WEBPACK_EXTERNAL_MODULE_fast_glob__["default"];
20
11
  function loadTsconfig(tsconfigPath) {
21
- const configFile = external_typescript_namespaceObject["default"].readConfigFile(tsconfigPath, external_typescript_namespaceObject["default"].sys.readFile);
22
- const configFileContent = external_typescript_namespaceObject["default"].parseJsonConfigFileContent(configFile.config, external_typescript_namespaceObject["default"].sys, external_node_path_namespaceObject["default"].dirname(tsconfigPath));
12
+ const configFile = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].readConfigFile(tsconfigPath, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.readFile);
13
+ const configFileContent = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].parseJsonConfigFileContent(configFile.config, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigPath));
23
14
  return configFileContent;
24
15
  }
25
16
  const TEMP_FOLDER = '.rslib';
26
17
  const TEMP_DTS_DIR = `${TEMP_FOLDER}/declarations`;
27
18
  function ensureTempDeclarationDir(cwd) {
28
- const dirPath = external_node_path_namespaceObject["default"].join(cwd, TEMP_DTS_DIR);
29
- if (external_node_fs_namespaceObject["default"].existsSync(dirPath)) return dirPath;
30
- external_node_fs_namespaceObject["default"].mkdirSync(dirPath, {
19
+ const dirPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(cwd, TEMP_DTS_DIR);
20
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(dirPath)) return dirPath;
21
+ __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].mkdirSync(dirPath, {
31
22
  recursive: true
32
23
  });
33
- const gitIgnorePath = external_node_path_namespaceObject["default"].join(cwd, TEMP_FOLDER, '.gitignore');
34
- external_node_fs_namespaceObject["default"].writeFileSync(gitIgnorePath, '**/*\n');
24
+ const gitIgnorePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(cwd, TEMP_FOLDER, '.gitignore');
25
+ __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].writeFileSync(gitIgnorePath, '**/*\n');
35
26
  return dirPath;
36
27
  }
37
28
  function getFileLoc(diagnostic) {
38
29
  if (diagnostic.file) {
39
- const { line, character } = external_typescript_namespaceObject["default"].getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
40
- return `${external_picocolors_namespaceObject["default"].cyan(diagnostic.file.fileName)}:${external_picocolors_namespaceObject["default"].yellow(line + 1)}:${external_picocolors_namespaceObject["default"].yellow(character + 1)}`;
30
+ const { line, character } = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
31
+ return `${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(diagnostic.file.fileName)}:${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(line + 1)}:${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(character + 1)}`;
41
32
  }
42
33
  return '';
43
34
  }
44
35
  const prettyTime = (seconds)=>{
45
- const format = (time)=>external_picocolors_namespaceObject["default"].bold(time);
36
+ const format = (time)=>__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].bold(time);
46
37
  if (seconds < 10) {
47
38
  const digits = seconds >= 0.01 ? 2 : 3;
48
39
  return `${format(seconds.toFixed(digits))} s`;
@@ -54,7 +45,7 @@ const prettyTime = (seconds)=>{
54
45
  // fast-glob only accepts posix path
55
46
  // https://github.com/mrmlnc/fast-glob#convertpathtopatternpath
56
47
  const convertPath = (path)=>{
57
- if ('win32' === (0, external_node_os_namespaceObject.platform)()) return convertPathToPattern(path);
48
+ if ('win32' === (0, __WEBPACK_EXTERNAL_MODULE_node_os__.platform)()) return convertPathToPattern(path);
58
49
  return path;
59
50
  };
60
51
  function getTimeCost(start) {
@@ -63,21 +54,21 @@ function getTimeCost(start) {
63
54
  }
64
55
  async function addBannerAndFooter(file, banner, footer) {
65
56
  if (!banner && !footer) return;
66
- const content = await promises_namespaceObject["default"].readFile(file, 'utf-8');
67
- const code = new external_magic_string_namespaceObject["default"](content);
57
+ const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].readFile(file, 'utf-8');
58
+ const code = new __WEBPACK_EXTERNAL_MODULE_magic_string__["default"](content);
68
59
  banner && code.prepend(`${banner}\n`);
69
60
  footer && code.append(`\n${footer}\n`);
70
- await promises_namespaceObject["default"].writeFile(file, code.toString());
61
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].writeFile(file, code.toString());
71
62
  }
72
63
  async function processDtsFiles(bundle, dir, dtsExtension, banner, footer) {
73
64
  if (bundle) return;
74
- const dtsFiles = await (0, external_fast_glob_namespaceObject["default"])(convertPath((0, external_node_path_namespaceObject.join)(dir, '/**/*.d.ts')));
65
+ const dtsFiles = await (0, __WEBPACK_EXTERNAL_MODULE_fast_glob__["default"])(convertPath((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(dir, '/**/*.d.ts')));
75
66
  for (const file of dtsFiles)try {
76
67
  await addBannerAndFooter(file, banner, footer);
77
68
  const newFile = file.replace('.d.ts', dtsExtension);
78
- external_node_fs_namespaceObject["default"].renameSync(file, newFile);
69
+ __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].renameSync(file, newFile);
79
70
  } catch (error) {
80
- core_namespaceObject.logger.error(`Error renaming DTS file ${file}: ${error}`);
71
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error(`Error renaming DTS file ${file}: ${error}`);
81
72
  }
82
73
  }
83
74
  function processSourceEntry(bundle, entryConfig) {
@@ -97,7 +88,7 @@ async function calcLongestCommonPath(absPaths) {
97
88
  // we support two cases
98
89
  // 1. /packages-a/src/index.ts
99
90
  // 2. D:/packages-a/src/index.ts
100
- const sep = external_node_path_namespaceObject["default"].posix.sep;
91
+ const sep = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep;
101
92
  const splitPaths = absPaths.map((p)=>p.split(sep));
102
93
  let lcaFragments = splitPaths[0];
103
94
  for(let i = 1; i < splitPaths.length; i++){
@@ -108,8 +99,8 @@ async function calcLongestCommonPath(absPaths) {
108
99
  lcaFragments = lcaFragments.slice(0, j);
109
100
  }
110
101
  let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
111
- const stats = await promises_namespaceObject["default"].stat(lca);
112
- if (stats?.isFile()) lca = external_node_path_namespaceObject["default"].dirname(lca);
102
+ const stats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].stat(lca);
103
+ if (stats?.isFile()) lca = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(lca);
113
104
  return lca;
114
105
  }
115
106
  export { TEMP_DTS_DIR, TEMP_FOLDER, addBannerAndFooter, calcLongestCommonPath, ensureTempDeclarationDir, getFileLoc, getTimeCost, loadTsconfig, prettyTime, processDtsFiles, processSourceEntry };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-dts",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Dts plugin for Rsbuild",
5
- "homepage": "https://rslib.dev",
5
+ "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
7
7
  "url": "https://github.com/web-infra-dev/rslib/issues"
8
8
  },
@@ -30,10 +30,10 @@
30
30
  "picocolors": "1.1.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@microsoft/api-extractor": "^7.47.7",
34
- "@rsbuild/core": "1.0.1-rc.4",
35
- "rslib": "npm:@rslib/core@0.0.4",
36
- "typescript": "^5.5.4",
33
+ "@microsoft/api-extractor": "^7.47.9",
34
+ "@rsbuild/core": "1.0.5",
35
+ "rslib": "npm:@rslib/core@0.0.6",
36
+ "typescript": "^5.6.2",
37
37
  "@rslib/tsconfig": "0.0.1"
38
38
  },
39
39
  "peerDependencies": {