rolldown-plugin-dts 0.21.9 → 0.22.1
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/{tsc-CJtlSu--.mjs → emit-compiler-CfQ29zff.mjs} +33 -43
- package/dist/filename.mjs +29 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +16 -13
- package/dist/tsc-context.d.mts +17 -1
- package/dist/tsc-context.mjs +23 -1
- package/dist/tsc-worker.d.mts +1 -1
- package/dist/tsc-worker.mjs +1 -1
- package/dist/tsc.d.mts +6 -2
- package/dist/tsc.mjs +14 -1
- package/dist/{index-DWPGYc3m.d.mts → types-D8g6CB60.d.mts} +3 -6
- package/package.json +6 -5
- package/dist/context-DoVwxr5H.mjs +0 -25
- package/dist/context-Dt8gPoCq.d.mts +0 -18
- package/dist/filename-DQSb77Ln.mjs +0 -28
- /package/dist/{resolver-o20sdYK5.mjs → resolver-j7HY1N36.mjs} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { RE_DTS, RE_DTS_MAP } from "./filename.mjs";
|
|
3
|
+
import { globalContext } from "./tsc-context.mjs";
|
|
4
4
|
const {
|
|
5
5
|
createRequire
|
|
6
6
|
} = globalThis.process.getBuiltinModule("node:module");
|
|
@@ -16,7 +16,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/tsc/system.ts
|
|
19
|
-
const debug$
|
|
19
|
+
const debug$3 = createDebug("rolldown-plugin-dts:tsc-system");
|
|
20
20
|
/**
|
|
21
21
|
* A system that writes files to both memory and disk. It will try read files
|
|
22
22
|
* from memory firstly and fallback to disk if not found.
|
|
@@ -25,7 +25,7 @@ function createFsSystem(files) {
|
|
|
25
25
|
return {
|
|
26
26
|
...ts.sys,
|
|
27
27
|
write(message) {
|
|
28
|
-
debug$
|
|
28
|
+
debug$3(message);
|
|
29
29
|
},
|
|
30
30
|
resolvePath(path) {
|
|
31
31
|
if (files.has(path)) return path;
|
|
@@ -90,20 +90,20 @@ function setSourceMapRoot(map, originalFilePath, finalFilePath) {
|
|
|
90
90
|
|
|
91
91
|
//#endregion
|
|
92
92
|
//#region src/tsc/emit-build.ts
|
|
93
|
-
const debug$
|
|
93
|
+
const debug$2 = createDebug("rolldown-plugin-dts:tsc-build");
|
|
94
94
|
function tscEmitBuild(tscOptions) {
|
|
95
95
|
const { id, tsconfig, incremental, context = globalContext, sourcemap } = tscOptions;
|
|
96
|
-
debug$
|
|
96
|
+
debug$2(`running tscEmitBuild id: ${id}, tsconfig: ${tsconfig}, incremental: ${incremental}`);
|
|
97
97
|
if (!tsconfig) return { error: "[rolldown-plugin-dts] build mode requires a tsconfig path" };
|
|
98
98
|
const fsSystem = (incremental ? createFsSystem : createMemorySystem)(context.files);
|
|
99
99
|
const resolvedId = fsSystem.resolvePath(id);
|
|
100
|
-
if (resolvedId !== id) debug$
|
|
100
|
+
if (resolvedId !== id) debug$2(`resolved id from ${id} to ${resolvedId}`);
|
|
101
101
|
const project = getOrBuildProjects(context, fsSystem, tsconfig, !incremental, sourcemap).get(resolvedId);
|
|
102
102
|
if (!project) {
|
|
103
|
-
debug$
|
|
103
|
+
debug$2(`unable to locate a project containing ${resolvedId}`);
|
|
104
104
|
return { error: `Unable to locate ${id} from the given tsconfig file ${tsconfig}` };
|
|
105
105
|
}
|
|
106
|
-
debug$
|
|
106
|
+
debug$2(`loaded project ${project.tsconfigPath} for ${id}`);
|
|
107
107
|
const ignoreCase = !fsSystem.useCaseSensitiveFileNames;
|
|
108
108
|
const outputFiles = ts.getOutputFileNames(project.parsedConfig, resolvedId, ignoreCase);
|
|
109
109
|
let code;
|
|
@@ -133,20 +133,20 @@ function tscEmitBuild(tscOptions) {
|
|
|
133
133
|
map
|
|
134
134
|
};
|
|
135
135
|
if (incremental) {
|
|
136
|
-
debug$
|
|
136
|
+
debug$2(`incremental build failed`);
|
|
137
137
|
return tscEmitBuild({
|
|
138
138
|
...tscOptions,
|
|
139
139
|
incremental: false
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
debug$
|
|
142
|
+
debug$2(`unable to build .d.ts file for ${id}`);
|
|
143
143
|
if (project.parsedConfig.options.declaration !== true) return { error: `Unable to build .d.ts file for ${id}; Make sure the "declaration" option is set to true in ${project.tsconfigPath}` };
|
|
144
144
|
return { error: `Unable to build .d.ts file for ${id}; This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues` };
|
|
145
145
|
}
|
|
146
146
|
function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
|
|
147
147
|
let projectMap = context.projects.get(tsconfig);
|
|
148
148
|
if (projectMap) {
|
|
149
|
-
debug$
|
|
149
|
+
debug$2(`skip building projects for ${tsconfig}`);
|
|
150
150
|
return projectMap;
|
|
151
151
|
}
|
|
152
152
|
projectMap = buildProjects(fsSystem, tsconfig, force, sourcemap);
|
|
@@ -157,15 +157,15 @@ function getOrBuildProjects(context, fsSystem, tsconfig, force, sourcemap) {
|
|
|
157
157
|
* Use TypeScript compiler to build all projects referenced
|
|
158
158
|
*/
|
|
159
159
|
function buildProjects(fsSystem, tsconfig, force, sourcemap) {
|
|
160
|
-
debug$
|
|
160
|
+
debug$2(`start building projects for ${tsconfig}`);
|
|
161
161
|
const projects = collectProjectGraph(tsconfig, fsSystem, force, sourcemap);
|
|
162
|
-
debug$
|
|
162
|
+
debug$2("collected %d projects: %j", projects.length, projects.map((project) => project.tsconfigPath));
|
|
163
163
|
const host = ts.createSolutionBuilderHost(fsSystem, createProgramWithPatchedCompilerOptions);
|
|
164
|
-
debug$
|
|
164
|
+
debug$2(`built solution for ${tsconfig} with exit status ${ts.createSolutionBuilder(host, [tsconfig], {
|
|
165
165
|
force,
|
|
166
166
|
verbose: true
|
|
167
167
|
}).build(void 0, void 0, void 0, (project) => {
|
|
168
|
-
debug$
|
|
168
|
+
debug$2(`transforming project ${project}`);
|
|
169
169
|
return customTransformers;
|
|
170
170
|
})}`);
|
|
171
171
|
const sourceFileToProjectMap = /* @__PURE__ */ new Map();
|
|
@@ -244,9 +244,9 @@ const createProgramWithPatchedCompilerOptions = (rootNames, options, ...args) =>
|
|
|
244
244
|
|
|
245
245
|
//#endregion
|
|
246
246
|
//#region src/tsc/volar.ts
|
|
247
|
-
const debug$
|
|
247
|
+
const debug$1 = createDebug("rolldown-plugin-dts:volar");
|
|
248
248
|
function loadVueLanguageTools() {
|
|
249
|
-
debug$
|
|
249
|
+
debug$1("loading vue language tools");
|
|
250
250
|
try {
|
|
251
251
|
const vueTscPath = __require.resolve("vue-tsc");
|
|
252
252
|
return {
|
|
@@ -254,7 +254,7 @@ function loadVueLanguageTools() {
|
|
|
254
254
|
vue: __require(__require.resolve("@vue/language-core", { paths: [vueTscPath] }))
|
|
255
255
|
};
|
|
256
256
|
} catch (error) {
|
|
257
|
-
debug$
|
|
257
|
+
debug$1("vue language tools not found", error);
|
|
258
258
|
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.");
|
|
259
259
|
}
|
|
260
260
|
}
|
|
@@ -309,7 +309,7 @@ function createProgramFactory(ts, options) {
|
|
|
309
309
|
|
|
310
310
|
//#endregion
|
|
311
311
|
//#region src/tsc/emit-compiler.ts
|
|
312
|
-
const debug
|
|
312
|
+
const debug = createDebug("rolldown-plugin-dts:tsc-compiler");
|
|
313
313
|
const defaultCompilerOptions = {
|
|
314
314
|
declaration: true,
|
|
315
315
|
noEmit: false,
|
|
@@ -336,9 +336,9 @@ function createOrGetTsModule(options) {
|
|
|
336
336
|
file: sourceFile
|
|
337
337
|
};
|
|
338
338
|
}
|
|
339
|
-
debug
|
|
339
|
+
debug(`create program for module: ${id}`);
|
|
340
340
|
const module = createTsProgram(options);
|
|
341
|
-
debug
|
|
341
|
+
debug(`created program for module: ${id}`);
|
|
342
342
|
context.programs.push(module.program);
|
|
343
343
|
return module;
|
|
344
344
|
}
|
|
@@ -350,7 +350,7 @@ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, vue, tsMacro, cwd
|
|
|
350
350
|
isMixedContent: true,
|
|
351
351
|
scriptKind: ts.ScriptKind.Deferred
|
|
352
352
|
}] : void 0);
|
|
353
|
-
debug
|
|
353
|
+
debug(`creating program for root project: ${baseDir}`);
|
|
354
354
|
return createTsProgramFromParsedConfig({
|
|
355
355
|
parsedConfig,
|
|
356
356
|
fsSystem,
|
|
@@ -381,13 +381,13 @@ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id,
|
|
|
381
381
|
});
|
|
382
382
|
const sourceFile = program.getSourceFile(id);
|
|
383
383
|
if (!sourceFile) {
|
|
384
|
-
debug
|
|
384
|
+
debug(`source file not found in program: ${id}`);
|
|
385
385
|
if (!!parsedConfig.projectReferences?.length) throw new Error(`[rolldown-plugin-dts] Unable to load ${id}; You have "references" in your tsconfig file. Perhaps you want to add \`dts: { build: true }\` in your config?`);
|
|
386
386
|
if (fsSystem.fileExists(id)) {
|
|
387
|
-
debug
|
|
387
|
+
debug(`File ${id} exists on disk.`);
|
|
388
388
|
throw new Error(`Unable to load file ${id} from the program. This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues`);
|
|
389
389
|
} else {
|
|
390
|
-
debug
|
|
390
|
+
debug(`File ${id} does not exist on disk.`);
|
|
391
391
|
throw new Error(`Source file not found: ${id}`);
|
|
392
392
|
}
|
|
393
393
|
}
|
|
@@ -397,26 +397,26 @@ function createTsProgramFromParsedConfig({ parsedConfig, fsSystem, baseDir, id,
|
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
399
|
function tscEmitCompiler(tscOptions) {
|
|
400
|
-
debug
|
|
400
|
+
debug(`running tscEmitCompiler ${tscOptions.id}`);
|
|
401
401
|
const { program, file } = createOrGetTsModule(tscOptions);
|
|
402
|
-
debug
|
|
402
|
+
debug(`got source file: ${file.fileName}`);
|
|
403
403
|
let dtsCode;
|
|
404
404
|
let map;
|
|
405
405
|
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
406
406
|
if (fileName.endsWith(".map")) {
|
|
407
|
-
debug
|
|
407
|
+
debug(`emit dts sourcemap: ${fileName}`);
|
|
408
408
|
map = JSON.parse(code);
|
|
409
409
|
setSourceMapRoot(map, fileName, tscOptions.id);
|
|
410
410
|
} else {
|
|
411
|
-
debug
|
|
411
|
+
debug(`emit dts: ${fileName}`);
|
|
412
412
|
dtsCode = code;
|
|
413
413
|
}
|
|
414
414
|
}, void 0, true, customTransformers, true);
|
|
415
415
|
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
416
416
|
if (!dtsCode) {
|
|
417
|
-
debug
|
|
417
|
+
debug("nothing was emitted.");
|
|
418
418
|
if (file.isDeclarationFile) {
|
|
419
|
-
debug
|
|
419
|
+
debug("source file is a declaration file.");
|
|
420
420
|
dtsCode = file.getFullText();
|
|
421
421
|
} else console.warn("[rolldown-plugin-dts] Warning: Failed to emit declaration file. Please try to enable `eager` option (`dts.eager` for tsdown).");
|
|
422
422
|
}
|
|
@@ -427,14 +427,4 @@ function tscEmitCompiler(tscOptions) {
|
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
//#endregion
|
|
430
|
-
|
|
431
|
-
const debug = createDebug("rolldown-plugin-dts:tsc");
|
|
432
|
-
debug(`loaded typescript: ${ts.version}`);
|
|
433
|
-
function tscEmit(tscOptions) {
|
|
434
|
-
debug(`running tscEmit ${tscOptions.id}`);
|
|
435
|
-
if (tscOptions.build) return tscEmitBuild(tscOptions);
|
|
436
|
-
else return tscEmitCompiler(tscOptions);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
//#endregion
|
|
440
|
-
export { tscEmit as t };
|
|
430
|
+
export { tscEmitBuild as n, tscEmitCompiler as t };
|
package/dist/filename.mjs
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RUNTIME_MODULE_ID } from "rolldown";
|
|
2
|
+
import { exactRegex } from "rolldown/filter";
|
|
2
3
|
|
|
4
|
+
//#region src/filename.ts
|
|
5
|
+
const RE_JS = /\.([cm]?)jsx?$/;
|
|
6
|
+
const RE_TS = /\.([cm]?)tsx?$/;
|
|
7
|
+
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
8
|
+
const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
|
|
9
|
+
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
10
|
+
const RE_CSS = /\.css$/;
|
|
11
|
+
const RE_VUE = /\.vue$/;
|
|
12
|
+
const RE_JSON = /\.json$/;
|
|
13
|
+
const RE_ROLLDOWN_RUNTIME = exactRegex(RUNTIME_MODULE_ID);
|
|
14
|
+
function filename_js_to_dts(id) {
|
|
15
|
+
return id.replace(RE_JS, ".d.$1ts");
|
|
16
|
+
}
|
|
17
|
+
function filename_to_dts(id) {
|
|
18
|
+
return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".json.d.ts");
|
|
19
|
+
}
|
|
20
|
+
function filename_dts_to(id, ext) {
|
|
21
|
+
return id.replace(RE_DTS, `.$1${ext}`);
|
|
22
|
+
}
|
|
23
|
+
function resolveTemplateFn(fn, chunk) {
|
|
24
|
+
return typeof fn === "function" ? fn(chunk) : fn;
|
|
25
|
+
}
|
|
26
|
+
function replaceTemplateName(template, name) {
|
|
27
|
+
return template.replaceAll("[name]", name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
3
31
|
export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_JSON, RE_NODE_MODULES, RE_ROLLDOWN_RUNTIME, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_to_dts, replaceTemplateName, resolveTemplateFn };
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_JSON, RE_NODE_MODULES, RE_ROLLDOWN_RUNTIME, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_to_dts, replaceTemplateName, resolveTemplateFn } from "./filename.mjs";
|
|
2
|
+
import { createContext, globalContext, invalidateContextFile } from "./tsc-context.mjs";
|
|
3
3
|
import { createDebug } from "obug";
|
|
4
|
+
import { importerId, include } from "rolldown/filter";
|
|
4
5
|
import { generate } from "@babel/generator";
|
|
6
|
+
import { isIdentifierName } from "@babel/helper-validator-identifier";
|
|
5
7
|
import { parse } from "@babel/parser";
|
|
6
8
|
import * as t from "@babel/types";
|
|
7
9
|
import { isDeclarationType, isIdentifierOf, isTypeOf, resolveString, walkAST } from "ast-kit";
|
|
@@ -25,7 +27,6 @@ const {
|
|
|
25
27
|
const process = globalThis.process;
|
|
26
28
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
27
29
|
import { createResolver } from "dts-resolver";
|
|
28
|
-
import { importerId, include } from "rolldown/filter";
|
|
29
30
|
|
|
30
31
|
//#region src/dts-input.ts
|
|
31
32
|
function createDtsInputPlugin({ sideEffects }) {
|
|
@@ -65,7 +66,6 @@ function createDtsInputPlugin({ sideEffects }) {
|
|
|
65
66
|
//#region src/fake-js.ts
|
|
66
67
|
function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
67
68
|
let declarationIdx = 0;
|
|
68
|
-
const identifierMap = Object.create(null);
|
|
69
69
|
const declarationMap = /* @__PURE__ */ new Map();
|
|
70
70
|
const commentsMap = /* @__PURE__ */ new Map();
|
|
71
71
|
const typeOnlyMap = /* @__PURE__ */ new Map();
|
|
@@ -115,6 +115,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
115
115
|
});
|
|
116
116
|
const { program, comments } = file;
|
|
117
117
|
const typeOnlyIds = [];
|
|
118
|
+
const identifierMap = Object.create(null);
|
|
118
119
|
if (comments) {
|
|
119
120
|
const directives = collectReferenceDirectives(comments);
|
|
120
121
|
commentsMap.set(id, directives);
|
|
@@ -145,7 +146,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
145
146
|
else if ("id" in decl && decl.id) {
|
|
146
147
|
let binding = decl.id;
|
|
147
148
|
if (binding.type === "TSQualifiedName") binding = getIdFromTSEntityName(binding);
|
|
148
|
-
binding = sideEffect ? t.identifier(`_${getIdentifierIndex("")}`) : binding;
|
|
149
|
+
binding = sideEffect ? t.identifier(`_${getIdentifierIndex(identifierMap, "")}`) : binding;
|
|
149
150
|
if (binding.type !== "Identifier") throw new Error(`Unexpected ${binding.type} declaration id`);
|
|
150
151
|
bindings.push(binding);
|
|
151
152
|
} else {
|
|
@@ -155,7 +156,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
155
156
|
}
|
|
156
157
|
const params = collectParams(decl);
|
|
157
158
|
const childrenSet = /* @__PURE__ */ new Set();
|
|
158
|
-
const deps = collectDependencies(decl, namespaceStmts, childrenSet);
|
|
159
|
+
const deps = collectDependencies(decl, namespaceStmts, childrenSet, identifierMap);
|
|
159
160
|
const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
|
|
160
161
|
if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
|
|
161
162
|
const declarationId = registerDeclaration({
|
|
@@ -301,8 +302,8 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
301
302
|
map: result.map
|
|
302
303
|
};
|
|
303
304
|
}
|
|
304
|
-
function getIdentifierIndex(name) {
|
|
305
|
-
if (name in identifierMap) return identifierMap[name]
|
|
305
|
+
function getIdentifierIndex(identifierMap, name) {
|
|
306
|
+
if (name in identifierMap) return ++identifierMap[name];
|
|
306
307
|
return identifierMap[name] = 0;
|
|
307
308
|
}
|
|
308
309
|
function registerDeclaration(info) {
|
|
@@ -336,7 +337,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
336
337
|
typeParams
|
|
337
338
|
}));
|
|
338
339
|
}
|
|
339
|
-
function collectDependencies(node, namespaceStmts, children) {
|
|
340
|
+
function collectDependencies(node, namespaceStmts, children, identifierMap) {
|
|
340
341
|
const deps = /* @__PURE__ */ new Set();
|
|
341
342
|
const seen = /* @__PURE__ */ new Set();
|
|
342
343
|
const inferredStack = [];
|
|
@@ -387,7 +388,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
387
388
|
case "TSImportType": {
|
|
388
389
|
seen.add(node);
|
|
389
390
|
const { source, qualifier } = node;
|
|
390
|
-
addDependency(importNamespace(node, qualifier, source, namespaceStmts));
|
|
391
|
+
addDependency(importNamespace(node, qualifier, source, namespaceStmts, identifierMap));
|
|
391
392
|
break;
|
|
392
393
|
}
|
|
393
394
|
}
|
|
@@ -400,9 +401,10 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
400
401
|
deps.add(node);
|
|
401
402
|
}
|
|
402
403
|
}
|
|
403
|
-
function importNamespace(node, imported, source, namespaceStmts) {
|
|
404
|
+
function importNamespace(node, imported, source, namespaceStmts, identifierMap) {
|
|
404
405
|
const sourceText = source.value.replaceAll(/\W/g, "_");
|
|
405
|
-
|
|
406
|
+
const localName = isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`;
|
|
407
|
+
let local = t.identifier(localName);
|
|
406
408
|
if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
|
|
407
409
|
else namespaceStmts.set(source.value, {
|
|
408
410
|
stmt: t.importDeclaration([t.importNamespaceSpecifier(local)], source),
|
|
@@ -517,6 +519,7 @@ function patchTsNamespace(nodes) {
|
|
|
517
519
|
const result = handleExport(node);
|
|
518
520
|
if (!result) continue;
|
|
519
521
|
const [binding, exports] = result;
|
|
522
|
+
if (!exports.properties.length) continue;
|
|
520
523
|
nodes[i] = {
|
|
521
524
|
type: "TSModuleDeclaration",
|
|
522
525
|
id: binding,
|
|
@@ -1050,7 +1053,7 @@ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolver, sideEffe
|
|
|
1050
1053
|
async function resolveDtsPath(id, importer, rolldownResolution) {
|
|
1051
1054
|
let dtsPath;
|
|
1052
1055
|
if (resolver === "tsc") {
|
|
1053
|
-
const { tscResolve } = await import("./resolver-
|
|
1056
|
+
const { tscResolve } = await import("./resolver-j7HY1N36.mjs");
|
|
1054
1057
|
dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
|
|
1055
1058
|
} else dtsPath = baseDtsResolver(id, importer);
|
|
1056
1059
|
debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
|
package/dist/tsc-context.d.mts
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/tsc/context.d.ts
|
|
4
|
+
interface ParsedProject {
|
|
5
|
+
tsconfigPath: string;
|
|
6
|
+
parsedConfig: ts.ParsedCommandLine;
|
|
7
|
+
}
|
|
8
|
+
type SourceFileToProjectMap = Map<string, ParsedProject>;
|
|
9
|
+
interface TscContext {
|
|
10
|
+
programs: ts.Program[];
|
|
11
|
+
files: Map<string, string>;
|
|
12
|
+
projects: Map<string, SourceFileToProjectMap>;
|
|
13
|
+
}
|
|
14
|
+
declare function createContext(): TscContext;
|
|
15
|
+
declare function invalidateContextFile(context: TscContext, file: string): void;
|
|
16
|
+
declare const globalContext: TscContext;
|
|
17
|
+
//#endregion
|
|
2
18
|
export { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile };
|
package/dist/tsc-context.mjs
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDebug } from "obug";
|
|
2
|
+
const path = globalThis.process.getBuiltinModule("node:path");
|
|
2
3
|
|
|
4
|
+
//#region src/tsc/context.ts
|
|
5
|
+
const debug = createDebug("rolldown-plugin-dts:tsc-context");
|
|
6
|
+
function createContext() {
|
|
7
|
+
return {
|
|
8
|
+
programs: [],
|
|
9
|
+
files: /* @__PURE__ */ new Map(),
|
|
10
|
+
projects: /* @__PURE__ */ new Map()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function invalidateContextFile(context, file) {
|
|
14
|
+
file = path.resolve(file).replaceAll("\\", "/");
|
|
15
|
+
debug(`invalidating context file: ${file}`);
|
|
16
|
+
context.files.delete(file);
|
|
17
|
+
context.programs = context.programs.filter((program) => {
|
|
18
|
+
return !program.getSourceFiles().some((sourceFile) => sourceFile.fileName === file);
|
|
19
|
+
});
|
|
20
|
+
context.projects.clear();
|
|
21
|
+
}
|
|
22
|
+
const globalContext = createContext();
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
3
25
|
export { createContext, globalContext, invalidateContextFile };
|
package/dist/tsc-worker.d.mts
CHANGED
package/dist/tsc-worker.mjs
CHANGED
package/dist/tsc.d.mts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as TscOptions, r as TscResult, t as TscModule } from "./types-D8g6CB60.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/tsc/index.d.ts
|
|
4
|
+
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { type TscModule, type TscOptions, type TscResult, tscEmit };
|
package/dist/tsc.mjs
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
2
|
+
import { n as tscEmitBuild, t as tscEmitCompiler } from "./emit-compiler-CfQ29zff.mjs";
|
|
3
|
+
import { createDebug } from "obug";
|
|
4
|
+
const ts = __cjs_require("typescript");
|
|
2
5
|
|
|
6
|
+
//#region src/tsc/index.ts
|
|
7
|
+
const debug = createDebug("rolldown-plugin-dts:tsc");
|
|
8
|
+
debug(`loaded typescript: ${ts.version}`);
|
|
9
|
+
function tscEmit(tscOptions) {
|
|
10
|
+
debug(`running tscEmit ${tscOptions.id}`);
|
|
11
|
+
if (tscOptions.build) return tscEmitBuild(tscOptions);
|
|
12
|
+
else return tscEmitCompiler(tscOptions);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
3
16
|
export { tscEmit };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TscContext } from "./tsc-context.mjs";
|
|
2
|
+
import { SourceMapInput } from "rolldown";
|
|
2
3
|
import { TsConfigJson } from "get-tsconfig";
|
|
3
4
|
import ts from "typescript";
|
|
4
|
-
import { SourceMapInput } from "rolldown";
|
|
5
5
|
|
|
6
6
|
//#region src/tsc/types.d.ts
|
|
7
7
|
interface TscModule {
|
|
@@ -27,7 +27,4 @@ interface TscResult {
|
|
|
27
27
|
error?: string;
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
|
-
|
|
31
|
-
declare function tscEmit(tscOptions: TscOptions): TscResult;
|
|
32
|
-
//#endregion
|
|
33
|
-
export { TscResult as i, TscModule as n, TscOptions as r, tscEmit as t };
|
|
30
|
+
export { TscOptions as n, TscResult as r, TscModule as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.22.1",
|
|
5
5
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@ts-macro/tsc": "^0.3.6",
|
|
45
45
|
"@typescript/native-preview": ">=7.0.0-dev.20250601.1",
|
|
46
|
-
"rolldown": "^1.0.0-
|
|
46
|
+
"rolldown": "^1.0.0-rc.3",
|
|
47
47
|
"typescript": "^5.0.0",
|
|
48
48
|
"vue-tsc": "~3.2.0"
|
|
49
49
|
},
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@babel/generator": "8.0.0-rc.1",
|
|
66
|
+
"@babel/helper-validator-identifier": "8.0.0-rc.1",
|
|
66
67
|
"@babel/parser": "8.0.0-rc.1",
|
|
67
68
|
"@babel/types": "8.0.0-rc.1",
|
|
68
69
|
"ast-kit": "^3.0.0-beta.1",
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"@sxzz/prettier-config": "^2.3.1",
|
|
78
79
|
"@sxzz/test-utils": "^0.5.15",
|
|
79
80
|
"@types/node": "^25.2.0",
|
|
80
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
81
|
+
"@typescript/native-preview": "7.0.0-dev.20260204.1",
|
|
81
82
|
"@volar/typescript": "^2.4.28",
|
|
82
83
|
"@vue/language-core": "^3.2.4",
|
|
83
84
|
"arktype": "^2.1.29",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
"diff": "^8.0.3",
|
|
86
87
|
"eslint": "^9.39.2",
|
|
87
88
|
"prettier": "^3.8.1",
|
|
88
|
-
"rolldown": "^1.0.0-rc.
|
|
89
|
+
"rolldown": "^1.0.0-rc.3",
|
|
89
90
|
"rolldown-plugin-dts-snapshot": "^0.3.2",
|
|
90
91
|
"rolldown-plugin-require-cjs": "^0.3.3",
|
|
91
92
|
"rollup-plugin-dts": "^6.3.0",
|
|
@@ -97,7 +98,7 @@
|
|
|
97
98
|
"vue-tsc": "^3.2.4"
|
|
98
99
|
},
|
|
99
100
|
"resolutions": {
|
|
100
|
-
"rolldown": "^1.0.0-rc.
|
|
101
|
+
"rolldown": "^1.0.0-rc.3"
|
|
101
102
|
},
|
|
102
103
|
"prettier": "@sxzz/prettier-config",
|
|
103
104
|
"scripts": {
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { createDebug } from "obug";
|
|
2
|
-
const path = globalThis.process.getBuiltinModule("node:path");
|
|
3
|
-
|
|
4
|
-
//#region src/tsc/context.ts
|
|
5
|
-
const debug = createDebug("rolldown-plugin-dts:tsc-context");
|
|
6
|
-
function createContext() {
|
|
7
|
-
return {
|
|
8
|
-
programs: [],
|
|
9
|
-
files: /* @__PURE__ */ new Map(),
|
|
10
|
-
projects: /* @__PURE__ */ new Map()
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function invalidateContextFile(context, file) {
|
|
14
|
-
file = path.resolve(file).replaceAll("\\", "/");
|
|
15
|
-
debug(`invalidating context file: ${file}`);
|
|
16
|
-
context.files.delete(file);
|
|
17
|
-
context.programs = context.programs.filter((program) => {
|
|
18
|
-
return !program.getSourceFiles().some((sourceFile) => sourceFile.fileName === file);
|
|
19
|
-
});
|
|
20
|
-
context.projects.clear();
|
|
21
|
-
}
|
|
22
|
-
const globalContext = createContext();
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { globalContext as n, invalidateContextFile as r, createContext as t };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
//#region src/tsc/context.d.ts
|
|
4
|
-
interface ParsedProject {
|
|
5
|
-
tsconfigPath: string;
|
|
6
|
-
parsedConfig: ts.ParsedCommandLine;
|
|
7
|
-
}
|
|
8
|
-
type SourceFileToProjectMap = Map<string, ParsedProject>;
|
|
9
|
-
interface TscContext {
|
|
10
|
-
programs: ts.Program[];
|
|
11
|
-
files: Map<string, string>;
|
|
12
|
-
projects: Map<string, SourceFileToProjectMap>;
|
|
13
|
-
}
|
|
14
|
-
declare function createContext(): TscContext;
|
|
15
|
-
declare function invalidateContextFile(context: TscContext, file: string): void;
|
|
16
|
-
declare const globalContext: TscContext;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { globalContext as a, createContext as i, SourceFileToProjectMap as n, invalidateContextFile as o, TscContext as r, ParsedProject as t };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
//#region src/filename.ts
|
|
2
|
-
const RE_JS = /\.([cm]?)jsx?$/;
|
|
3
|
-
const RE_TS = /\.([cm]?)tsx?$/;
|
|
4
|
-
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
5
|
-
const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
|
|
6
|
-
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
7
|
-
const RE_CSS = /\.css$/;
|
|
8
|
-
const RE_VUE = /\.vue$/;
|
|
9
|
-
const RE_JSON = /\.json$/;
|
|
10
|
-
const RE_ROLLDOWN_RUNTIME = /^\0rolldown\/runtime\.js$/;
|
|
11
|
-
function filename_js_to_dts(id) {
|
|
12
|
-
return id.replace(RE_JS, ".d.$1ts");
|
|
13
|
-
}
|
|
14
|
-
function filename_to_dts(id) {
|
|
15
|
-
return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".json.d.ts");
|
|
16
|
-
}
|
|
17
|
-
function filename_dts_to(id, ext) {
|
|
18
|
-
return id.replace(RE_DTS, `.$1${ext}`);
|
|
19
|
-
}
|
|
20
|
-
function resolveTemplateFn(fn, chunk) {
|
|
21
|
-
return typeof fn === "function" ? fn(chunk) : fn;
|
|
22
|
-
}
|
|
23
|
-
function replaceTemplateName(template, name) {
|
|
24
|
-
return template.replaceAll("[name]", name);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
export { RE_JSON as a, RE_TS as c, filename_js_to_dts as d, filename_to_dts as f, RE_JS as i, RE_VUE as l, resolveTemplateFn as m, RE_DTS as n, RE_NODE_MODULES as o, replaceTemplateName as p, RE_DTS_MAP as r, RE_ROLLDOWN_RUNTIME as s, RE_CSS as t, filename_dts_to as u };
|
|
File without changes
|