rolldown-plugin-dts 0.13.13 → 0.14.0
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 +11 -0
- package/dist/index-B4kTNEjT.d.ts +28 -0
- package/dist/index.d.ts +18 -4
- package/dist/index.js +44 -22
- package/dist/tsc/worker.d.ts +1 -25
- package/dist/tsc/worker.js +1 -1
- package/dist/{tsc-AS4dxecO.js → tsc-DkRb5DrU.js} +66 -8
- package/dist/tsc-qM2loyiG.js +3 -0
- package/package.json +16 -16
- package/dist/tsc-CJ55BCXi.js +0 -3
package/README.md
CHANGED
|
@@ -148,6 +148,17 @@ This is especially useful when you have a single `tsconfig.json` for multiple pr
|
|
|
148
148
|
|
|
149
149
|
---
|
|
150
150
|
|
|
151
|
+
### newContext
|
|
152
|
+
|
|
153
|
+
If `true`, the plugin will create a new isolated context for each build,
|
|
154
|
+
ensuring that previously generated `.d.ts` code and caches are not reused.
|
|
155
|
+
|
|
156
|
+
By default, the plugin may reuse internal caches or incremental build artifacts
|
|
157
|
+
to speed up repeated builds. Enabling this option forces a clean context,
|
|
158
|
+
guaranteeing that all type definitions are generated from scratch.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
151
162
|
### tsgo
|
|
152
163
|
|
|
153
164
|
**[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TsConfigJson } from "get-tsconfig";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { SourceMapInput } from "rolldown";
|
|
4
|
+
|
|
5
|
+
//#region src/tsc/index.d.ts
|
|
6
|
+
interface TscContext {
|
|
7
|
+
programs: ts.Program[];
|
|
8
|
+
files: Map<string, string>;
|
|
9
|
+
}
|
|
10
|
+
interface TscOptions {
|
|
11
|
+
tsconfig?: string;
|
|
12
|
+
tsconfigRaw: TsConfigJson;
|
|
13
|
+
cwd: string;
|
|
14
|
+
incremental: boolean;
|
|
15
|
+
entries?: string[];
|
|
16
|
+
id: string;
|
|
17
|
+
vue?: boolean;
|
|
18
|
+
context?: TscContext;
|
|
19
|
+
}
|
|
20
|
+
declare function createContext(): TscContext;
|
|
21
|
+
interface TscResult {
|
|
22
|
+
code?: string;
|
|
23
|
+
map?: SourceMapInput;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { TscContext, createContext, tscEmit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-TbnZq0n4.js";
|
|
2
|
+
import { TscContext, createContext } from "./index-B4kTNEjT.js";
|
|
2
3
|
import { IsolatedDeclarationsOptions } from "rolldown/experimental";
|
|
3
4
|
import { TsConfigJson } from "get-tsconfig";
|
|
4
5
|
import { Plugin } from "rolldown";
|
|
@@ -111,6 +112,17 @@ interface Options {
|
|
|
111
112
|
* `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
|
|
112
113
|
*/
|
|
113
114
|
tsgo?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* If `true`, the plugin will create a new isolated context for each build,
|
|
117
|
+
* ensuring that previously generated `.d.ts` code and caches are not reused.
|
|
118
|
+
*
|
|
119
|
+
* By default, the plugin may reuse internal caches or incremental build artifacts
|
|
120
|
+
* to speed up repeated builds. Enabling this option forces a clean context,
|
|
121
|
+
* guaranteeing that all type definitions are generated from scratch.
|
|
122
|
+
*
|
|
123
|
+
* **Default:** `false`
|
|
124
|
+
*/
|
|
125
|
+
newContext?: boolean;
|
|
114
126
|
}
|
|
115
127
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
116
128
|
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
|
|
@@ -132,7 +144,8 @@ declare function resolveOptions({
|
|
|
132
144
|
vue,
|
|
133
145
|
parallel,
|
|
134
146
|
eager,
|
|
135
|
-
tsgo
|
|
147
|
+
tsgo,
|
|
148
|
+
newContext
|
|
136
149
|
}: Options): OptionsResolved;
|
|
137
150
|
//#endregion
|
|
138
151
|
//#region src/fake-js.d.ts
|
|
@@ -152,10 +165,11 @@ declare function createGeneratePlugin({
|
|
|
152
165
|
vue,
|
|
153
166
|
parallel,
|
|
154
167
|
eager,
|
|
155
|
-
tsgo
|
|
156
|
-
|
|
168
|
+
tsgo,
|
|
169
|
+
newContext
|
|
170
|
+
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext">): Plugin;
|
|
157
171
|
//#endregion
|
|
158
172
|
//#region src/index.d.ts
|
|
159
173
|
declare function dts(options?: Options): Plugin[];
|
|
160
174
|
//#endregion
|
|
161
|
-
export { Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
|
175
|
+
export { type Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, type TscContext, createContext, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts } from "./filename-Dpr2dKWZ.js";
|
|
2
|
+
import { createContext } from "./tsc-DkRb5DrU.js";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import Debug from "debug";
|
|
4
5
|
import _generate from "@babel/generator";
|
|
5
6
|
import { parse } from "@babel/parser";
|
|
6
7
|
import * as t from "@babel/types";
|
|
7
|
-
import { isDeclarationType, isTypeOf } from "ast-kit";
|
|
8
|
+
import { isDeclarationType, isTypeOf, resolveString } from "ast-kit";
|
|
8
9
|
import { fork, spawn } from "node:child_process";
|
|
9
10
|
import { existsSync } from "node:fs";
|
|
10
11
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
@@ -232,9 +233,10 @@ function walk(ast, { enter, leave }) {
|
|
|
232
233
|
const generate = _generate.default || _generate;
|
|
233
234
|
function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
234
235
|
let symbolIdx = 0;
|
|
235
|
-
|
|
236
|
+
const identifierMap = Object.create(null);
|
|
236
237
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
237
238
|
const commentsMap = /* @__PURE__ */ new Map();
|
|
239
|
+
const typeOnlyMap = /* @__PURE__ */ new Map();
|
|
238
240
|
return {
|
|
239
241
|
name: "rolldown-plugin-dts:fake-js",
|
|
240
242
|
outputOptions(options) {
|
|
@@ -268,6 +270,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
268
270
|
sourceType: "module"
|
|
269
271
|
});
|
|
270
272
|
const { program, comments } = file;
|
|
273
|
+
const typeOnlyIds = [];
|
|
271
274
|
if (comments) {
|
|
272
275
|
const directives = collectReferenceDirectives(comments);
|
|
273
276
|
commentsMap.set(id, directives);
|
|
@@ -276,7 +279,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
276
279
|
const namespaceStmts = /* @__PURE__ */ new Map();
|
|
277
280
|
for (const [i, stmt] of program.body.entries()) {
|
|
278
281
|
const setStmt = (node) => program.body[i] = node;
|
|
279
|
-
if (rewriteImportExport(stmt, setStmt)) continue;
|
|
282
|
+
if (rewriteImportExport(stmt, setStmt, typeOnlyIds)) continue;
|
|
280
283
|
const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
|
|
281
284
|
if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
|
|
282
285
|
const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
|
|
@@ -296,7 +299,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
296
299
|
if (decl.type === "VariableDeclaration") bindings.push(...decl.declarations.map((decl$1) => decl$1.id));
|
|
297
300
|
else if ("id" in decl && decl.id) {
|
|
298
301
|
let binding = decl.id;
|
|
299
|
-
binding = sideEffect ? t.identifier(`_${
|
|
302
|
+
binding = sideEffect ? t.identifier(`_${getIdentifierIndex("")}`) : binding;
|
|
300
303
|
bindings.push(binding);
|
|
301
304
|
} else {
|
|
302
305
|
const binding = t.identifier("export_default");
|
|
@@ -349,6 +352,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
349
352
|
...program.body,
|
|
350
353
|
...appendStmts
|
|
351
354
|
];
|
|
355
|
+
typeOnlyMap.set(id, typeOnlyIds);
|
|
352
356
|
const result = generate(file, {
|
|
353
357
|
comments: false,
|
|
354
358
|
sourceMaps: sourcemap,
|
|
@@ -358,12 +362,17 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
358
362
|
}
|
|
359
363
|
function renderChunk(code, chunk) {
|
|
360
364
|
if (!RE_DTS.test(chunk.fileName)) return;
|
|
365
|
+
const typeOnlyIds = [];
|
|
366
|
+
for (const module of chunk.moduleIds) {
|
|
367
|
+
const ids = typeOnlyMap.get(module);
|
|
368
|
+
if (ids) typeOnlyIds.push(...ids);
|
|
369
|
+
}
|
|
361
370
|
const file = parse(code, { sourceType: "module" });
|
|
362
371
|
const { program } = file;
|
|
363
372
|
program.body = patchTsNamespace(program.body);
|
|
364
373
|
program.body = program.body.map((node) => {
|
|
365
374
|
if (isHelperImport(node)) return null;
|
|
366
|
-
if (
|
|
375
|
+
if (patchImportExport(node, typeOnlyIds)) return node;
|
|
367
376
|
if (node.type !== "VariableDeclaration") return node;
|
|
368
377
|
const [decl] = node.declarations;
|
|
369
378
|
if (decl.init?.type !== "ArrayExpression" || !decl.init.elements[0]) return null;
|
|
@@ -412,8 +421,9 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
412
421
|
});
|
|
413
422
|
return result;
|
|
414
423
|
}
|
|
415
|
-
function getIdentifierIndex() {
|
|
416
|
-
return
|
|
424
|
+
function getIdentifierIndex(name) {
|
|
425
|
+
if (name in identifierMap) return identifierMap[name]++;
|
|
426
|
+
return identifierMap[name] = 0;
|
|
417
427
|
}
|
|
418
428
|
function registerSymbol(info) {
|
|
419
429
|
const symbolId = symbolIdx++;
|
|
@@ -462,7 +472,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
462
472
|
}
|
|
463
473
|
function importNamespace(node, imported, source, namespaceStmts) {
|
|
464
474
|
const sourceText = source.value.replaceAll(/\W/g, "_");
|
|
465
|
-
let local = t.identifier(`${sourceText}${getIdentifierIndex()}`);
|
|
475
|
+
let local = t.identifier(`${sourceText}${getIdentifierIndex(sourceText)}`);
|
|
466
476
|
if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
|
|
467
477
|
else namespaceStmts.set(source.value, {
|
|
468
478
|
stmt: t.importDeclaration([t.importNamespaceSpecifier(local)], source),
|
|
@@ -506,14 +516,21 @@ function isReferenceId(node) {
|
|
|
506
516
|
function isHelperImport(node) {
|
|
507
517
|
return node.type === "ImportDeclaration" && node.specifiers.length === 1 && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__export", "__reExport"].includes(spec.imported.name));
|
|
508
518
|
}
|
|
509
|
-
function
|
|
519
|
+
function patchImportExport(node, typeOnlyIds) {
|
|
510
520
|
if (isTypeOf(node, [
|
|
511
521
|
"ImportDeclaration",
|
|
512
522
|
"ExportAllDeclaration",
|
|
513
523
|
"ExportNamedDeclaration"
|
|
514
|
-
])
|
|
515
|
-
|
|
516
|
-
|
|
524
|
+
])) {
|
|
525
|
+
if (typeOnlyIds.length && node.type === "ExportNamedDeclaration") for (const spec of node.specifiers) {
|
|
526
|
+
const name = resolveString(spec.exported);
|
|
527
|
+
if (typeOnlyIds.includes(name)) if (spec.type === "ExportSpecifier") spec.exportKind = "type";
|
|
528
|
+
else node.exportKind = "type";
|
|
529
|
+
}
|
|
530
|
+
if (node.source?.value && RE_DTS.test(node.source.value)) {
|
|
531
|
+
node.source.value = filename_dts_to(node.source.value, "js");
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
517
534
|
}
|
|
518
535
|
}
|
|
519
536
|
function patchTsNamespace(nodes) {
|
|
@@ -552,10 +569,13 @@ function patchTsNamespace(nodes) {
|
|
|
552
569
|
}
|
|
553
570
|
return nodes.filter((node) => !removed.has(node));
|
|
554
571
|
}
|
|
555
|
-
function rewriteImportExport(node, set) {
|
|
572
|
+
function rewriteImportExport(node, set, typeOnlyIds) {
|
|
556
573
|
if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" && !node.declaration) {
|
|
557
|
-
for (const specifier of node.specifiers)
|
|
558
|
-
|
|
574
|
+
for (const specifier of node.specifiers) {
|
|
575
|
+
if ("exportKind" in specifier && specifier.exportKind === "type" || "exportKind" in node && node.exportKind === "type") typeOnlyIds.push(resolveString(specifier.exported));
|
|
576
|
+
if (specifier.type === "ImportSpecifier") specifier.importKind = "value";
|
|
577
|
+
else if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
|
|
578
|
+
}
|
|
559
579
|
if (node.type === "ImportDeclaration") node.importKind = "value";
|
|
560
580
|
else if (node.type === "ExportNamedDeclaration") node.exportKind = "value";
|
|
561
581
|
return true;
|
|
@@ -620,7 +640,7 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
|
620
640
|
child.on("close", () => resolve());
|
|
621
641
|
child.on("error", (error) => reject(error));
|
|
622
642
|
});
|
|
623
|
-
function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo }) {
|
|
643
|
+
function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo, newContext }) {
|
|
624
644
|
const dtsMap = /* @__PURE__ */ new Map();
|
|
625
645
|
/**
|
|
626
646
|
* A map of input id to output file name
|
|
@@ -649,8 +669,8 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
649
669
|
async buildStart(options) {
|
|
650
670
|
if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
|
|
651
671
|
else if (!parallel && (!isolatedDeclarations || vue)) {
|
|
652
|
-
tscModule = await import("./tsc-
|
|
653
|
-
tscContext =
|
|
672
|
+
tscModule = await import("./tsc-qM2loyiG.js");
|
|
673
|
+
if (newContext) tscContext = tscModule.createContext();
|
|
654
674
|
}
|
|
655
675
|
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
656
676
|
debug$1("resolving input alias %s -> %s", name, id);
|
|
@@ -773,7 +793,8 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
|
|
|
773
793
|
recursive: true,
|
|
774
794
|
force: true
|
|
775
795
|
}).catch(() => {});
|
|
776
|
-
|
|
796
|
+
tsgoDist = void 0;
|
|
797
|
+
if (newContext) tscContext = void 0;
|
|
777
798
|
}
|
|
778
799
|
};
|
|
779
800
|
}
|
|
@@ -801,7 +822,7 @@ async function runTsgo(root, tsconfig) {
|
|
|
801
822
|
//#endregion
|
|
802
823
|
//#region src/options.ts
|
|
803
824
|
let warnedTsgo = false;
|
|
804
|
-
function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false }) {
|
|
825
|
+
function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false, newContext = false }) {
|
|
805
826
|
let resolvedTsconfig;
|
|
806
827
|
if (tsconfig === true || tsconfig == null) {
|
|
807
828
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -846,7 +867,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
|
|
|
846
867
|
vue,
|
|
847
868
|
parallel,
|
|
848
869
|
eager,
|
|
849
|
-
tsgo
|
|
870
|
+
tsgo,
|
|
871
|
+
newContext
|
|
850
872
|
};
|
|
851
873
|
}
|
|
852
874
|
|
|
@@ -912,4 +934,4 @@ function dts(options = {}) {
|
|
|
912
934
|
}
|
|
913
935
|
|
|
914
936
|
//#endregion
|
|
915
|
-
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
|
937
|
+
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createContext, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
package/dist/tsc/worker.d.ts
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { SourceMapInput } from "rolldown";
|
|
1
|
+
import { tscEmit } from "../index-B4kTNEjT.js";
|
|
4
2
|
|
|
5
|
-
//#region src/tsc/index.d.ts
|
|
6
|
-
interface TscContext {
|
|
7
|
-
programs: ts.Program[];
|
|
8
|
-
files: Map<string, string>;
|
|
9
|
-
}
|
|
10
|
-
interface TscOptions {
|
|
11
|
-
tsconfig?: string;
|
|
12
|
-
tsconfigRaw: TsConfigJson;
|
|
13
|
-
cwd: string;
|
|
14
|
-
incremental: boolean;
|
|
15
|
-
entries?: string[];
|
|
16
|
-
id: string;
|
|
17
|
-
vue?: boolean;
|
|
18
|
-
context?: TscContext;
|
|
19
|
-
}
|
|
20
|
-
interface TscResult {
|
|
21
|
-
code?: string;
|
|
22
|
-
map?: SourceMapInput;
|
|
23
|
-
error?: string;
|
|
24
|
-
}
|
|
25
|
-
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
26
|
-
//#endregion
|
|
27
3
|
//#region src/tsc/worker.d.ts
|
|
28
4
|
declare const functions: {
|
|
29
5
|
tscEmit: typeof tscEmit;
|
package/dist/tsc/worker.js
CHANGED
|
@@ -77,8 +77,11 @@ function createVueProgramFactory(ts$1) {
|
|
|
77
77
|
debug$1("loading vue language tools");
|
|
78
78
|
const { proxyCreateProgram, vue } = loadVueLanguageTools();
|
|
79
79
|
return createVueProgram = proxyCreateProgram(ts$1, ts$1.createProgram, (ts$2, options) => {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
80
|
+
const $rootDir = options.options.$rootDir;
|
|
81
|
+
const $configRaw = options.options.$configRaw;
|
|
82
|
+
const resolver = new vue.CompilerOptionsResolver();
|
|
83
|
+
resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
|
|
84
|
+
const vueOptions = resolver.build();
|
|
82
85
|
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts$2, options.options, vueOptions, (id) => id);
|
|
83
86
|
return { languagePlugins: [vueLanguagePlugin] };
|
|
84
87
|
});
|
|
@@ -151,18 +154,73 @@ function buildSolution(tsconfig, incremental, context) {
|
|
|
151
154
|
force: !incremental,
|
|
152
155
|
verbose: true
|
|
153
156
|
});
|
|
154
|
-
const
|
|
157
|
+
const projects = [];
|
|
158
|
+
const getCustomTransformers = (project) => {
|
|
159
|
+
projects.push(project);
|
|
160
|
+
return {};
|
|
161
|
+
};
|
|
162
|
+
const exitStatus = builder.build(void 0, void 0, void 0, getCustomTransformers);
|
|
155
163
|
debug(`built solution for ${tsconfig} with exit status ${exitStatus}`);
|
|
164
|
+
return Array.from(new Set(projects));
|
|
165
|
+
}
|
|
166
|
+
function findProjectContainingFile(projects, targetFile, fsSystem) {
|
|
167
|
+
const resolvedTargetFile = fsSystem.resolvePath(targetFile);
|
|
168
|
+
for (const tsconfigPath of projects) {
|
|
169
|
+
const parsedConfig = parseTsconfig(tsconfigPath, fsSystem);
|
|
170
|
+
if (parsedConfig && parsedConfig.fileNames.some((fileName) => fsSystem.resolvePath(fileName) === resolvedTargetFile)) return {
|
|
171
|
+
parsedConfig,
|
|
172
|
+
tsconfigPath
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function parseTsconfig(tsconfigPath, fsSystem) {
|
|
177
|
+
const diagnostics = [];
|
|
178
|
+
const parsedConfig = ts.getParsedCommandLineOfConfigFile(tsconfigPath, void 0, {
|
|
179
|
+
...fsSystem,
|
|
180
|
+
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
181
|
+
diagnostics.push(diagnostic);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
if (diagnostics.length) throw new Error(`[rolldown-plugin-dts] Unable to read ${tsconfigPath}: ${ts.formatDiagnostics(diagnostics, formatHost)}`);
|
|
185
|
+
return parsedConfig;
|
|
156
186
|
}
|
|
157
187
|
function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd, context = globalContext }) {
|
|
158
188
|
const fsSystem = createFsSystem(context.files);
|
|
159
|
-
const
|
|
160
|
-
|
|
189
|
+
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
190
|
+
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, baseDir);
|
|
191
|
+
if (tsconfig && parsedConfig.projectReferences?.length) {
|
|
192
|
+
const projectPaths = buildSolution(tsconfig, incremental, context);
|
|
193
|
+
debug(`collected projects: ${JSON.stringify(projectPaths)}`);
|
|
194
|
+
const project = findProjectContainingFile(projectPaths, id, fsSystem);
|
|
195
|
+
if (project) {
|
|
196
|
+
debug(`Creating program for project: ${project.tsconfigPath}`);
|
|
197
|
+
return createTsProgramFromParsedConfig({
|
|
198
|
+
parsedConfig: project.parsedConfig,
|
|
199
|
+
fsSystem,
|
|
200
|
+
baseDir: path.dirname(project.tsconfigPath),
|
|
201
|
+
id,
|
|
202
|
+
entries,
|
|
203
|
+
vue
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return createTsProgramFromParsedConfig({
|
|
208
|
+
parsedConfig,
|
|
209
|
+
fsSystem,
|
|
210
|
+
baseDir,
|
|
211
|
+
id,
|
|
212
|
+
entries,
|
|
213
|
+
vue
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id, entries, vue }) {
|
|
161
217
|
const compilerOptions = {
|
|
162
218
|
...defaultCompilerOptions,
|
|
163
|
-
...
|
|
219
|
+
...parsedConfig.options,
|
|
220
|
+
$configRaw: parsedConfig.raw,
|
|
221
|
+
$rootDir: baseDir
|
|
164
222
|
};
|
|
165
|
-
const rootNames = [...new Set([id, ...entries ||
|
|
223
|
+
const rootNames = [...new Set([id, ...entries || parsedConfig.fileNames].map((f) => fsSystem.resolvePath(f)))];
|
|
166
224
|
const host = ts.createCompilerHost(compilerOptions, true);
|
|
167
225
|
host.readFile = fsSystem.readFile;
|
|
168
226
|
host.fileExists = fsSystem.fileExists;
|
|
@@ -172,7 +230,7 @@ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue,
|
|
|
172
230
|
rootNames,
|
|
173
231
|
options: compilerOptions,
|
|
174
232
|
host,
|
|
175
|
-
projectReferences:
|
|
233
|
+
projectReferences: parsedConfig.projectReferences
|
|
176
234
|
});
|
|
177
235
|
const sourceFile = program.getSourceFile(id);
|
|
178
236
|
if (!sourceFile) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A Rolldown plugin to bundle dts files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@typescript/native-preview": ">=7.0.0-dev.20250601.1",
|
|
33
33
|
"rolldown": "^1.0.0-beta.9",
|
|
34
34
|
"typescript": "^5.0.0",
|
|
35
|
-
"vue-tsc": "
|
|
35
|
+
"vue-tsc": "^2.2.0 || ^3.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@typescript/native-preview": {
|
|
@@ -46,31 +46,31 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@babel/generator": "^7.
|
|
50
|
-
"@babel/parser": "^7.
|
|
51
|
-
"@babel/types": "^7.
|
|
52
|
-
"ast-kit": "^2.1.
|
|
53
|
-
"birpc": "^2.
|
|
49
|
+
"@babel/generator": "^7.28.0",
|
|
50
|
+
"@babel/parser": "^7.28.0",
|
|
51
|
+
"@babel/types": "^7.28.1",
|
|
52
|
+
"ast-kit": "^2.1.1",
|
|
53
|
+
"birpc": "^2.5.0",
|
|
54
54
|
"debug": "^4.4.1",
|
|
55
55
|
"dts-resolver": "^2.1.1",
|
|
56
56
|
"get-tsconfig": "^4.10.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@sxzz/eslint-config": "^7.0.
|
|
59
|
+
"@sxzz/eslint-config": "^7.0.6",
|
|
60
60
|
"@sxzz/prettier-config": "^2.2.3",
|
|
61
|
-
"@sxzz/test-utils": "^0.5.
|
|
61
|
+
"@sxzz/test-utils": "^0.5.7",
|
|
62
62
|
"@types/babel__generator": "^7.27.0",
|
|
63
63
|
"@types/debug": "^4.1.12",
|
|
64
|
-
"@types/node": "^24.0.
|
|
65
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
66
|
-
"@volar/typescript": "^2.4.
|
|
67
|
-
"@vue/language-core": "^
|
|
64
|
+
"@types/node": "^24.0.14",
|
|
65
|
+
"@typescript/native-preview": "7.0.0-dev.20250718.1",
|
|
66
|
+
"@volar/typescript": "^2.4.20",
|
|
67
|
+
"@vue/language-core": "^3.0.3",
|
|
68
68
|
"bumpp": "^10.2.0",
|
|
69
69
|
"diff": "^8.0.2",
|
|
70
|
-
"eslint": "^9.
|
|
70
|
+
"eslint": "^9.31.0",
|
|
71
71
|
"estree-walker": "^3.0.3",
|
|
72
72
|
"prettier": "^3.6.2",
|
|
73
|
-
"rolldown": "^1.0.0-beta.
|
|
73
|
+
"rolldown": "^1.0.0-beta.28",
|
|
74
74
|
"rollup-plugin-dts": "^6.2.1",
|
|
75
75
|
"tinyglobby": "^0.2.14",
|
|
76
76
|
"tsdown": "^0.12.9",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"typescript": "^5.8.3",
|
|
79
79
|
"vitest": "^3.2.4",
|
|
80
80
|
"vue": "^3.5.17",
|
|
81
|
-
"vue-tsc": "^
|
|
81
|
+
"vue-tsc": "^3.0.3"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=20.18.0"
|
package/dist/tsc-CJ55BCXi.js
DELETED