rolldown-plugin-dts 0.23.0 → 0.23.2

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/dist/index.d.mts CHANGED
@@ -4,6 +4,20 @@ import { TsConfigJson } from "get-tsconfig";
4
4
 
5
5
  //#region src/options.d.ts
6
6
  interface GeneralOptions {
7
+ /**
8
+ * Glob pattern(s) to filter which entry files get `.d.ts` generation.
9
+ *
10
+ * When specified, only entry files matching these patterns will emit `.d.ts` chunks.
11
+ * When not specified, all entries get `.d.ts` generation.
12
+ *
13
+ * Supports negation patterns (e.g., `['**', '!src/icons/**']`) for exclusion.
14
+ * Patterns are matched against file paths relative to `cwd`.
15
+ *
16
+ * @example
17
+ * entry: 'src/index.ts'
18
+ * entry: ['src/*.ts', '!src/internal/**']
19
+ */
20
+ entry?: string | string[];
7
21
  /**
8
22
  * The directory in which the plugin will search for the `tsconfig.json` file.
9
23
  */
@@ -188,12 +202,14 @@ interface TsgoOptions {
188
202
  }
189
203
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
190
204
  type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
205
+ entry?: string[];
191
206
  tsconfig?: string;
192
207
  oxc: IsolatedDeclarationsOptions | false;
193
208
  tsconfigRaw: TsConfigJson;
194
209
  tsgo: Omit<TsgoOptions, "enabled"> | false;
195
210
  }>;
