rolldown-plugin-dts 0.14.2 → 0.14.3

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
@@ -158,6 +158,15 @@ guaranteeing that all type definitions are generated from scratch.
158
158
 
159
159
  ---
160
160
 
161
+ ### emitJs
162
+
163
+ If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
164
+ This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
165
+
166
+ Enabled by default when `allowJs` in compilerOptions is `true`.
167
+
168
+ ---
169
+
161
170
  ### tsgo
162
171
 
163
172
  **[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
@@ -7,8 +7,8 @@ declare const RE_NODE_MODULES: RegExp;
7
7
  declare const RE_CSS: RegExp;
8
8
  declare const RE_VUE: RegExp;
9
9
  declare function filename_js_to_dts(id: string): string;
10
- declare function filename_ts_to_dts(id: string): string;
10
+ declare function filename_to_dts(id: string): string;
11
11
  declare function filename_dts_to(id: string, ext: "js" | "ts"): string;
12
12
  declare function isRelative(id: string): boolean;
13
13
  //#endregion
14
- 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_ts_to_dts, isRelative };
14
+ 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, isRelative };
@@ -11,8 +11,8 @@ const RE_VUE = /\.vue$/;
11
11
  function filename_js_to_dts(id) {
12
12
  return id.replace(RE_JS, ".d.$1ts");
13
13
  }
14
- function filename_ts_to_dts(id) {
15
- return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts");
14
+ function filename_to_dts(id) {
15
+ return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts");
16
16
  }
17
17
  function filename_dts_to(id, ext) {
18
18
  return id.replace(RE_DTS, `.$1${ext}`);
@@ -22,4 +22,4 @@ function isRelative(id) {
22
22
  }
23
23
 
24
24
  //#endregion
25
- 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_ts_to_dts, isRelative };
25
+ 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, isRelative };
@@ -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_ts_to_dts, isRelative } from "./filename-TbnZq0n4.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_ts_to_dts, isRelative };
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, isRelative } from "./filename-4MoswV50.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, isRelative };
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_ts_to_dts, isRelative } from "./filename-Dpr2dKWZ.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, isRelative } from "./filename-Dz6Li3gj.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_ts_to_dts, isRelative };
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, isRelative };
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-TbnZq0n4.js";
1
+ import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-4MoswV50.js";
2
2
  import { TscContext, createContext } from "./index-B4kTNEjT.js";
3
3
  import { IsolatedDeclarationsOptions } from "rolldown/experimental";
4
4
  import { TsConfigJson } from "get-tsconfig";
@@ -120,9 +120,16 @@ interface Options {
120
120
  * to speed up repeated builds. Enabling this option forces a clean context,
121
121
  * guaranteeing that all type definitions are generated from scratch.
122
122
  *
123
- * **Default:** `false`
123
+ * @default false
124
124
  */
125
125
  newContext?: boolean;
126
+ /**
127
+ * If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
128
+ * This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
129
+ *
130
+ * Enabled by default when `allowJs` in compilerOptions is `true`.
131
+ */
132
+ emitJs?: boolean;
126
133
  }
127
134
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
128
135
  type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
@@ -145,7 +152,8 @@ declare function resolveOptions({
145
152
  parallel,
146
153
  eager,
147
154
  tsgo,
148
- newContext
155
+ newContext,
156
+ emitJs
149
157
  }: Options): OptionsResolved;
150
158
  //#endregion
151
159
  //#region src/fake-js.d.ts
@@ -166,8 +174,9 @@ declare function createGeneratePlugin({
166
174
  parallel,
167
175
  eager,
168
176
  tsgo,
169
- newContext
170
- }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext">): Plugin;
177
+ newContext,
178
+ emitJs
179
+ }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs">): Plugin;
171
180
  //#endregion
172
181
  //#region src/index.d.ts
173
182
  declare function dts(options?: Options): Plugin[];
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_ts_to_dts } from "./filename-Dpr2dKWZ.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 } from "./filename-Dz6Li3gj.js";
2
2
  import { createContext } from "./tsc-Czx4mPt7.js";
3
3
  import path from "node:path";
4
4
  import Debug from "debug";
@@ -640,7 +640,7 @@ const spawnAsync = (...args) => new Promise((resolve, reject) => {
640
640
  child.on("close", () => resolve());
641
641
  child.on("error", (error) => reject(error));
642
642
  });
