rolldown-plugin-dts 0.15.4 → 0.15.6
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 +8 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +14 -5
- package/dist/{tsc-BSxLVaDe.js → tsc-BJW5IMTs.js} +8 -1
- package/dist/tsc-worker.js +1 -1
- package/dist/tsc.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,14 @@ Resolve external types used in `.d.ts` files from `node_modules`.
|
|
|
86
86
|
- If `true`, all external types are resolved.
|
|
87
87
|
- If an array, only types matching the provided strings or regular expressions are resolved.
|
|
88
88
|
|
|
89
|
+
#### `cjsDefault`
|
|
90
|
+
|
|
91
|
+
Determines how the default export is emitted.
|
|
92
|
+
|
|
93
|
+
If set to `true`, and you are only exporting a single item using `export default ...`,
|
|
94
|
+
the output will use `export = ...` instead of the standard ES module syntax.
|
|
95
|
+
This is useful for compatibility with CommonJS.
|
|
96
|
+
|
|
89
97
|
### `tsc` Options
|
|
90
98
|
|
|
91
99
|
> [!NOTE]
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,14 @@ interface GeneralOptions {
|
|
|
50
50
|
* Resolve external types used in `.d.ts` files from `node_modules`.
|
|
51
51
|
*/
|
|
52
52
|
resolve?: boolean | (string | RegExp)[];
|
|
53
|
+
/**
|
|
54
|
+
* Determines how the default export is emitted.
|
|
55
|
+
*
|
|
56
|
+
* If set to `true`, and you are only exporting a single item using `export default ...`,
|
|
57
|
+
* the output will use `export = ...` instead of the standard ES module syntax.
|
|
58
|
+
* This is useful for compatibility with CommonJS.
|
|
59
|
+
*/
|
|
60
|
+
cjsDefault?: boolean;
|
|
53
61
|
}
|
|
54
62
|
interface TscOptions {
|
|
55
63
|
/**
|
|
@@ -160,6 +168,7 @@ declare function resolveOptions({
|
|
|
160
168
|
compilerOptions,
|
|
161
169
|
sourcemap,
|
|
162
170
|
resolve,
|
|
171
|
+
cjsDefault,
|
|
163
172
|
build,
|
|
164
173
|
incremental,
|
|
165
174
|
vue,
|
|
@@ -174,8 +183,9 @@ declare function resolveOptions({
|
|
|
174
183
|
//#region src/fake-js.d.ts
|
|
175
184
|
declare function createFakeJsPlugin({
|
|
176
185
|
dtsInput,
|
|
177
|
-
sourcemap
|
|
178
|
-
|
|
186
|
+
sourcemap,
|
|
187
|
+
cjsDefault
|
|
188
|
+
}: Pick<OptionsResolved, "dtsInput" | "sourcemap" | "cjsDefault">): Plugin;
|
|
179
189
|
//#endregion
|
|
180
190
|
//#region src/generate.d.ts
|
|
181
191
|
declare function createGeneratePlugin({
|
package/dist/index.js
CHANGED
|
@@ -230,7 +230,7 @@ function walk(ast, { enter, leave }) {
|
|
|
230
230
|
//#endregion
|
|
231
231
|
//#region src/fake-js.ts
|
|
232
232
|
const generate = _generate.default || _generate;
|
|
233
|
-
function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
233
|
+
function createFakeJsPlugin({ dtsInput, sourcemap, cjsDefault }) {
|
|
234
234
|
let symbolIdx = 0;
|
|
235
235
|
const identifierMap = Object.create(null);
|
|
236
236
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -371,7 +371,8 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
371
371
|
program.body = patchTsNamespace(program.body);
|
|
372
372
|
program.body = program.body.map((node) => {
|
|
373
373
|
if (isHelperImport(node)) return null;
|
|
374
|
-
|
|
374
|
+
const newNode = patchImportExport(node, typeOnlyIds, cjsDefault);
|
|
375
|
+
if (newNode) return newNode;
|
|
375
376
|
if (node.type !== "VariableDeclaration") return node;
|
|
376
377
|
const [decl] = node.declarations;
|
|
377
378
|
if (decl.init?.type !== "ArrayExpression" || !decl.init.elements[0]) return null;
|
|
@@ -515,7 +516,7 @@ function isReferenceId(node) {
|
|
|
515
516
|
function isHelperImport(node) {
|
|
516
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));
|
|
517
518
|
}
|
|
518
|
-
function patchImportExport(node, typeOnlyIds) {
|
|
519
|
+
function patchImportExport(node, typeOnlyIds, cjsDefault) {
|
|
519
520
|
if (isTypeOf(node, [
|
|
520
521
|
"ImportDeclaration",
|
|
521
522
|
"ExportAllDeclaration",
|
|
@@ -528,7 +529,14 @@ function patchImportExport(node, typeOnlyIds) {
|
|
|
528
529
|
}
|
|
529
530
|
if (node.source?.value && RE_DTS.test(node.source.value)) {
|
|
530
531
|
node.source.value = filename_dts_to(node.source.value, "js");
|
|
531
|
-
return
|
|
532
|
+
return node;
|
|
533
|
+
}
|
|
534
|
+
if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && resolveString(node.specifiers[0].exported) === "default") {
|
|
535
|
+
const defaultExport = node.specifiers[0];
|
|
536
|
+
return {
|
|
537
|
+
type: "TSExportAssignment",
|
|
538
|
+
expression: defaultExport.local
|
|
539
|
+
};
|
|
532
540
|
}
|
|
533
541
|
}
|
|
534
542
|
}
|
|
@@ -832,7 +840,7 @@ async function runTsgo(root, tsconfig) {
|
|
|
832
840
|
//#endregion
|
|
833
841
|
//#region src/options.ts
|
|
834
842
|
let warnedTsgo = false;
|
|
835
|
-
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, build = false, incremental = false, vue = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
843
|
+
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, cjsDefault = false, build = false, incremental = false, vue = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
836
844
|
let resolvedTsconfig;
|
|
837
845
|
if (tsconfig === true || tsconfig == null) {
|
|
838
846
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -878,6 +886,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
|
|
|
878
886
|
tsconfigRaw,
|
|
879
887
|
sourcemap,
|
|
880
888
|
resolve,
|
|
889
|
+
cjsDefault,
|
|
881
890
|
build,
|
|
882
891
|
incremental,
|
|
883
892
|
vue,
|
|
@@ -248,6 +248,13 @@ function tscEmit(tscOptions) {
|
|
|
248
248
|
debug(`got source file: ${file.fileName}`);
|
|
249
249
|
let dtsCode;
|
|
250
250
|
let map;
|
|
251
|
+
const stripPrivateFields = (ctx) => {
|
|
252
|
+
const visitor = (node) => {
|
|
253
|
+
if (ts.isPropertySignature(node) && ts.isPrivateIdentifier(node.name)) return ctx.factory.updatePropertySignature(node, node.modifiers, ctx.factory.createStringLiteral(node.name.text), node.questionToken, node.type);
|
|
254
|
+
return ts.visitEachChild(node, visitor, ctx);
|
|
255
|
+
};
|
|
256
|
+
return (sourceFile) => ts.visitNode(sourceFile, visitor, ts.isSourceFile) ?? sourceFile;
|
|
257
|
+
};
|
|
251
258
|
const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
|
|
252
259
|
if (fileName.endsWith(".map")) {
|
|
253
260
|
debug(`emit dts sourcemap: ${fileName}`);
|
|
@@ -256,7 +263,7 @@ function tscEmit(tscOptions) {
|
|
|
256
263
|
debug(`emit dts: ${fileName}`);
|
|
257
264
|
dtsCode = code;
|
|
258
265
|
}
|
|
259
|
-
}, void 0, true,
|
|
266
|
+
}, void 0, true, { afterDeclarations: [stripPrivateFields] }, true);
|
|
260
267
|
if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
|
|
261
268
|
if (!dtsCode && file.isDeclarationFile) {
|
|
262
269
|
debug("nothing was emitted. fallback to sourceFile text.");
|
package/dist/tsc-worker.js
CHANGED
package/dist/tsc.js
CHANGED