rolldown-plugin-dts 0.15.9 → 0.15.10

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
@@ -83,10 +83,13 @@ If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` f
83
83
 
84
84
  #### `resolve`
85
85
 
86
- Resolve external types used in `.d.ts` files from `node_modules`.
86
+ Controls whether type definitions from `node_modules` are bundled into your final `.d.ts` file or kept as external `import` statements.
87
87
 
88
- - If `true`, all external types are resolved.
89
- - If an array, only types matching the provided strings or regular expressions are resolved.
88
+ By default, dependencies are external, resulting in `import { Type } from 'some-package'`. When bundled, this `import` is removed, and the type definitions from `some-package` are copied directly into your file.
89
+
90
+ - `true`: Bundles all dependencies.
91
+ - `false`: (Default) Keeps all dependencies external.
92
+ - `(string | RegExp)[]`: Bundles only dependencies matching the provided strings or regular expressions (e.g. `['pkg-a', /^@scope\//]`).
90
93
 
91
94
  #### `cjsDefault`
92
95
 
package/dist/index.d.ts CHANGED
@@ -47,7 +47,13 @@ interface GeneralOptions {
47
47
  */
48
48
  sourcemap?: boolean;
49
49
  /**
50
- * Resolve external types used in `.d.ts` files from `node_modules`.
50
+ * Controls whether type definitions from `node_modules` are bundled into your final `.d.ts` file or kept as external `import` statements.
51
+ *
52
+ * By default, dependencies are external, resulting in `import { Type } from 'some-package'`. When bundled, this `import` is removed, and the type definitions from `some-package` are copied directly into your file.
53
+
54
+ * - `true`: Bundles all dependencies.
55
+ * - `false`: (Default) Keeps all dependencies external.
56
+ * - `(string | RegExp)[]`: Bundles only dependencies matching the provided strings or regular expressions (e.g. `['pkg-a', /^@scope\//]`).
51
57
  */
52
58
  resolve?: boolean | (string | RegExp)[];
53
59
  /**
package/dist/index.js CHANGED
@@ -385,6 +385,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault }) {
385
385
  program.body = patchTsNamespace(program.body);
386
386
  program.body = program.body.map((node) => {
387
387
  if (isHelperImport(node)) return null;
388
+ if (node.type === "ExpressionStatement") return null;
388
389
  const newNode = patchImportExport(node, typeOnlyIds, cjsDefault);
389
390
  if (newNode) return newNode;
390
391
  if (node.type !== "VariableDeclaration") return node;
@@ -919,11 +920,25 @@ function resolveOptions({ cwd = process.cwd(), dtsInput = false, emitDtsOnly = f
919
920
  //#endregion
920
921
  //#region src/resolver.ts
921
922
  function createDtsResolvePlugin({ tsconfig, resolve }) {
922
- const resolver = createResolver({
923
+ const isSourceFile = (p) => RE_TS.test(p) || RE_VUE.test(p);
924
+ const shouldBundleNodeModule = (id) => {
925
+ if (typeof resolve === "boolean") return resolve;
926
+ return resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
927
+ };
928
+ const baseDtsResolver = createResolver({
923
929
  tsconfig,
924
930
  resolveNodeModules: !!resolve,
925
931
  ResolverFactory
926
932
  });
933
+ const resolveDtsPath = (id, importer, rolldownResolution) => {
934
+ let dtsPath = baseDtsResolver(id, importer);
935
+ if (dtsPath) dtsPath = path.normalize(dtsPath);
936
+ if (!dtsPath || !isSourceFile(dtsPath)) {
937
+ if (rolldownResolution && isSourceFile(rolldownResolution.id)) return rolldownResolution.id;
938
+ return null;
939
+ }
940
+ return dtsPath;
941
+ };
927
942
  return {
928
943
  name: "rolldown-plugin-dts:resolver",
929
944
  resolveId: {
@@ -937,30 +952,17 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
937
952
  if (!importer || !RE_DTS.test(importer)) return;
938
953
  if (RE_CSS.test(id)) return external;
939
954
  const rolldownResolution = await this.resolve(id, importer, options);
940
- let dtsResolution = resolver(id, importer);
941
- dtsResolution &&= path.normalize(dtsResolution);
942
- if (!dtsResolution || !RE_TS.test(dtsResolution) && !RE_VUE.test(dtsResolution)) {
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
- }
949
- dtsResolution = rolldownResolution.id;
955
+ const dtsResolution = resolveDtsPath(id, importer, rolldownResolution);
956
+ if (!dtsResolution) {
957
+ const isFileImport = id.startsWith(".") || path.isAbsolute(id);
958
+ return isFileImport ? null : external;
950
959
  }
951
- if (RE_NODE_MODULES.test(dtsResolution)) {
952
- let shouldResolve;
953
- if (typeof resolve === "boolean") shouldResolve = resolve;
954
- else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
955
- if (!shouldResolve) if (RE_NODE_MODULES.test(importer)) {
956
- if (rolldownResolution?.external) return external;
957
- } else return external;
958
- }
959
- if (RE_TS.test(dtsResolution) && !RE_DTS.test(dtsResolution) || RE_VUE.test(dtsResolution)) {
960
+ if (RE_NODE_MODULES.test(dtsResolution) && !shouldBundleNodeModule(id) && (!RE_NODE_MODULES.test(importer) || rolldownResolution?.external)) return external;
961
+ if (RE_DTS.test(dtsResolution)) return dtsResolution;
962
+ if (isSourceFile(dtsResolution)) {
960
963
  await this.load({ id: dtsResolution });
961
- dtsResolution = filename_to_dts(dtsResolution);
964
+ return filename_to_dts(dtsResolution);
962
965
  }
963
- if (RE_DTS.test(dtsResolution)) return dtsResolution;
964
966
  }
965
967
  }
966
968
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.15.9",
3
+ "version": "0.15.10",
4
4
  "description": "A Rolldown plugin to generate and bundle dts files.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -73,7 +73,7 @@
73
73
  "@types/babel__generator": "^7.27.0",
74
74
  "@types/debug": "^4.1.12",
75
75
  "@types/node": "^24.3.0",
76
- "@typescript/native-preview": "7.0.0-dev.20250824.1",
76
+ "@typescript/native-preview": "7.0.0-dev.20250826.1",
77
77
  "@volar/typescript": "^2.4.23",
78
78
  "@vue/language-core": "^3.0.6",
79
79
  "bumpp": "^10.2.3",
@@ -81,13 +81,13 @@
81
81
  "eslint": "^9.34.0",
82
82
  "estree-walker": "^3.0.3",
83
83
  "prettier": "^3.6.2",
84
- "rolldown": "^1.0.0-beta.33",
84
+ "rolldown": "^1.0.0-beta.34",
85
85
  "rollup-plugin-dts": "^6.2.3",
86
86
  "tinyglobby": "^0.2.14",
87
- "tsdown": "^0.14.1",
87
+ "tsdown": "^0.14.2",
88
88
  "typescript": "^5.9.2",
89
89
  "vitest": "^3.2.4",
90
- "vue": "^3.5.19",
90
+ "vue": "^3.5.20",
91
91
  "vue-tsc": "^3.0.6"
92
92
  },
93
93
  "engines": {