196
211
  declare function resolveOptions({
212
+ entry,
197
213
  cwd,
198
214
  dtsInput,
199
215
  emitDtsOnly,
@@ -225,6 +241,7 @@ declare function createFakeJsPlugin({
225
241
  //#endregion
226
242
  //#region src/generate.d.ts
227
243
  declare function createGeneratePlugin({
244
+ entry,
228
245
  tsconfig,
229
246
  tsconfigRaw,
230
247
  build,
@@ -240,7 +257,7 @@ declare function createGeneratePlugin({
240
257
  newContext,
241
258
  emitJs,
242
259
  sourcemap
243
- }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
260
+ }: Pick<OptionsResolved, "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
244
261
  //#endregion
245
262
  //#region src/index.d.ts
246
263
  declare function dts(options?: Options): Plugin[];
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+ const __cjs_require = __cjs_createRequire(import.meta.url);
1
3
  import { a as RE_JSON, c as RE_TS, d as filename_js_to_dts, f as filename_to_dts, i as RE_JS, l as RE_VUE, m as resolveTemplateFn, n as RE_DTS, o as RE_NODE_MODULES, p as replaceTemplateName, r as RE_DTS_MAP, s as RE_ROLLDOWN_RUNTIME, t as RE_CSS, u as filename_dts_to } from "./filename-DQnUJlio.mjs";
2
4
  import { createContext, globalContext, invalidateContextFile } from "./tsc-context.mjs";
3
5
  import { createDebug } from "obug";
@@ -11,6 +13,7 @@ import { fork, spawn } from "node:child_process";
11
13
  import { existsSync } from "node:fs";
12
14
  import { mkdtemp, readFile, rm } from "node:fs/promises";
13
15
  import path from "node:path";
16
+ const picomatch = __cjs_require("picomatch");
14
17
  import { ResolverFactory, isolatedDeclarationSync } from "rolldown/experimental";
15
18
  import { tmpdir } from "node:os";
16
19
  import process from "node:process";
@@ -94,12 +97,17 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
94
97
  }
95
98
  };
96
99
  function transform(code, id) {
97
- const file = parse(code, {
98
- plugins: [["typescript", { dts: true }], "decoratorAutoAccessors"],
99
- sourceType: "module",
100
- errorRecovery: true,
101
- createParenthesizedExpressions: true
102
- });
100
+ let file;
101
+ try {
102
+ file = parse(code, {
103
+ plugins: [["typescript", { dts: true }], "decoratorAutoAccessors"],
104
+ sourceType: "module",
105
+ errorRecovery: true,
106
+ createParenthesizedExpressions: true
107
+ });
108
+ } catch (error) {
109
+ throw new Error(`Failed to parse ${id}. This may be caused by a syntax error in the declaration file or a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
110
+ }
103
111
  const { program, comments } = file;
104
112
  const typeOnlyIds = [];
105
113
  const identifierMap = Object.create(null);
@@ -216,7 +224,12 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
216
224
  const ids = typeOnlyMap.get(module);
217
225
  if (ids) typeOnlyIds.push(...ids);
218
226
  }
219
- const file = parse(code, { sourceType: "module" });
227
+ let file;
228
+ try {
229
+ file = parse(code, { sourceType: "module" });
230
+ } catch (error) {
231
+ throw new Error(`Failed to parse generated code for chunk ${chunk.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
232
+ }
220
233
  const { program } = file;
221
234
  program.body = patchTsNamespace(program.body);
222
235
  program.body = patchReExport(program.body);
@@ -391,7 +404,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
391
404
  }
392
405
  function importNamespace(node, imported, source, namespaceStmts, identifierMap) {
393
406
  const sourceText = source.value.replaceAll(/\W/g, "_");
394
- const localName = isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`;
407
+ const localName = `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`;
395
408
  let local = t.identifier(localName);
396
409
  if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
397
410
  else namespaceStmts.set(source.value, {
@@ -680,7 +693,8 @@ async function runTsgo(rootDir, tsconfig, sourcemap, tsgoPath) {
680
693
  //#region src/generate.ts
681
694
  const debug$2 = createDebug("rolldown-plugin-dts:generate");
682
695
  const WORKER_URL = "./tsc-worker.mjs";
683
- function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
696
+ function createGeneratePlugin({ entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }) {
697
+ const entryMatcher = entry ? picomatch(entry, { ignore: entry.filter((p) => p.startsWith("!")).map((p) => p.slice(1)) }) : void 0;
684
698
  const dtsMap = /* @__PURE__ */ new Map();
685
699
  /**
686
700
  * A map of input id to output file name
@@ -758,7 +772,8 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, build, incremental, cwd,
758
772
  } },
759
773
  handler(code, id) {
760
774
  if (!RE_JS.test(id) || emitJs) {
761
- const isEntry = !!this.getModuleInfo(id)?.isEntry;
775
+ const mod = this.getModuleInfo(id);
776
+ const isEntry = entryMatcher ? entryMatcher(path.relative(cwd, id)) : !!mod?.isEntry;
762
777
  const dtsId = filename_to_dts(id);
763
778
  dtsMap.set(dtsId, {
764
779
  code,
@@ -917,7 +932,7 @@ function collectJsonExports(code) {
917
932
  //#endregion
918
933
  //#region src/options.ts
919
934
  let warnedTsgo = false;
920
- function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
935
+ function resolveOptions({ entry, cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo = false }) {
921
936
  if (tsgo === true) tsgo = {};
922
937
  else if (typeof tsgo === "object" && tsgo.enabled === false) tsgo = false;
923
938
  let resolvedTsconfig;
@@ -960,6 +975,7 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
960
975
  warnedTsgo = true;
961
976
  }
962
977
  return {
978
+ entry: entry ? Array.isArray(entry) ? entry : [entry] : void 0,
963
979
  cwd,
964
980
  dtsInput,
965
981
  emitDtsOnly,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
3
  "type": "module",
4
- "version": "0.23.0",
4
+ "version": "0.23.2",
5
5
  "description": "A Rolldown plugin to generate and bundle dts files.",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -70,15 +70,17 @@
70
70
  "birpc": "^4.0.0",
71
71
  "dts-resolver": "^2.1.3",
72
72
  "get-tsconfig": "^4.13.7",
73
- "obug": "^2.1.1"
73
+ "obug": "^2.1.1",
74
+ "picomatch": "^4.0.4"
74
75
  },
75
76
  "devDependencies": {
76
77
  "@jridgewell/source-map": "^0.3.11",
77
- "@sxzz/eslint-config": "^7.8.3",
78
+ "@sxzz/eslint-config": "^7.8.4",
78
79
  "@sxzz/prettier-config": "^2.3.1",
79
- "@sxzz/test-utils": "^0.5.15",
80
+ "@sxzz/test-utils": "^0.5.16",
80
81
  "@types/node": "^25.5.0",
81
- "@typescript/native-preview": "7.0.0-dev.20260325.1",
82
+ "@types/picomatch": "^4.0.2",
83
+ "@typescript/native-preview": "7.0.0-dev.20260328.1",
82
84
  "@volar/typescript": "^2.4.28",
83
85
  "@vue/language-core": "^3.2.6",
84
86
  "arktype": "^2.2.0",
@@ -91,9 +93,9 @@
91
93
  "rolldown-plugin-require-cjs": "^0.4.0",
92
94
  "rollup-plugin-dts": "^6.4.1",
93
95
  "tinyglobby": "^0.2.15",
94
- "tsdown": "^0.21.5",
96
+ "tsdown": "^0.21.6",
95
97
  "typescript": "^6.0.2",
96
- "vitest": "^4.1.1",
98
+ "vitest": "^4.1.2",
97
99
  "vue": "^3.5.31",
98
100
  "vue-tsc": "^3.2.6",
99
101
  "zod": "^4.3.6"