643
- function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo, newContext }) {
643
+ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo, newContext, emitJs }) {
644
644
  const dtsMap = /* @__PURE__ */ new Map();
645
645
  /**
646
646
  * A map of input id to output file name
@@ -701,13 +701,17 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
701
701
  transform: {
702
702
  order: "pre",
703
703
  filter: { id: {
704
- include: [RE_TS, RE_VUE],
704
+ include: [
705
+ RE_TS,
706
+ RE_VUE,
707
+ ...emitJs ? [RE_JS] : []
708
+ ],
705
709
  exclude: [RE_DTS, RE_NODE_MODULES]
706
710
  } },
707
711
  handler(code, id) {
708
712
  const mod = this.getModuleInfo(id);
709
713
  const isEntry = !!mod?.isEntry;
710
- const dtsId = filename_ts_to_dts(id);
714
+ const dtsId = filename_to_dts(id);
711
715
  dtsMap.set(dtsId, {
712
716
  code,
713
717
  id,
@@ -738,7 +742,7 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
738
742
  debug$1("generate dts %s from %s", dtsId, id);
739
743
  if (tsgo) {
740
744
  if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
741
- const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(cwd), filename_ts_to_dts(id)));
745
+ const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(cwd), filename_to_dts(id)));
742
746
  if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
743
747
  else {
744
748
  debug$1("[tsgo]", dtsPath, "is missing");
@@ -822,7 +826,7 @@ async function runTsgo(root, tsconfig) {
822
826
  //#endregion
823
827
  //#region src/options.ts
824
828
  let warnedTsgo = false;
825
- function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false, newContext = false }) {
829
+ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false, newContext = false, emitJs }) {
826
830
  let resolvedTsconfig;
827
831
  if (tsconfig === true || tsconfig == null) {
828
832
  const { config, path: path$1 } = getTsconfig(cwd) || {};
@@ -850,6 +854,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
850
854
  isolatedDeclarations.stripInternal ??= !!compilerOptions?.stripInternal;
851
855
  isolatedDeclarations.sourcemap = !!compilerOptions.declarationMap;
852
856
  }
857
+ emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
853
858
  if (tsgo && !warnedTsgo) {
854
859
  console.warn("The `tsgo` option is experimental and may change in the future.");
855
860
  warnedTsgo = true;
@@ -868,7 +873,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
868
873
  parallel,
869
874
  eager,
870
875
  tsgo,
871
- newContext
876
+ newContext,
877
+ emitJs
872
878
  };
873
879
  }
874
880
 
@@ -911,7 +917,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
911
917
  }
912
918
  if (RE_TS.test(resolution) && !RE_DTS.test(resolution) || RE_VUE.test(resolution)) {
913
919
  await this.load({ id: resolution });
914
- resolution = filename_ts_to_dts(resolution);
920
+ resolution = filename_to_dts(resolution);
915
921
  }
916
922
  if (RE_DTS.test(resolution)) return resolution;
917
923
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -56,13 +56,13 @@
56
56
  "get-tsconfig": "^4.10.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@sxzz/eslint-config": "^7.1.0",
59
+ "@sxzz/eslint-config": "^7.1.1",
60
60
  "@sxzz/prettier-config": "^2.2.3",
61
- "@sxzz/test-utils": "^0.5.7",
61
+ "@sxzz/test-utils": "^0.5.8",
62
62
  "@types/babel__generator": "^7.27.0",
63
63
  "@types/debug": "^4.1.12",
64
64
  "@types/node": "^24.1.0",
65
- "@typescript/native-preview": "7.0.0-dev.20250728.1",
65
+ "@typescript/native-preview": "7.0.0-dev.20250731.1",
66
66
  "@volar/typescript": "^2.4.22",
67
67
  "@vue/language-core": "^3.0.4",
68
68
  "bumpp": "^10.2.1",
@@ -70,7 +70,7 @@
70
70
  "eslint": "^9.32.0",
71
71
  "estree-walker": "^3.0.3",
72
72
  "prettier": "^3.6.2",
73
- "rolldown": "^1.0.0-beta.29",
73
+ "rolldown": "^1.0.0-beta.30",
74
74
  "rollup-plugin-dts": "^6.2.1",
75
75
  "tinyglobby": "^0.2.14",
76
76
  "tsdown": "^0.13.0",