rolldown-plugin-dts 0.16.4 → 0.16.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 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]
@@ -1,13 +1,13 @@
1
- import ts from "typescript";
1
+ import Ts from "typescript";
2
2
 
3
3
  //#region src/tsc/context.d.ts
4
4
  interface ParsedProject {
5
5
  tsconfigPath: string;
6
- parsedConfig: ts.ParsedCommandLine;
6
+ parsedConfig: Ts.ParsedCommandLine;
7
7
  }
8
8
  type SourceFileToProjectMap = Map<string, ParsedProject>;
9
9
  interface TscContext {
10
- programs: ts.Program[];
10
+ programs: Ts.Program[];
11
11
  files: Map<string, string>;
12
12
  projects: Map<string, SourceFileToProjectMap>;
13
13
  }
@@ -15,4 +15,4 @@ declare function createContext(): TscContext;
15
15
  declare function invalidateContextFile(context: TscContext, file: string): void;
16
16
  declare const globalContext: TscContext;
17
17
  //#endregion
18
- export { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile };
18
+ export { ParsedProject, SourceFileToProjectMap, type Ts, TscContext, createContext, globalContext, invalidateContextFile };
@@ -1,12 +1,11 @@
1
- import { TscContext } from "./context-DXNtAHtR.js";
1
+ import { Ts, TscContext } from "./context-BafOW9LT.js";
2
2
  import { TsConfigJson } from "get-tsconfig";
3
- import ts from "typescript";
4
3
  import { SourceMapInput } from "rolldown";
5
4
 
6
5
  //#region src/tsc/types.d.ts
7
6
  interface TscModule {
8
- program: ts.Program;
9
- file: ts.SourceFile;
7
+ program: Ts.Program;
8
+ file: Ts.SourceFile;
10
9
  }
