rolldown-plugin-dts 0.16.4 → 0.16.5
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 +14 -3
- package/dist/index.js +35 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -99,6 +99,14 @@ If set to `true`, and you are only exporting a single item using `export default
|
|
|
99
99
|
the output will use `export = ...` instead of the standard ES module syntax.
|
|
100
100
|
This is useful for compatibility with CommonJS.
|
|
101
101
|
|
|
102
|
+
#### `banner`
|
|
103
|
+
|
|
104
|
+
Content to be added at the top of each generated `.d.ts` file.
|
|
105
|
+
|
|
106
|
+
#### `footer`
|
|
107
|
+
|
|
108
|
+
Content to be added at the bottom of each generated `.d.ts` file.
|
|
109
|
+
|
|
102
110
|
### `tsc` Options
|
|
103
111
|
|
|
104
112
|
> [!NOTE]
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-BDKLOOY5.js";
|
|
2
2
|
import { IsolatedDeclarationsOptions } from "rolldown/experimental";
|
|
3
3
|
import { TsConfigJson } from "get-tsconfig";
|
|
4
|
-
import { Plugin } from "rolldown";
|
|
4
|
+
import { AddonFunction, Plugin } from "rolldown";
|
|
5
5
|
|
|
6
6
|
//#region src/options.d.ts
|
|
7
7
|
interface GeneralOptions {
|
|
@@ -144,6 +144,14 @@ interface TscOptions {
|
|
|
144
144
|
* `false`.
|
|
145
145
|
*/
|
|
146
146
|
emitJs?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Content to be added at the top of each generated `.d.ts` file.
|
|
149
|
+
*/
|
|
150
|
+
banner?: string | Promise<string> | AddonFunction;
|
|
151
|
+
/**
|
|
152
|
+
* Content to be added at the bottom of each generated `.d.ts` file.
|
|
153
|
+
*/
|
|
154
|
+
footer?: string | Promise<string> | AddonFunction;
|
|
147
155
|
}
|
|
148
156
|
interface Options extends GeneralOptions, TscOptions {
|
|
149
157
|
/**
|
|
@@ -164,8 +172,9 @@ interface Options extends GeneralOptions, TscOptions {
|
|
|
164
172
|
tsgo?: boolean;
|
|
165
173
|
}
|
|
166
174
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
167
|
-
type
|
|
168
|
-
|
|
175
|
+
type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
|
|
176
|
+
type OptionsResolved = Overwrite<MarkPartial<Omit<Options, "compilerOptions">, "banner" | "footer">, {
|
|
177
|
+
tsconfig?: string;
|
|
169
178
|
oxc: IsolatedDeclarationsOptions | false;
|
|
170
179
|
tsconfigRaw: TsConfigJson;
|
|
171
180
|
}>;
|
|
@@ -179,6 +188,8 @@ declare function resolveOptions({
|
|
|
179
188
|
sourcemap,
|
|
180
189
|
resolve,
|
|
181
190
|
cjsDefault,
|
|
191
|
+
banner,
|
|
192
|
+
footer,
|
|
182
193
|
build,
|
|
183
194
|
incremental,
|
|
184
195
|
vue,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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_to_dts, replaceTemplateName, resolveTemplateFn } from "./filename-Dd76wOJT.js";
|
|
2
2
|
import { createContext, globalContext, invalidateContextFile } from "./context-Digr9tkU.js";
|
|
3
3
|
import Debug from "debug";
|
|
4
|
+
import MagicString from "magic-string";
|
|
4
5
|
import _generate from "@babel/generator";
|
|
5
6
|
import { parse } from "@babel/parser";
|
|
6
7
|
import * as t from "@babel/types";
|
|
@@ -15,6 +16,36 @@ import process from "node:process";
|
|
|
15
16
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
16
17
|
import { createResolver } from "dts-resolver";
|
|
17
18
|
|
|
19
|
+
//#region src/banner.ts
|
|
20
|
+
function createBannerPlugin({ banner, footer }) {
|
|
21
|
+
return {
|
|
22
|
+
name: "rolldown-plugin-dts:banner",
|
|
23
|
+
async renderChunk(code, chunk) {
|
|
24
|
+
if (!RE_DTS.test(chunk.fileName)) return;
|
|
25
|
+
const s = new MagicString(code);
|
|
26
|
+
if (banner) {
|
|
27
|
+
const code$1 = await (typeof banner === "function" ? banner(chunk) : banner);
|
|
28
|
+
if (code$1) s.prepend(`${code$1}\n`);
|
|
29
|
+
}
|
|
30
|
+
if (footer) {
|
|
31
|
+
const code$1 = await (typeof footer === "function" ? footer(chunk) : footer);
|
|
32
|
+
if (code$1) s.append(`\n${code$1}`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
code: s.toString(),
|
|
36
|
+
get map() {
|
|
37
|
+
return s.generateMap({
|
|
38
|
+
source: chunk.fileName,
|
|
39
|
+
includeContent: true,
|
|
40
|
+
hires: "boundary"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
18
49
|
//#region src/dts-input.ts
|
|
19
50
|
function createDtsInputPlugin() {
|
|
20
51
|
return {
|
|
@@ -865,7 +896,7 @@ async function runTsgo(root, tsconfig) {
|
|
|
865
896
|
//#endregion
|
|
866
897
|
//#region src/options.ts
|
|
867
898
|
let warnedTsgo = false;
|
|
868
|
-
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, cjsDefault = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
899
|
+
function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolve = false, cjsDefault = false, banner, footer, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
|
|
869
900
|
let resolvedTsconfig;
|
|
870
901
|
if (tsconfig === true || tsconfig == null) {
|
|
871
902
|
const { config, path: path$1 } = getTsconfig(cwd) || {};
|
|
@@ -914,6 +945,8 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
|
|
|
914
945
|
sourcemap,
|
|
915
946
|
resolve,
|
|
916
947
|
cjsDefault,
|
|
948
|
+
banner,
|
|
949
|
+
footer,
|
|
917
950
|
build,
|
|
918
951
|
incremental,
|
|
919
952
|
vue,
|
|
@@ -986,6 +1019,7 @@ function dts(options = {}) {
|
|
|
986
1019
|
if (options.dtsInput) plugins.push(createDtsInputPlugin());
|
|
987
1020
|
else plugins.push(createGeneratePlugin(resolved));
|
|
988
1021
|
plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
|
|
1022
|
+
if (options.banner || options.footer) plugins.push(createBannerPlugin(resolved));
|
|
989
1023
|
return plugins;
|
|
990
1024
|
}
|
|
991
1025
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.5",
|
|
4
4
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
"birpc": "^2.5.0",
|
|
69
69
|
"debug": "^4.4.1",
|
|
70
70
|
"dts-resolver": "^2.1.2",
|
|
71
|
-
"get-tsconfig": "^4.10.1"
|
|
71
|
+
"get-tsconfig": "^4.10.1",
|
|
72
|
+
"magic-string": "^0.30.19"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
75
|
"@sxzz/eslint-config": "^7.1.4",
|