rolldown-plugin-dts 0.3.0 → 0.4.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 +8 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +27 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,13 @@ interface Options {
|
|
|
38
38
|
*/
|
|
39
39
|
dtsInput?: boolean
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* When `true`, the plugin will only emit `.d.ts` files and remove all other chunks.
|
|
43
|
+
*
|
|
44
|
+
* This feature is particularly beneficial when you need to generate `d.ts` files for the CommonJS format as part of a separate build process.
|
|
45
|
+
*/
|
|
46
|
+
emitDtsOnly?: boolean
|
|
47
|
+
|
|
41
48
|
isolatedDeclaration?: Omit<IsolatedDeclarationsOptions, 'sourcemap'>
|
|
42
49
|
|
|
43
50
|
/**
|
|
@@ -56,7 +63,7 @@ interface Options {
|
|
|
56
63
|
}
|
|
57
64
|
````
|
|
58
65
|
|
|
59
|
-
## Caveats
|
|
66
|
+
## ⚠️ Caveats
|
|
60
67
|
|
|
61
68
|
- The plugin uses Oxc's `isolatedDeclarations` to generate `.d.ts` files,
|
|
62
69
|
which means you need to set `isolatedDeclarations: true` in your `tsconfig.json` and ensure there are no errors.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare function createFakeJsPlugin({ dtsInput }: Pick<Options, "dtsInput">): Pl
|
|
|
6
6
|
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/generate.d.ts
|
|
9
|
-
declare function createGeneratePlugin({ isolatedDeclaration, inputAlias, resolve }: Pick<Options, "isolatedDeclaration" | "inputAlias" | "resolve">): Plugin;
|
|
9
|
+
declare function createGeneratePlugin({ isolatedDeclaration, inputAlias, resolve, emitDtsOnly }: Pick<Options, "isolatedDeclaration" | "inputAlias" | "resolve" | "emitDtsOnly">): Plugin;
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/index.d.ts
|
|
@@ -17,6 +17,12 @@ interface Options {
|
|
|
17
17
|
* If enabled, the plugin will skip generating a `.d.ts` file for the entry point.
|
|
18
18
|
*/
|
|
19
19
|
dtsInput?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* When `true`, the plugin will only emit `.d.ts` files and remove all other chunks.
|
|
22
|
+
*
|
|
23
|
+
* This feature is particularly beneficial when you need to generate `d.ts` files for the CommonJS format as part of a separate build process.
|
|
24
|
+
*/
|
|
25
|
+
emitDtsOnly?: boolean;
|
|
20
26
|
isolatedDeclaration?: Omit<IsolatedDeclarationsOptions, "sourcemap">;
|
|
21
27
|
/**
|
|
22
28
|
* dts file name alias `{ [filename]: path }`
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MagicStringAST } from "magic-string-ast";
|
|
2
2
|
import { parseAsync } from "oxc-parser";
|
|
3
|
-
import path, { basename } from "node:path";
|
|
3
|
+
import path, { basename, extname } from "node:path";
|
|
4
4
|
import { createResolver } from "dts-resolver";
|
|
5
5
|
import { isolatedDeclaration } from "oxc-transform";
|
|
6
6
|
|
|
@@ -436,9 +436,9 @@ function importNamespace(s, source, imported, getIdentifierIndex) {
|
|
|
436
436
|
//#endregion
|
|
437
437
|
//#region src/generate.ts
|
|
438
438
|
const meta = { dtsFile: true };
|
|
439
|
-
function createGeneratePlugin({ isolatedDeclaration: isolatedDeclaration$1, inputAlias =
|
|
439
|
+
function createGeneratePlugin({ isolatedDeclaration: isolatedDeclaration$1, inputAlias, resolve = false, emitDtsOnly = false }) {
|
|
440
440
|
const dtsMap = new Map();
|
|
441
|
-
const inputAliasMap = new Map(Object.entries(inputAlias));
|
|
441
|
+
const inputAliasMap = new Map(inputAlias && Object.entries(inputAlias));
|
|
442
442
|
const resolver = createResolver();
|
|
443
443
|
let inputOption;
|
|
444
444
|
return {
|
|
@@ -446,6 +446,16 @@ function createGeneratePlugin({ isolatedDeclaration: isolatedDeclaration$1, inpu
|
|
|
446
446
|
options({ input }) {
|
|
447
447
|
if (isPlainObject(input)) inputOption = { ...input };
|
|
448
448
|
},
|
|
449
|
+
outputOptions(options) {
|
|
450
|
+
return {
|
|
451
|
+
...options,
|
|
452
|
+
entryFileNames(chunk) {
|
|
453
|
+
const original = (typeof options.entryFileNames === "function" ? options.entryFileNames(chunk) : options.entryFileNames) || "[name].js";
|
|
454
|
+
if (chunk.name.endsWith(".d")) return original.replace(RE_JS, ".$1ts");
|
|
455
|
+
return original;
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
},
|
|
449
459
|
transform: {
|
|
450
460
|
order: "pre",
|
|
451
461
|
filter: { id: {
|
|
@@ -456,17 +466,21 @@ function createGeneratePlugin({ isolatedDeclaration: isolatedDeclaration$1, inpu
|
|
|
456
466
|
const { code: dtsCode, errors } = isolatedDeclaration(id, code, isolatedDeclaration$1);
|
|
457
467
|
if (errors.length) return this.error(errors[0]);
|
|
458
468
|
const dtsId = filename_ts_to_dts(id);
|
|
459
|
-
dtsMap.set(dtsId,
|
|
469
|
+
dtsMap.set(dtsId, {
|
|
470
|
+
code: dtsCode,
|
|
471
|
+
src: id
|
|
472
|
+
});
|
|
460
473
|
const mod = this.getModuleInfo(id);
|
|
461
474
|
if (mod?.isEntry) {
|
|
462
|
-
let
|
|
463
|
-
if (inputAliasMap.has(
|
|
464
|
-
else if (inputAliasMap.has(dtsId))
|
|
475
|
+
let name = basename(dtsId, extname(dtsId));
|
|
476
|
+
if (inputAliasMap.has(name)) name = inputAliasMap.get(name);
|
|
477
|
+
else if (inputAliasMap.has(dtsId)) name = inputAliasMap.get(dtsId);
|
|
465
478
|
this.emitFile({
|
|
466
479
|
type: "chunk",
|
|
467
480
|
id: dtsId,
|
|
468
|
-
|
|
481
|
+
name
|
|
469
482
|
});
|
|
483
|
+
if (emitDtsOnly) return "//";
|
|
470
484
|
}
|
|
471
485
|
}
|
|
472
486
|
},
|
|
@@ -523,11 +537,14 @@ function createGeneratePlugin({ isolatedDeclaration: isolatedDeclaration$1, inpu
|
|
|
523
537
|
} },
|
|
524
538
|
handler(id) {
|
|
525
539
|
if (dtsMap.has(id)) return {
|
|
526
|
-
code: dtsMap.get(id),
|
|
540
|
+
code: dtsMap.get(id).code,
|
|
527
541
|
moduleSideEffects: false
|
|
528
542
|
};
|
|
529
543
|
}
|
|
530
|
-
}
|
|
544
|
+
},
|
|
545
|
+
generateBundle: emitDtsOnly ? (options, bundle) => {
|
|
546
|
+
for (const fileName of Object.keys(bundle)) if (!RE_DTS.test(fileName)) delete bundle[fileName];
|
|
547
|
+
} : void 0
|
|
531
548
|
};
|
|
532
549
|
}
|
|
533
550
|
function isPlainObject(data) {
|