rolldown-plugin-dts 0.21.2 → 0.21.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 +1 -1
- package/dist/index.d.mts +20 -2
- package/dist/index.mjs +103 -69
- package/dist/{resolver-DksQRwY1.mjs → resolver-CQnlAxJ7.mjs} +4 -1
- package/package.json +8 -8
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -162,18 +162,36 @@ interface Options extends GeneralOptions, TscOptions {
|
|
|
162
162
|
/**
|
|
163
163
|
* **[Experimental]** Enables DTS generation using `tsgo`.
|
|
164
164
|
*
|
|
165
|
-
* To use this option, make sure `@typescript/native-preview` is installed as a dependency
|
|
165
|
+
* To use this option, make sure `@typescript/native-preview` is installed as a dependency,
|
|
166
|
+
* or provide a custom path to the `tsgo` binary using the `path` option.
|
|
166
167
|
*
|
|
167
168
|
* **Note:** This option is not yet recommended for production environments.
|
|
168
169
|
* `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
|
|
170
|
+
*
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* // Use tsgo from `@typescript/native-preview` dependency
|
|
174
|
+
* tsgo: true
|
|
175
|
+
*
|
|
176
|
+
* // Use custom tsgo path (e.g., managed by Nix)
|
|
177
|
+
* tsgo: { path: '/path/to/tsgo' }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
tsgo?: boolean | TsgoOptions;
|
|
181
|
+
}
|
|
182
|
+
interface TsgoOptions {
|
|
183
|
+
enabled?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Custom path to the `tsgo` binary.
|
|
169
186
|
*/
|
|
170
|
-
|
|
187
|
+
path?: string;
|
|
171
188
|
}
|
|
172
189
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
173
190
|
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
|
174
191
|
tsconfig?: string;
|
|
175
192
|
oxc: IsolatedDeclarationsOptions | false;
|
|
176
193
|
tsconfigRaw: TsConfigJson;
|
|
194
|
+
tsgo: Omit<TsgoOptions, "enabled"> | false;
|
|
177
195
|
}>;
|
|
178
196
|
declare function resolveOptions({
|
|
179
197
|
cwd,
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
2
1
|
import { a as RE_JSON, c as RE_VUE, d as filename_to_dts, f as replaceTemplateName, i as RE_JS, l as filename_dts_to, n as RE_DTS, o as RE_NODE_MODULES, p as resolveTemplateFn, r as RE_DTS_MAP, s as RE_TS, t as RE_CSS, u as filename_js_to_dts } from "./filename-Cqnsj8Gp.mjs";
|
|
3
2
|
import { n as globalContext, r as invalidateContextFile, t as createContext } from "./context-EuY-ImLj.mjs";
|
|
4
3
|
import { createDebug } from "obug";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
parse
|
|
10
|
-
} = __cjs_require("@babel/parser");
|
|
11
|
-
const t = __cjs_require("@babel/types");
|
|
4
|
+
import { generate } from "@babel/generator";
|
|
5
|
+
import { parse } from "@babel/parser";
|
|
6
|
+
import * as t from "@babel/types";
|
|
12
7
|
import { isDeclarationType, isIdentifierOf, isTypeOf, resolveString, walkAST } from "ast-kit";
|
|
13
8
|
const {
|
|
14
9
|
fork,
|
|
@@ -69,9 +64,9 @@ function createDtsInputPlugin({ sideEffects }) {
|
|
|
69
64
|
//#endregion
|
|
70
65
|
//#region src/fake-js.ts
|
|
71
66
|
function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
72
|
-
let
|
|
67
|
+
let declarationIdx = 0;
|
|
73
68
|
const identifierMap = Object.create(null);
|
|
74
|
-
const
|
|
69
|
+
const declarationMap = /* @__PURE__ */ new Map();
|
|
75
70
|
const commentsMap = /* @__PURE__ */ new Map();
|
|
76
71
|
const typeOnlyMap = /* @__PURE__ */ new Map();
|
|
77
72
|
return {
|
|
@@ -115,7 +110,8 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
115
110
|
const file = parse(code, {
|
|
116
111
|
plugins: [["typescript", { dts: true }]],
|
|
117
112
|
sourceType: "module",
|
|
118
|
-
errorRecovery: true
|
|
113
|
+
errorRecovery: true,
|
|
114
|
+
createParenthesizedExpressions: true
|
|
119
115
|
});
|
|
120
116
|
const { program, comments } = file;
|
|
121
117
|
const typeOnlyIds = [];
|
|
@@ -131,9 +127,9 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
131
127
|
const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
|
|
132
128
|
if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
|
|
133
129
|
const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
|
|
134
|
-
const
|
|
135
|
-
const decl =
|
|
136
|
-
const setDecl =
|
|
130
|
+
const isExportDecl = isTypeOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && !!stmt.declaration;
|
|
131
|
+
const decl = isExportDecl ? stmt.declaration : stmt;
|
|
132
|
+
const setDecl = isExportDecl ? (decl$1) => stmt.declaration = decl$1 : setStmt;
|
|
137
133
|
if (decl.type !== "TSDeclareFunction" && !isDeclarationType(decl)) continue;
|
|
138
134
|
if (isTypeOf(decl, [
|
|
139
135
|
"TSEnumDeclaration",
|
|
@@ -155,22 +151,33 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
155
151
|
decl.id = binding;
|
|
156
152
|
}
|
|
157
153
|
const params = collectParams(decl);
|
|
158
|
-
const
|
|
154
|
+
const childrenSet = /* @__PURE__ */ new Set();
|
|
155
|
+
const deps = collectDependencies(decl, namespaceStmts, childrenSet);
|
|
156
|
+
const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
|
|
159
157
|
if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
|
|
160
|
-
const
|
|
158
|
+
const declarationId = registerDeclaration({
|
|
161
159
|
decl,
|
|
162
160
|
deps,
|
|
163
161
|
bindings,
|
|
164
|
-
params
|
|
162
|
+
params,
|
|
163
|
+
children
|
|
165
164
|
});
|
|
166
|
-
const
|
|
165
|
+
const declarationIdNode = t.numericLiteral(declarationId);
|
|
167
166
|
const depsNode = t.arrowFunctionExpression(params.map(({ name }) => t.identifier(name)), t.arrayExpression(deps));
|
|
167
|
+
const childrenNode = t.arrayExpression(children.map((node) => ({
|
|
168
|
+
type: "StringLiteral",
|
|
169
|
+
value: "",
|
|
170
|
+
start: node.start,
|
|
171
|
+
end: node.end,
|
|
172
|
+
loc: node.loc
|
|
173
|
+
})));
|
|
168
174
|
const sideEffectNode = sideEffect && t.callExpression(t.identifier("sideEffect"), [bindings[0]]);
|
|
169
|
-
const runtimeArrayNode = runtimeBindingArrayExpression(
|
|
170
|
-
|
|
175
|
+
const runtimeArrayNode = runtimeBindingArrayExpression([
|
|
176
|
+
declarationIdNode,
|
|
171
177
|
depsNode,
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
childrenNode,
|
|
179
|
+
...sideEffectNode ? [sideEffectNode] : []
|
|
180
|
+
]);
|
|
174
181
|
const runtimeAssignment = {
|
|
175
182
|
type: "VariableDeclaration",
|
|
176
183
|
kind: "var",
|
|
@@ -201,11 +208,15 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
201
208
|
...appendStmts
|
|
202
209
|
];
|
|
203
210
|
typeOnlyMap.set(id, typeOnlyIds);
|
|
204
|
-
|
|
211
|
+
const result = generate(file, {
|
|
205
212
|
comments: false,
|
|
206
213
|
sourceMaps: sourcemap,
|
|
207
214
|
sourceFileName: id
|
|
208
215
|
});
|
|
216
|
+
return {
|
|
217
|
+
code: result.code,
|
|
218
|
+
map: result.map
|
|
219
|
+
};
|
|
209
220
|
}
|
|
210
221
|
function renderChunk(code, chunk) {
|
|
211
222
|
if (!RE_DTS.test(chunk.fileName)) return;
|
|
@@ -225,31 +236,29 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
225
236
|
if (newNode || newNode === false) return newNode;
|
|
226
237
|
if (node.type !== "VariableDeclaration") return node;
|
|
227
238
|
if (!isRuntimeBindingVariableDeclaration(node)) return null;
|
|
228
|
-
const [
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
walkAST(
|
|
239
|
+
const [declarationIdNode, depsFn, children] = node.declarations[0].init.elements;
|
|
240
|
+
const declarationId = declarationIdNode.value;
|
|
241
|
+
const declaration = getDeclaration(declarationId);
|
|
242
|
+
walkAST(declaration.decl, { enter(node$1) {
|
|
232
243
|
delete node$1.loc;
|
|
233
244
|
} });
|
|
234
245
|
for (const [i, decl] of node.declarations.entries()) {
|
|
235
246
|
const transformedBinding = {
|
|
236
247
|
...decl.id,
|
|
237
|
-
typeAnnotation:
|
|
248
|
+
typeAnnotation: declaration.bindings[i].typeAnnotation
|
|
238
249
|
};
|
|
239
|
-
overwriteNode(
|
|
250
|
+
overwriteNode(declaration.bindings[i], transformedBinding);
|
|
240
251
|
}
|
|
252
|
+
for (const [i, child] of children.elements.entries()) Object.assign(declaration.children[i], { loc: child.loc });
|
|
241
253
|
const transformedParams = depsFn.params;
|
|
242
254
|
for (const [i, transformedParam] of transformedParams.entries()) {
|
|
243
255
|
const transformedName = transformedParam.name;
|
|
244
|
-
for (const originalTypeParam of
|
|
256
|
+
for (const originalTypeParam of declaration.params[i].typeParams) originalTypeParam.name = transformedName;
|
|
245
257
|
}
|
|
246
258
|
const transformedDeps = depsFn.body.elements;
|
|
247
|
-
for (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
else Object.assign(originalDep, transformedDeps[i]);
|
|
251
|
-
}
|
|
252
|
-
return inheritNodeComments(node, original.decl);
|
|
259
|
+
for (const [i, originalDep] of declaration.deps.entries()) if (originalDep.replace) originalDep.replace(transformedDeps[i]);
|
|
260
|
+
else Object.assign(originalDep, transformedDeps[i]);
|
|
261
|
+
return inheritNodeComments(node, declaration.decl);
|
|
253
262
|
}).filter((node) => !!node);
|
|
254
263
|
if (program.body.length === 0) return "export { };";
|
|
255
264
|
const comments = /* @__PURE__ */ new Set();
|
|
@@ -270,23 +279,27 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
270
279
|
program.body[0].leadingComments ||= [];
|
|
271
280
|
program.body[0].leadingComments.unshift(...comments);
|
|
272
281
|
}
|
|
273
|
-
|
|
282
|
+
const result = generate(file, {
|
|
274
283
|
comments: true,
|
|
275
284
|
sourceMaps: sourcemap,
|
|
276
285
|
sourceFileName: chunk.fileName
|
|
277
286
|
});
|
|
287
|
+
return {
|
|
288
|
+
code: result.code,
|
|
289
|
+
map: result.map
|
|
290
|
+
};
|
|
278
291
|
}
|
|
279
292
|
function getIdentifierIndex(name) {
|
|
280
293
|
if (name in identifierMap) return identifierMap[name]++;
|
|
281
294
|
return identifierMap[name] = 0;
|
|
282
295
|
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
return
|
|
296
|
+
function registerDeclaration(info) {
|
|
297
|
+
const declarationId = declarationIdx++;
|
|
298
|
+
declarationMap.set(declarationId, info);
|
|
299
|
+
return declarationId;
|
|
287
300
|
}
|
|
288
|
-
function
|
|
289
|
-
return
|
|
301
|
+
function getDeclaration(declarationId) {
|
|
302
|
+
return declarationMap.get(declarationId);
|
|
290
303
|
}
|
|
291
304
|
/**
|
|
292
305
|
* Collects all TSTypeParameter nodes from the given node and groups them by
|
|
@@ -297,7 +310,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
297
310
|
function collectParams(node) {
|
|
298
311
|
const typeParams = [];
|
|
299
312
|
walkAST(node, { leave(node$1) {
|
|
300
|
-
if ("typeParameters" in node$1 && node$1.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node$1.typeParameters.params);
|
|
313
|
+
if ("typeParameters" in node$1 && node$1.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node$1.typeParameters.params.map((param) => param.name));
|
|
301
314
|
} });
|
|
302
315
|
const paramMap = /* @__PURE__ */ new Map();
|
|
303
316
|
for (const typeParam of typeParams) {
|
|
@@ -311,7 +324,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
311
324
|
typeParams: typeParams$1
|
|
312
325
|
}));
|
|
313
326
|
}
|
|
314
|
-
function collectDependencies(node, namespaceStmts) {
|
|
327
|
+
function collectDependencies(node, namespaceStmts, children) {
|
|
315
328
|
const deps = /* @__PURE__ */ new Set();
|
|
316
329
|
const seen = /* @__PURE__ */ new Set();
|
|
317
330
|
const inferredStack = [];
|
|
@@ -334,10 +347,13 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
334
347
|
} else currentInferred = /* @__PURE__ */ new Set();
|
|
335
348
|
if (node$1.type === "ExportNamedDeclaration") {
|
|
336
349
|
for (const specifier of node$1.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
|
|
337
|
-
} else if (node$1.type === "TSInterfaceDeclaration" && node$1.extends) for (const heritage of node$1.extends || []) addDependency(
|
|
350
|
+
} else if (node$1.type === "TSInterfaceDeclaration" && node$1.extends) for (const heritage of node$1.extends || []) addDependency(heritage.expression);
|
|
338
351
|
else if (node$1.type === "ClassDeclaration") {
|
|
339
352
|
if (node$1.superClass) addDependency(node$1.superClass);
|
|
340
|
-
if (node$1.implements) for (const implement of node$1.implements)
|
|
353
|
+
if (node$1.implements) for (const implement of node$1.implements) {
|
|
354
|
+
if (implement.type === "ClassImplements") throw new Error("Unexpected Flow syntax");
|
|
355
|
+
addDependency(implement.expression);
|
|
356
|
+
}
|
|
341
357
|
} else if (isTypeOf(node$1, [
|
|
342
358
|
"ObjectMethod",
|
|
343
359
|
"ObjectProperty",
|
|
@@ -358,12 +374,12 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
358
374
|
break;
|
|
359
375
|
case "TSImportType": {
|
|
360
376
|
seen.add(node$1);
|
|
361
|
-
const source = node$1
|
|
362
|
-
|
|
363
|
-
addDependency(importNamespace(node$1, imported, source, namespaceStmts));
|
|
377
|
+
const { source, qualifier } = node$1;
|
|
378
|
+
addDependency(importNamespace(node$1, qualifier, source, namespaceStmts));
|
|
364
379
|
break;
|
|
365
380
|
}
|
|
366
381
|
}
|
|
382
|
+
if (parent && !deps.has(node$1) && isChildSymbol(node$1, parent)) children.add(node$1);
|
|
367
383
|
}
|
|
368
384
|
});
|
|
369
385
|
return Array.from(deps);
|
|
@@ -382,12 +398,13 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
382
398
|
});
|
|
383
399
|
if (imported) {
|
|
384
400
|
const importedLeft = getIdFromTSEntityName(imported);
|
|
401
|
+
if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
|
|
385
402
|
overwriteNode(importedLeft, t.tsQualifiedName(local, { ...importedLeft }));
|
|
386
403
|
local = imported;
|
|
387
404
|
}
|
|
388
405
|
let replacement = node;
|
|
389
|
-
if (node.
|
|
390
|
-
overwriteNode(node, t.tsTypeReference(local, node.
|
|
406
|
+
if (node.typeArguments) {
|
|
407
|
+
overwriteNode(node, t.tsTypeReference(local, node.typeArguments));
|
|
391
408
|
replacement = local;
|
|
392
409
|
} else overwriteNode(node, local);
|
|
393
410
|
return {
|
|
@@ -398,10 +415,15 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
398
415
|
};
|
|
399
416
|
}
|
|
400
417
|
}
|
|
418
|
+
function isChildSymbol(node, parent) {
|
|
419
|
+
if (node.type === "Identifier") return true;
|
|
420
|
+
if (isTypeOf(parent, ["TSPropertySignature", "TSMethodSignature"]) && parent.key === node) return true;
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
401
423
|
function collectInferredNames(node) {
|
|
402
424
|
const inferred = [];
|
|
403
425
|
walkAST(node, { enter(node$1) {
|
|
404
|
-
if (node$1.type === "TSInferType" && node$1.typeParameter) inferred.push(node$1.typeParameter.name);
|
|
426
|
+
if (node$1.type === "TSInferType" && node$1.typeParameter) inferred.push(node$1.typeParameter.name.name);
|
|
405
427
|
} });
|
|
406
428
|
return inferred;
|
|
407
429
|
}
|
|
@@ -413,34 +435,34 @@ function collectReferenceDirectives(comment, negative = false) {
|
|
|
413
435
|
* Check if the given node is a {@link RuntimeBindingVariableDeclration}
|
|
414
436
|
*/
|
|
415
437
|
function isRuntimeBindingVariableDeclaration(node) {
|
|
416
|
-
return
|
|
438
|
+
return node?.type === "VariableDeclaration" && node.declarations.length > 0 && node.declarations[0].type === "VariableDeclarator" && isRuntimeBindingArrayExpression(node.declarations[0].init);
|
|
417
439
|
}
|
|
418
440
|
/**
|
|
419
441
|
* Check if the given node is a {@link RuntimeBindingArrayExpression}
|
|
420
442
|
*/
|
|
421
443
|
function isRuntimeBindingArrayExpression(node) {
|
|
422
|
-
return
|
|
423
|
-
}
|
|
424
|
-
function runtimeBindingArrayExpression(elements) {
|
|
425
|
-
return t.arrayExpression(elements);
|
|
444
|
+
return node?.type === "ArrayExpression" && isRuntimeBindingArrayElements(node.elements);
|
|
426
445
|
}
|
|
427
446
|
/**
|
|
428
447
|
* Check if the given array is a {@link RuntimeBindingArrayElements}
|
|
429
448
|
*/
|
|
430
449
|
function isRuntimeBindingArrayElements(elements) {
|
|
431
|
-
const [
|
|
432
|
-
return
|
|
450
|
+
const [declarationId, deps, children, effect] = elements;
|
|
451
|
+
return declarationId?.type === "NumericLiteral" && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
|
|
452
|
+
}
|
|
453
|
+
function runtimeBindingArrayExpression(elements) {
|
|
454
|
+
return t.arrayExpression(elements);
|
|
433
455
|
}
|
|
434
456
|
function isThisExpression(node) {
|
|
435
|
-
return isIdentifierOf(node, "this") || node.type === "MemberExpression" && isThisExpression(node.object);
|
|
457
|
+
return isIdentifierOf(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
|
|
436
458
|
}
|
|
437
459
|
function TSEntityNameToRuntime(node) {
|
|
438
|
-
if (node.type === "Identifier") return node;
|
|
460
|
+
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
439
461
|
const left = TSEntityNameToRuntime(node.left);
|
|
440
462
|
return Object.assign(node, t.memberExpression(left, node.right));
|
|
441
463
|
}
|
|
442
464
|
function getIdFromTSEntityName(node) {
|
|
443
|
-
if (node.type === "Identifier") return node;
|
|
465
|
+
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
444
466
|
return getIdFromTSEntityName(node.left);
|
|
445
467
|
}
|
|
446
468
|
function isReferenceId(node) {
|
|
@@ -612,11 +634,21 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
|
612
634
|
child.on("close", () => resolve());
|
|
613
635
|
child.on("error", (error) => reject(error));
|
|
614
636
|
});
|
|
615
|
-
async function
|
|
616
|
-
debug$3("[tsgo] rootDir", rootDir);
|
|
637
|
+
async function getTsgoPathFromNodeModules() {
|
|
617
638
|
const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
|
|
618
639
|
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
|
|
619
|
-
|
|
640
|
+
return getExePath();
|
|
641
|
+
}
|
|
642
|
+
async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
|
|
643
|
+
debug$3("[tsgo] rootDir", rootDir);
|
|
644
|
+
let tsgo;
|
|
645
|
+
if (tsgoPath) {
|
|
646
|
+
tsgo = tsgoPath;
|
|
647
|
+
debug$3("[tsgo] using custom path", tsgo);
|
|
648
|
+
} else {
|
|
649
|
+
tsgo = await getTsgoPathFromNodeModules();
|
|
650
|
+
debug$3("[tsgo] using tsgo from node_modules", tsgo);
|
|
651
|
+
}
|
|
620
652
|
const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
621
653
|
debug$3("[tsgo] tsgoDist", tsgoDist);
|
|
622
654
|
const args = [
|
|
@@ -662,7 +694,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
662
694
|
return {
|
|
663
695
|
name: "rolldown-plugin-dts:generate",
|
|
664
696
|
async buildStart(options) {
|
|
665
|
-
if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig, sourcemap);
|
|
697
|
+
if (tsgo) tsgoDist = await runTsgo(rootDir, tsconfig, sourcemap, tsgo.path);
|
|
666
698
|
else if (!oxc) if (parallel) {
|
|
667
699
|
childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
|
|
668
700
|
rpc = (await import("birpc")).createBirpc({}, {
|
|
@@ -800,7 +832,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
|
|
|
800
832
|
dtsCode = result.code;
|
|
801
833
|
map = result.map;
|
|
802
834
|
if (dtsCode && RE_JSON.test(id)) if (dtsCode.includes("declare const _exports")) {
|
|
803
|
-
if (dtsCode.includes("declare const _exports: {")) {
|
|
835
|
+
if (dtsCode.includes("declare const _exports: {") && !dtsCode.includes("\n}[];")) {
|
|
804
836
|
const exports = collectJsonExports(dtsCode);
|
|
805
837
|
let i = 0;
|
|
806
838
|
dtsCode += exports.map((e) => {
|
|
@@ -876,6 +908,8 @@ function collectJsonExports(code) {
|
|
|
876
908
|
//#region src/options.ts
|
|
877
909
|
let warnedTsgo = false;
|
|
878
910
|
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
911
|
+
if (tsgo === true) tsgo = {};
|
|
912
|
+
else if (typeof tsgo === "object" && tsgo.enabled === false) tsgo = false;
|
|
879
913
|
let resolvedTsconfig;
|
|
880
914
|
if (tsconfig === true || tsconfig == null) {
|
|
881
915
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -1000,7 +1034,7 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolver, sideEffe
|
|
|
1000
1034
|
async function resolveDtsPath(id, importer, rolldownResolution) {
|
|
1001
1035
|
let dtsPath;
|
|
1002
1036
|
if (resolver === "tsc") {
|
|
1003
|
-
const { tscResolve } = await import("./resolver-
|
|
1037
|
+
const { tscResolve } = await import("./resolver-CQnlAxJ7.mjs");
|
|
1004
1038
|
dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
|
|
1005
1039
|
} else dtsPath = baseDtsResolver(id, importer);
|
|
1006
1040
|
debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
|
|
@@ -8,7 +8,10 @@ const debug = createDebug("rolldown-plugin-dts:tsc-resolver");
|
|
|
8
8
|
function tscResolve(id, importer, cwd, tsconfig, tsconfigRaw, reference) {
|
|
9
9
|
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
10
10
|
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, ts.sys, baseDir);
|
|
11
|
-
const resolved = ts.bundlerModuleNameResolver(id, importer,
|
|
11
|
+
const resolved = ts.bundlerModuleNameResolver(id, importer, {
|
|
12
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
13
|
+
...parsedConfig.options
|
|
14
|
+
}, ts.sys, void 0, reference);
|
|
12
15
|
debug(`tsc resolving id "%s" from "%s" -> %O`, id, importer, resolved.resolvedModule);
|
|
13
16
|
return resolved.resolvedModule?.resolvedFileName;
|
|
14
17
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.21.
|
|
4
|
+
"version": "0.21.4",
|
|
5
5
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -62,22 +62,22 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@babel/generator": "
|
|
66
|
-
"@babel/parser": "
|
|
67
|
-
"@babel/types": "
|
|
68
|
-
"ast-kit": "^
|
|
65
|
+
"@babel/generator": "8.0.0-beta.4",
|
|
66
|
+
"@babel/parser": "8.0.0-beta.4",
|
|
67
|
+
"@babel/types": "8.0.0-beta.4",
|
|
68
|
+
"ast-kit": "^3.0.0-beta.1",
|
|
69
69
|
"birpc": "^4.0.0",
|
|
70
70
|
"dts-resolver": "^2.1.3",
|
|
71
71
|
"get-tsconfig": "^4.13.0",
|
|
72
72
|
"obug": "^2.1.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
+
"@jridgewell/source-map": "^0.3.11",
|
|
75
76
|
"@sxzz/eslint-config": "^7.4.5",
|
|
76
77
|
"@sxzz/prettier-config": "^2.2.6",
|
|
77
78
|
"@sxzz/test-utils": "^0.5.15",
|
|
78
|
-
"@types/
|
|
79
|
-
"@
|
|
80
|
-
"@typescript/native-preview": "7.0.0-dev.20260115.1",
|
|
79
|
+
"@types/node": "^25.0.9",
|
|
80
|
+
"@typescript/native-preview": "7.0.0-dev.20260118.1",
|
|
81
81
|
"@volar/typescript": "^2.4.27",
|
|
82
82
|
"@vue/language-core": "^3.2.2",
|
|
83
83
|
"arktype": "^2.1.29",
|