11
10
  interface TscOptions {
12
11
  tsconfig?: string;
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 OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
168
- tsconfig: string | undefined;
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,8 +1,8 @@
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
+ import { createRequire } from "node:module";
3
4
  import Debug from "debug";
4
- import _generate from "@babel/generator";
5
- import { parse } from "@babel/parser";
5
+ import MagicString from "magic-string";
6
6
  import * as t from "@babel/types";
7
7
  import { isDeclarationType, isTypeOf, resolveString } from "ast-kit";
8
8
  import { fork, spawn } from "node:child_process";
@@ -15,6 +15,36 @@ import process from "node:process";
15
15
  import { getTsconfig, parseTsconfig } from "get-tsconfig";
16
16
  import { createResolver } from "dts-resolver";
17
17
 
18
+ //#region src/banner.ts
19
+ function createBannerPlugin({ banner, footer }) {
20
+ return {
21
+ name: "rolldown-plugin-dts:banner",
22
+ async renderChunk(code, chunk) {
23
+ if (!RE_DTS.test(chunk.fileName)) return;
24
+ const s = new MagicString(code);
25
+ if (banner) {
26
+ const code$1 = await (typeof banner === "function" ? banner(chunk) : banner);
27
+ if (code$1) s.prepend(`${code$1}\n`);
28
+ }
29
+ if (footer) {
30
+ const code$1 = await (typeof footer === "function" ? footer(chunk) : footer);
31
+ if (code$1) s.append(`\n${code$1}`);
32
+ }
33
+ return {
34
+ code: s.toString(),
35
+ get map() {
36
+ return s.generateMap({
37
+ source: chunk.fileName,
38
+ includeContent: true,
39
+ hires: "boundary"
40
+ });
41
+ }
42
+ };
43
+ }
44
+ };
45
+ }
46
+
47
+ //#endregion
18
48
  //#region src/dts-input.ts
19
49
  function createDtsInputPlugin() {
20
50
  return {
@@ -237,7 +267,9 @@ function walk(ast, { enter, leave }) {
237
267
 
238
268
  //#endregion
239
269
  //#region src/fake-js.ts
240
- const generate = _generate.default || _generate;
270
+ const require = createRequire(import.meta.url);
271
+ const { parse } = require("@babel/parser");
272
+ const generate = require("@babel/generator").default;
241
273
  function createFakeJsPlugin({ sourcemap, cjsDefault }) {
242
274
  let symbolIdx = 0;
243
275
  const identifierMap = Object.create(null);
@@ -865,7 +897,7 @@ async function runTsgo(root, tsconfig) {
865
897
  //#endregion
866
898
  //#region src/options.ts
867
899
  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 }) {
900
+ 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
901
  let resolvedTsconfig;
870
902
  if (tsconfig === true || tsconfig == null) {
871
903
  const { config, path: path$1 } = getTsconfig(cwd) || {};
@@ -914,6 +946,8 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
914
946
  sourcemap,
915
947
  resolve,
916
948
  cjsDefault,
949
+ banner,
950
+ footer,
917
951
  build,
918
952
  incremental,
919
953
  vue,
@@ -940,30 +974,30 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
940
974
  resolveNodeModules: !!resolve,
941
975
  ResolverFactory
942
976
  });
943
- const resolveDtsPath = (id, importer, rolldownResolution) => {
977
+ function resolveDtsPath(id, importer, rolldownResolution) {
944
978
  let dtsPath = baseDtsResolver(id, importer);
945
979
  if (dtsPath) dtsPath = path.normalize(dtsPath);
946
980
  if (!dtsPath || !isSourceFile(dtsPath)) {
947
- if (rolldownResolution && isSourceFile(rolldownResolution.id)) return rolldownResolution.id;
981
+ if (rolldownResolution && isFilePath(rolldownResolution.id) && isSourceFile(rolldownResolution.id) && !rolldownResolution.external) return rolldownResolution.id;
948
982
  return null;
949
983
  }
950
984
  return dtsPath;
951
- };
985
+ }
952
986
  return {
953
987
  name: "rolldown-plugin-dts:resolver",
954
988
  resolveId: {
955
989
  order: "pre",
956
990
  async handler(id, importer, options) {
991
+ if (!importer || !RE_DTS.test(importer)) return;
957
992
  const external = {
958
993
  id,
959
994
  external: true,
960
995
  moduleSideEffects: false
961
996
  };
962
- if (!importer || !RE_DTS.test(importer)) return;
963
997
  if (RE_CSS.test(id)) return external;
964
998
  const rolldownResolution = await this.resolve(id, importer, options);
965
999
  const dtsResolution = resolveDtsPath(id, importer, rolldownResolution);
966
- if (!dtsResolution) return id.startsWith(".") || path.isAbsolute(id) ? null : external;
1000
+ if (!dtsResolution) return isFilePath(id) ? null : external;
967
1001
  if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) return external;
968
1002
  if (RE_DTS.test(dtsResolution)) return dtsResolution;
969
1003
  if (isSourceFile(dtsResolution)) {
@@ -974,6 +1008,9 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
974
1008
  }
975
1009
  };
976
1010
  }
1011
+ function isFilePath(id) {
1012
+ return id.startsWith(".") || path.isAbsolute(id);
1013
+ }
977
1014
 
978
1015
  //#endregion
979
1016
  //#region src/index.ts
@@ -986,6 +1023,7 @@ function dts(options = {}) {
986
1023
  if (options.dtsInput) plugins.push(createDtsInputPlugin());
987
1024
  else plugins.push(createGeneratePlugin(resolved));
988
1025
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
1026
+ if (options.banner || options.footer) plugins.push(createBannerPlugin(resolved));
989
1027
  return plugins;
990
1028
  }
991
1029
 
@@ -2,9 +2,13 @@ import { globalContext } from "./context-Digr9tkU.js";
2
2
  import { createRequire } from "node:module";
3
3
  import Debug from "debug";
4
4
  import path from "node:path";
5
- import ts from "typescript";
6
5
  import { pathToFileURL } from "node:url";
7
6
 
7
+ //#region src/tsc/require-tsc.ts
8
+ const require$1 = createRequire(import.meta.url);
9
+ const ts = require$1("typescript");
10
+
11
+ //#endregion
8
12
  //#region src/tsc/system.ts
9
13
  const debug$3 = Debug("rolldown-plugin-dts:tsc-system");
10
14
  /**
@@ -1,2 +1,2 @@
1
- import { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile } from "./context-DXNtAHtR.js";
1
+ import { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile } from "./context-BafOW9LT.js";
2
2
  export { ParsedProject, SourceFileToProjectMap, TscContext, createContext, globalContext, invalidateContextFile };
@@ -1,5 +1,5 @@
1
- import "./context-DXNtAHtR.js";
2
- import { tscEmit } from "./index-CxJisQQS.js";
1
+ import "./context-BafOW9LT.js";
2
+ import { tscEmit } from "./index-BJoOXlKM.js";
3
3
 
4
4
  //#region src/tsc/worker.d.ts
5
5
  declare const functions: {
@@ -1,5 +1,5 @@
1
1
  import "./context-Digr9tkU.js";
2
- import { tscEmit } from "./tsc-DLbQk3B6.js";
2
+ import { tscEmit } from "./tsc-CCjlVYkv.js";
3
3
  import process from "node:process";
4
4
  import { createBirpc } from "birpc";
5
5
 
package/dist/tsc.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import "./context-DXNtAHtR.js";
2
- import { TscModule, TscOptions, TscResult, tscEmit } from "./index-CxJisQQS.js";
1
+ import "./context-BafOW9LT.js";
2
+ import { TscModule, TscOptions, TscResult, tscEmit } from "./index-BJoOXlKM.js";
3
3
  export { TscModule, TscOptions, TscResult, tscEmit };
package/dist/tsc.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./context-Digr9tkU.js";
2
- import { tscEmit } from "./tsc-DLbQk3B6.js";
2
+ import { tscEmit } from "./tsc-CCjlVYkv.js";
3
3
 
4
4
  export { tscEmit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.16.4",
3
+ "version": "0.16.6",
4
4
  "description": "A Rolldown plugin to generate and bundle dts files.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -66,33 +66,35 @@
66
66
  "@babel/types": "^7.28.4",
67
67
  "ast-kit": "^2.1.2",
68
68
  "birpc": "^2.5.0",
69
- "debug": "^4.4.1",
69
+ "debug": "^4.4.3",
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",
75
76
  "@sxzz/prettier-config": "^2.2.4",
76
- "@sxzz/test-utils": "^0.5.10",
77
+ "@sxzz/test-utils": "^0.5.11",
77
78
  "@types/babel__generator": "^7.27.0",
78
79
  "@types/debug": "^4.1.12",
79
- "@types/node": "^24.3.1",
80
- "@typescript/native-preview": "7.0.0-dev.20250911.1",
80
+ "@types/node": "^24.5.2",
81
+ "@typescript/native-preview": "7.0.0-dev.20250918.1",
81
82
  "@volar/typescript": "^2.4.23",
82
- "@vue/language-core": "^3.0.6",
83
+ "@vue/language-core": "^3.0.7",
84
+ "arktype": "^2.1.22",
83
85
  "bumpp": "^10.2.3",
84
86
  "diff": "^8.0.2",
85
87
  "eslint": "^9.35.0",
86
88
  "estree-walker": "^3.0.3",
87
89
  "prettier": "^3.6.2",
88
- "rolldown": "^1.0.0-beta.37",
90
+ "rolldown": "^1.0.0-beta.38",
89
91
  "rollup-plugin-dts": "^6.2.3",
90
92
  "tinyglobby": "^0.2.15",
91
- "tsdown": "^0.15.0",
93
+ "tsdown": "^0.15.2",
92
94
  "typescript": "^5.9.2",
93
95
  "vitest": "^3.2.4",
94
96
  "vue": "^3.5.21",
95
- "vue-tsc": "^3.0.6"
97
+ "vue-tsc": "^3.0.7"
96
98
  },
97
99
  "engines": {
98
100
  "node": ">=20.18.0"