rolldown-plugin-dts 0.15.6 → 0.15.8

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
@@ -1,6 +1,8 @@
1
- # rolldown-plugin-dts [![npm](https://img.shields.io/npm/v/rolldown-plugin-dts.svg)](https://npmjs.com/package/rolldown-plugin-dts)
1
+ # rolldown-plugin-dts
2
2
 
3
- [![Unit Test](https://github.com/sxzz/rolldown-plugin-dts/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sxzz/rolldown-plugin-dts/actions/workflows/unit-test.yml)
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![Unit Test][unit-test-src]][unit-test-href]
4
6
 
5
7
  A Rolldown plugin to generate and bundle dts files.
6
8
 
@@ -175,7 +177,7 @@ This option is automatically enabled when `isolatedDeclarations` in `compilerOpt
175
177
 
176
178
  To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
177
179
 
178
- `tsconfigRaw` option will be ignored when this option is enabled.
180
+ `tsconfigRaw` and `compilerOptions` options will be ignored when this option is enabled.
179
181
 
180
182
  ## Differences from `rollup-plugin-dts`
181
183
 
@@ -212,3 +214,12 @@ Furthermore, the test suite is authorized by them and distributed under the MIT
212
214
  ## License
213
215
 
214
216
  [MIT](./LICENSE) License © 2025 [三咲智子 Kevin Deng](https://github.com/sxzz)
217
+
218
+ <!-- Badges -->
219
+
220
+ [npm-version-src]: https://img.shields.io/npm/v/rolldown-plugin-dts.svg
221
+ [npm-version-href]: https://npmjs.com/package/rolldown-plugin-dts
222
+ [npm-downloads-src]: https://img.shields.io/npm/dm/rolldown-plugin-dts
223
+ [npm-downloads-href]: https://www.npmcharts.com/compare/rolldown-plugin-dts?interval=30
224
+ [unit-test-src]: https://github.com/sxzz/rolldown-plugin-dts/actions/workflows/unit-test.yml/badge.svg
225
+ [unit-test-href]: https://github.com/sxzz/rolldown-plugin-dts/actions/workflows/unit-test.yml
@@ -1,3 +1,5 @@
1
+ import { ChunkFileNamesFunction, PreRenderedChunk } from "rolldown";
2
+
1
3
  //#region src/filename.d.ts
2
4
  declare const RE_JS: RegExp;
3
5
  declare const RE_TS: RegExp;
@@ -9,5 +11,7 @@ declare const RE_VUE: RegExp;
9
11
  declare function filename_js_to_dts(id: string): string;
10
12
  declare function filename_to_dts(id: string): string;
11
13
  declare function filename_dts_to(id: string, ext: "js" | "ts"): string;
14
+ declare function resolveTemplateFn(fn: string | ChunkFileNamesFunction, chunk: PreRenderedChunk): string;
15
+ declare function replaceTemplateName(template: string, name: string): string;
12
16
  //#endregion
13
- export { 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 };
17
+ export { 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 };
@@ -15,6 +15,12 @@ function filename_to_dts(id) {
15
15
  function filename_dts_to(id, ext) {
16
16
  return id.replace(RE_DTS, `.$1${ext}`);
17
17
  }
18
+ function resolveTemplateFn(fn, chunk) {
19
+ return typeof fn === "function" ? fn(chunk) : fn;
20
+ }
21
+ function replaceTemplateName(template, name) {
22
+ return template.replaceAll("[name]", name);
23
+ }
18
24
 
19
25
  //#endregion
20
- export { 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 };
26
+ export { 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 };
@@ -1,2 +1,2 @@
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 } from "./filename-DUAyqgqS.js";
2
- export { 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 };
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-BDKLOOY5.js";
2
+ export { 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 };
package/dist/filename.js CHANGED
@@ -1,3 +1,3 @@
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 } from "./filename-DtB5setL.js";
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
 
3
- export { 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 };
3
+ export { 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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-DUAyqgqS.js";
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
4
  import { Plugin } from "rolldown";
@@ -182,10 +182,9 @@ declare function resolveOptions({
182
182
  //#endregion
183
183
  //#region src/fake-js.d.ts
184
184
  declare function createFakeJsPlugin({
185
- dtsInput,
186
185
  sourcemap,
187
186
  cjsDefault
188
- }: Pick<OptionsResolved, "dtsInput" | "sourcemap" | "cjsDefault">): Plugin;
187
+ }: Pick<OptionsResolved, "sourcemap" | "cjsDefault">): Plugin;
189
188
  //#endregion
190
189
  //#region src/generate.d.ts
191
190
  declare function createGeneratePlugin({
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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 } from "./filename-DtB5setL.js";
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-BG0dlajy.js";
3
3
  import Debug from "debug";
4
4
  import _generate from "@babel/generator";
@@ -32,6 +32,15 @@ function createDtsInputPlugin() {
32
32
  return {
33
33
  ...options,
34
34
  entryFileNames(chunk) {
35
+ const { entryFileNames } = options;
36
+ if (entryFileNames) {
37
+ const nameTemplate = resolveTemplateFn(entryFileNames, chunk);
38
+ const renderedName = replaceTemplateName(nameTemplate, chunk.name);
39
+ if (RE_DTS.test(renderedName)) return nameTemplate;
40
+ const renderedNameWithD = replaceTemplateName(nameTemplate, `${chunk.name}.d`);
41
+ if (RE_DTS.test(renderedNameWithD)) return renderedNameWithD;
42
+ }
43
+ if (RE_DTS.test(chunk.name)) return chunk.name;
35
44
  if (chunk.name.endsWith(".d")) return "[name].ts";
36
45
  return "[name].d.ts";
37
46
  }
@@ -230,7 +239,7 @@ function walk(ast, { enter, leave }) {
230
239
  //#endregion
231
240
  //#region src/fake-js.ts
232
241
  const generate = _generate.default || _generate;
233
- function createFakeJsPlugin({ dtsInput, sourcemap, cjsDefault }) {
242
+ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
234
243
  let symbolIdx = 0;
235
244
  const identifierMap = Object.create(null);
236
245
  const symbolMap = /* @__PURE__ */ new Map();
@@ -240,14 +249,19 @@ function createFakeJsPlugin({ dtsInput, sourcemap, cjsDefault }) {
240
249
  name: "rolldown-plugin-dts:fake-js",
241
250
  outputOptions(options) {
242
251
  if (options.format === "cjs" || options.format === "commonjs") throw new Error("[rolldown-plugin-dts] Cannot bundle dts files with `cjs` format.");
252
+ const { chunkFileNames } = options;
243
253
  return {
244
254
  ...options,
245
255
  sourcemap: options.sourcemap || sourcemap,
246
- entryFileNames: options.entryFileNames ?? (dtsInput ? "[name].ts" : void 0),
247
256
  chunkFileNames(chunk) {
248
- const original = (typeof options.chunkFileNames === "function" ? options.chunkFileNames(chunk) : options.chunkFileNames) || "[name]-[hash].js";
249
- if (!original.includes(".d") && chunk.name.endsWith(".d")) return filename_js_to_dts(original).replace("[name]", chunk.name.slice(0, -2));
250
- return original;
257
+ const nameTemplate = resolveTemplateFn(chunkFileNames || "[name]-[hash].js", chunk);
258
+ if (chunk.name.endsWith(".d")) {
259
+ const renderedNameWithoutD = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name.slice(0, -2)));
260
+ if (RE_DTS.test(renderedNameWithoutD)) return renderedNameWithoutD;
261
+ const renderedName = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name));
262
+ if (RE_DTS.test(renderedName)) return renderedName;
263
+ }
264
+ return nameTemplate;
251
265
  }
252
266
  };
253
267
  },
@@ -692,10 +706,13 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
692
706
  return {
693
707
  ...options,
694
708
  entryFileNames(chunk) {
695
- const original = (typeof options.entryFileNames === "function" ? options.entryFileNames(chunk) : options.entryFileNames) || "[name].js";
696
- if (!chunk.name.endsWith(".d")) return original;
697
- if (RE_DTS.test(original)) return original.replace("[name]", chunk.name.slice(0, -2));
698
- return original.replace(RE_JS, ".$1ts");
709
+ const { entryFileNames } = options;
710
+ const nameTemplate = resolveTemplateFn(entryFileNames || "[name].js", chunk);
711
+ if (chunk.name.endsWith(".d")) {
712
+ if (RE_DTS.test(nameTemplate)) return replaceTemplateName(nameTemplate, chunk.name.slice(0, -2));
713
+ if (RE_JS.test(nameTemplate)) return nameTemplate.replace(RE_JS, ".$1ts");
714
+ }
715
+ return nameTemplate;
699
716
  }
700
717
  };
701
718
  },
@@ -923,7 +940,12 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
923
940
  let dtsResolution = resolver(id, importer);
924
941
  dtsResolution &&= path.normalize(dtsResolution);
925
942
  if (!dtsResolution || !RE_TS.test(dtsResolution) && !RE_VUE.test(dtsResolution)) {
926
- if (!rolldownResolution || !RE_TS.test(rolldownResolution.id) && !RE_VUE.test(rolldownResolution.id)) return external;
943
+ const unresolved = !rolldownResolution || !RE_TS.test(rolldownResolution.id) && !RE_VUE.test(rolldownResolution.id);
944
+ if (unresolved) {
945
+ const isRelativeOrAbsolute = id.startsWith(".") || path.isAbsolute(id);
946
+ if (isRelativeOrAbsolute) return this.error(`Cannot resolve import '${id}' from '${importer}'`);
947
+ return external;
948
+ }
927
949
  dtsResolution = rolldownResolution.id;
928
950
  }
929
951
  if (RE_NODE_MODULES.test(dtsResolution)) {
@@ -264,7 +264,12 @@ function tscEmit(tscOptions) {
264
264
  dtsCode = code;
265
265
  }
266
266
  }, void 0, true, { afterDeclarations: [stripPrivateFields] }, true);
267
- if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
267
+ const emitErrors = diagnostics.filter((d) => d.category === ts.DiagnosticCategory.Error);
268
+ if (emitErrors.length > 0) return { error: ts.formatDiagnostics(emitErrors, formatHost) };
269
+ if (emitSkipped) {
270
+ const errors = ts.getPreEmitDiagnostics(program).filter((d) => d.category === ts.DiagnosticCategory.Error);
271
+ if (errors.length > 0) return { error: ts.formatDiagnostics(errors, formatHost) };
272
+ }
268
273
  if (!dtsCode && file.isDeclarationFile) {
269
274
  debug("nothing was emitted. fallback to sourceFile text.");
270
275
  dtsCode = file.getFullText();
@@ -1,5 +1,5 @@
1
1
  import "./context-BG0dlajy.js";
2
- import { tscEmit } from "./tsc-BJW5IMTs.js";
2
+ import { tscEmit } from "./tsc-BLPzoCMq.js";
3
3
  import process from "node:process";
4
4
  import { createBirpc } from "birpc";
5
5
 
@@ -10,4 +10,5 @@ createBirpc(functions, {
10
10
  on: (fn) => process.on("message", fn)
11
11
  });
12
12
 
13
- //#endregion
13
+ //#endregion
14
+ export { };
package/dist/tsc.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./context-BG0dlajy.js";
2
- import { tscEmit } from "./tsc-BJW5IMTs.js";
2
+ import { tscEmit } from "./tsc-BLPzoCMq.js";
3
3
 
4
4
  export { tscEmit };
package/package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.15.6",
4
- "description": "A Rolldown plugin to bundle dts files",
3
+ "version": "0.15.8",
4
+ "description": "A Rolldown plugin to generate and bundle dts files.",
5
5
  "type": "module",
6
+ "keywords": [
7
+ "rolldown",
8
+ "plugin",
9
+ "dts",
10
+ "typescript",
11
+ "vue",
12
+ "jsdoc"
13
+ ],
6
14
  "license": "MIT",
7
15
  "homepage": "https://github.com/sxzz/rolldown-plugin-dts#readme",
8
16
  "bugs": {
@@ -49,38 +57,38 @@
49
57
  }
50
58
  },
51
59
  "dependencies": {
52
- "@babel/generator": "^7.28.0",
53
- "@babel/parser": "^7.28.0",
60
+ "@babel/generator": "^7.28.3",
61
+ "@babel/parser": "^7.28.3",
54
62
  "@babel/types": "^7.28.2",
55
- "ast-kit": "^2.1.1",
63
+ "ast-kit": "^2.1.2",
56
64
  "birpc": "^2.5.0",
57
65
  "debug": "^4.4.1",
58
- "dts-resolver": "^2.1.1",
66
+ "dts-resolver": "^2.1.2",
59
67
  "get-tsconfig": "^4.10.1"
60
68
  },
61
69
  "devDependencies": {
62
- "@sxzz/eslint-config": "^7.1.2",
63
- "@sxzz/prettier-config": "^2.2.3",
64
- "@sxzz/test-utils": "^0.5.9",
70
+ "@sxzz/eslint-config": "^7.1.4",
71
+ "@sxzz/prettier-config": "^2.2.4",
72
+ "@sxzz/test-utils": "^0.5.10",
65
73
  "@types/babel__generator": "^7.27.0",
66
74
  "@types/debug": "^4.1.12",
67
- "@types/node": "^24.2.0",
68
- "@typescript/native-preview": "7.0.0-dev.20250806.1",
69
- "@volar/typescript": "^2.4.22",
70
- "@vue/language-core": "^3.0.5",
71
- "bumpp": "^10.2.2",
75
+ "@types/node": "^24.3.0",
76
+ "@typescript/native-preview": "7.0.0-dev.20250824.1",
77
+ "@volar/typescript": "^2.4.23",
78
+ "@vue/language-core": "^3.0.6",
79
+ "bumpp": "^10.2.3",
72
80
  "diff": "^8.0.2",
73
- "eslint": "^9.32.0",
81
+ "eslint": "^9.34.0",
74
82
  "estree-walker": "^3.0.3",
75
83
  "prettier": "^3.6.2",
76
- "rolldown": "^1.0.0-beta.31",
77
- "rollup-plugin-dts": "^6.2.1",
84
+ "rolldown": "^1.0.0-beta.33",
85
+ "rollup-plugin-dts": "^6.2.3",
78
86
  "tinyglobby": "^0.2.14",
79
- "tsdown": "^0.13.3",
87
+ "tsdown": "^0.14.1",
80
88
  "typescript": "^5.9.2",
81
89
  "vitest": "^3.2.4",
82
- "vue": "^3.5.18",
83
- "vue-tsc": "^3.0.5"
90
+ "vue": "^3.5.19",
91
+ "vue-tsc": "^3.0.6"
84
92
  },
85
93
  "engines": {
86
94
  "node": ">=20.18.0"
@@ -94,6 +102,6 @@
94
102
  "test": "vitest",
95
103
  "typecheck": "tsc --noEmit",
96
104
  "format": "prettier --cache --write .",
97
- "release": "bumpp && pnpm publish"
105
+ "release": "bumpp && unotp pnpm publish"
98
106
  }
99
107
  }