rsbuild-plugin-dts 0.6.2 → 0.6.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/dist/apiExtractor.js +10 -4
- package/dist/index.js +4 -4
- package/dist/utils.js +44 -33
- package/package.json +5 -5
package/dist/apiExtractor.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE__microsoft_api_extractor_99b102c2__ from "@microsoft/api-extractor";
|
|
3
2
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
4
3
|
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
5
4
|
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
6
5
|
const logPrefixApiExtractor = __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].dim('[api-extractor]');
|
|
7
6
|
async function bundleDts(options) {
|
|
7
|
+
let apiExtractor;
|
|
8
|
+
try {
|
|
9
|
+
apiExtractor = await import("@microsoft/api-extractor");
|
|
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.`);
|
|
12
|
+
}
|
|
13
|
+
const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor;
|
|
8
14
|
const { name, cwd, distPath, dtsExtension, banner, footer, dtsEntry, tsconfigPath = 'tsconfig.json', bundledPackages = [] } = options;
|
|
9
15
|
try {
|
|
10
16
|
await Promise.all(dtsEntry.map(async (entry)=>{
|
|
@@ -23,15 +29,15 @@ async function bundleDts(options) {
|
|
|
23
29
|
},
|
|
24
30
|
projectFolder: cwd
|
|
25
31
|
};
|
|
26
|
-
const extractorConfig =
|
|
32
|
+
const extractorConfig = ExtractorConfig.prepare({
|
|
27
33
|
configObject: internalConfig,
|
|
28
34
|
configObjectFullPath: void 0,
|
|
29
35
|
packageJsonFullPath: (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, 'package.json')
|
|
30
36
|
});
|
|
31
|
-
const extractorResult =
|
|
37
|
+
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
32
38
|
localBuild: true,
|
|
33
39
|
messageCallback (message) {
|
|
34
|
-
if ('console-compiler-version-notice' === message.messageId || 'console-preamble' === message.messageId) message.logLevel =
|
|
40
|
+
if ('console-compiler-version-notice' === message.messageId || 'console-preamble' === message.messageId) message.logLevel = ExtractorLogLevel.None;
|
|
35
41
|
}
|
|
36
42
|
});
|
|
37
43
|
if (!extractorResult.succeeded) throw new Error(`API Extractor error. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/co
|
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
6
6
|
import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const src_filename = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url);
|
|
9
|
+
const src_dirname = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(src_filename);
|
|
10
10
|
const PLUGIN_DTS_NAME = 'rsbuild:dts';
|
|
11
11
|
const pluginDts = (options = {})=>({
|
|
12
12
|
name: PLUGIN_DTS_NAME,
|
|
@@ -39,8 +39,8 @@ const pluginDts = (options = {})=>({
|
|
|
39
39
|
if (false !== config.output.cleanDistPath) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.cleanDtsFiles)(dtsEmitPath);
|
|
40
40
|
if (options.bundle) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.clearTempDeclarationDir)(cwd);
|
|
41
41
|
if (composite || incremental || options.build) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.cleanTsBuildInfoFile)(tsconfigPath, rawCompilerOptions);
|
|
42
|
-
const jsExtension = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(
|
|
43
|
-
const childProcess = (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.fork)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
42
|
+
const jsExtension = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(src_filename);
|
|
43
|
+
const childProcess = (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.fork)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(src_dirname, `./dts${jsExtension}`), [], {
|
|
44
44
|
stdio: 'inherit'
|
|
45
45
|
});
|
|
46
46
|
childProcesses.push(childProcess);
|
package/dist/utils.js
CHANGED
|
@@ -112,33 +112,42 @@ async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, ou
|
|
|
112
112
|
const sgNode = (await (0, __WEBPACK_EXTERNAL_MODULE__ast_grep_napi_5dd5d9b1__.parseAsync)("typescript", content)).root();
|
|
113
113
|
const matcher = {
|
|
114
114
|
rule: {
|
|
115
|
-
kind: 'string_fragment',
|
|
116
115
|
any: [
|
|
117
116
|
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
kind: 'import_statement',
|
|
118
|
+
has: {
|
|
119
|
+
field: 'source',
|
|
120
|
+
has: {
|
|
121
|
+
pattern: '$IMP',
|
|
122
|
+
kind: 'string_fragment'
|
|
123
|
+
}
|
|
122
124
|
}
|
|
123
125
|
},
|
|
124
126
|
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
kind: 'export_statement',
|
|
128
|
+
has: {
|
|
129
|
+
field: 'source',
|
|
130
|
+
has: {
|
|
131
|
+
pattern: '$IMP',
|
|
132
|
+
kind: 'string_fragment'
|
|
133
|
+
}
|
|
129
134
|
}
|
|
130
135
|
},
|
|
131
136
|
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
any: [
|
|
138
|
+
{
|
|
139
|
+
pattern: 'require($A)'
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
pattern: 'import($A)'
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
has: {
|
|
146
|
+
field: 'arguments',
|
|
147
|
+
has: {
|
|
148
|
+
has: {
|
|
149
|
+
pattern: '$IMP',
|
|
150
|
+
kind: 'string_fragment'
|
|
142
151
|
}
|
|
143
152
|
}
|
|
144
153
|
}
|
|
@@ -146,11 +155,14 @@ async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, ou
|
|
|
146
155
|
]
|
|
147
156
|
}
|
|
148
157
|
};
|
|
149
|
-
const matchModule = sgNode.findAll(matcher).map((
|
|
158
|
+
const matchModule = sgNode.findAll(matcher).map((match)=>{
|
|
159
|
+
const matchNode = match.getMatch('IMP');
|
|
160
|
+
return {
|
|
150
161
|
n: matchNode.text(),
|
|
151
162
|
s: matchNode.range().start.index,
|
|
152
163
|
e: matchNode.range().end.index
|
|
153
|
-
}
|
|
164
|
+
};
|
|
165
|
+
});
|
|
154
166
|
const extension = dtsExtension.replace(/\.d\.ts$/, '.js').replace(/\.d\.cts$/, '.cjs').replace(/\.d\.mts$/, '.mjs');
|
|
155
167
|
for (const imp of matchModule){
|
|
156
168
|
const { n: importPath, s: start, e: end } = imp;
|
|
@@ -200,24 +212,23 @@ async function processDtsFiles(bundle, dir, dtsExtension, redirect, tsconfigPath
|
|
|
200
212
|
let matchPath;
|
|
201
213
|
if (redirect.path || redirect.extension) {
|
|
202
214
|
const result = (0, __WEBPACK_EXTERNAL_MODULE_tsconfig_paths_df62e9eb__.loadConfig)(tsconfigPath);
|
|
203
|
-
if ('failed' === result.resultType)
|
|
204
|
-
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(result.message);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
215
|
+
if ('failed' === result.resultType) return void __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(result.message);
|
|
207
216
|
const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
|
|
208
217
|
matchPath = (0, __WEBPACK_EXTERNAL_MODULE_tsconfig_paths_df62e9eb__.createMatchPath)(absoluteBaseUrl, paths, mainFields, addMatchAll);
|
|
209
218
|
}
|
|
210
219
|
const dtsFiles = await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)(convertPath((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(dir, '/**/*.d.ts')), {
|
|
211
220
|
absolute: true
|
|
212
221
|
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
222
|
+
await Promise.all(dtsFiles.map(async (file)=>{
|
|
223
|
+
try {
|
|
224
|
+
if (banner || footer) await addBannerAndFooter(file, banner, footer);
|
|
225
|
+
if ((redirect.path || redirect.extension) && matchPath) await redirectDtsImports(file, dtsExtension, redirect, matchPath, dir, rootDir);
|
|
226
|
+
const newFile = file.replace('.d.ts', dtsExtension);
|
|
227
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(file, newFile);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Failed to rename declaration file ${file}: ${error}`);
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
221
232
|
}
|
|
222
233
|
function processSourceEntry(bundle, entryConfig) {
|
|
223
234
|
if (!bundle) return [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rsbuild-plugin-dts",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.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.
|
|
28
|
+
"@ast-grep/napi": "^0.37.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.52.
|
|
36
|
-
"@rsbuild/core": "1.3.
|
|
35
|
+
"@microsoft/api-extractor": "^7.52.4",
|
|
36
|
+
"@rsbuild/core": "1.3.8",
|
|
37
37
|
"rsbuild-plugin-publint": "^0.3.0",
|
|
38
|
-
"rslib": "npm:@rslib/core@0.6.
|
|
38
|
+
"rslib": "npm:@rslib/core@0.6.3",
|
|
39
39
|
"typescript": "^5.8.3",
|
|
40
40
|
"@rslib/tsconfig": "0.0.1"
|
|
41
41
|
},
|