rolldown-plugin-dts 0.15.6 → 0.15.7

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";
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
  }
@@ -240,14 +249,20 @@ 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
256
  entryFileNames: options.entryFileNames ?? (dtsInput ? "[name].ts" : void 0),
247
257
  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;
258
+ const nameTemplate = resolveTemplateFn(chunkFileNames || "[name]-[hash].js", chunk);
259
+ if (chunk.name.endsWith(".d")) {
260
+ const renderedNameWithoutD = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name.slice(0, -2)));
261
+ if (RE_DTS.test(renderedNameWithoutD)) return renderedNameWithoutD;
262
+ const renderedName = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name));
263
+ if (RE_DTS.test(renderedName)) return renderedName;
264
+ }
265
+ return nameTemplate;
251
266
  }
252
267
  };
253
268
  },
@@ -692,10 +707,10 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
692
707
  return {
693
708
  ...options,
694
709
  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");
710
+ const { entryFileNames } = options;
711
+ const nameTemplate = (typeof entryFileNames === "function" ? entryFileNames(chunk) : entryFileNames) || "[name].js";
712
+ if (chunk.name.endsWith(".d") && RE_JS.test(nameTemplate)) return nameTemplate.replace(RE_JS, ".$1ts");
713
+ return nameTemplate;
699
714
  }
700
715
  };
701
716
  },
@@ -923,7 +938,12 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
923
938
  let dtsResolution = resolver(id, importer);
924
939
  dtsResolution &&= path.normalize(dtsResolution);
925
940
  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;
941
+ const unresolved = !rolldownResolution || !RE_TS.test(rolldownResolution.id) && !RE_VUE.test(rolldownResolution.id);
942
+ if (unresolved) {
943
+ const isRelativeOrAbsolute = id.startsWith(".") || path.isAbsolute(id);
944
+ if (isRelativeOrAbsolute) return this.error(`Cannot resolve import '${id}' from '${importer}'`);
945
+ return external;
946
+ }
927
947
  dtsResolution = rolldownResolution.id;
928
948
  }
929
949
  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.7",
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
66
  "dts-resolver": "^2.1.1",
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.20250820.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.33.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
90
  "vue": "^3.5.18",
83
- "vue-tsc": "^3.0.5"
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
  }