rolldown-plugin-dts 0.9.10 → 0.10.0

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.ts CHANGED
@@ -63,12 +63,6 @@ interface Options {
63
63
  sourcemap?: boolean;
64
64
  /** Resolve external types used in dts files from `node_modules` */
65
65
  resolve?: boolean | (string | RegExp)[];
66
- /**
67
- * When `true`, the plugin will resolve `paths` in `tsconfig.json`.
68
- *
69
- * This option is enabled when `paths` is set in `compilerOptions`.
70
- */
71
- resolvePaths?: boolean;
72
66
  }
73
67
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
74
68
  type OptionsResolved = Overwrite<Required<Options>, {
@@ -84,8 +78,7 @@ declare function resolveOptions({
84
78
  sourcemap,
85
79
  dtsInput,
86
80
  emitDtsOnly,
87
- resolve,
88
- resolvePaths
81
+ resolve
89
82
  }: Options): OptionsResolved;
90
83
 
91
84
  //#endregion
package/dist/index.js CHANGED
@@ -239,9 +239,6 @@ function filename_ts_to_dts(id) {
239
239
  function filename_dts_to(id, ext) {
240
240
  return id.replace(RE_DTS, `.$1${ext}`);
241
241
  }
242
- function isRelative(id) {
243
- return path.isAbsolute(id) || id[0] === ".";
244
- }
245
242
 
246
243
  //#endregion
247
244
  //#region src/fake-js.ts
@@ -290,7 +287,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
290
287
  entryFileNames: options.entryFileNames ?? (dtsInput ? "[name].ts" : void 0),
291
288
  chunkFileNames(chunk) {
292
289
  const original = (typeof options.chunkFileNames === "function" ? options.chunkFileNames(chunk) : options.chunkFileNames) || "[name]-[hash].js";
293
- if (!original.includes(".d") && chunk.name.endsWith(".d")) return original.replace(RE_JS, ".$1ts");
290
+ if (!original.includes(".d") && chunk.name.endsWith(".d")) return filename_js_to_dts(original).replace("[name]", chunk.name.slice(0, -2));
294
291
  return original;
295
292
  }
296
293
  };
@@ -858,68 +855,47 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
858
855
  //#endregion
859
856
  //#region src/resolve.ts
860
857
  const meta = { dtsFile: true };
861
- function createDtsResolvePlugin({ tsconfig, resolve, resolvePaths }) {
862
- const resolver = createResolver({ tsconfig: tsconfig ? tsconfig : void 0 });
863
- function resolveDependency(id, importer) {
864
- let shouldResolve;
865
- if (typeof resolve === "boolean") shouldResolve = resolve;
866
- else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
867
- if (shouldResolve) {
868
- const resolution = resolver(id, importer);
869
- if (resolution) return {
870
- id: resolution,
871
- meta
872
- };
873
- } else return {
874
- id,
875
- external: true,
876
- meta
877
- };
878
- }
858
+ function createDtsResolvePlugin({ tsconfig, resolve }) {
859
+ const resolver = createResolver({
860
+ tsconfig,
861
+ resolveNodeModules: !!resolve
862
+ });
879
863
  return {
880
864
  name: "rolldown-plugin-dts:resolve",
881
865
  resolveId: {
882
866
  order: "pre",
883
867
  async handler(id, importer, options) {
868
+ const external = {
869
+ id,
870
+ external: true,
871
+ moduleSideEffects: false
872
+ };
884
873
  if (!importer || !RE_DTS.test(importer) && !this.getModuleInfo(importer)?.meta.dtsFile) return;
885
874
  if (RE_CSS.test(id)) return {
886
875
  id,
887
876
  external: true,
888
877
  moduleSideEffects: false
889
878
  };
890
- if (RE_NODE_MODULES.test(importer)) {
891
- const resolution$1 = resolver(id, importer);
892
- if (resolution$1) return {
893
- id: resolution$1,
894
- meta
895
- };
879
+ let resolution = resolver(id, importer);
880
+ if (!resolution || !RE_TS.test(resolution)) {
881
+ const result = await this.resolve(id, importer, options);
882
+ if (!result || !RE_TS.test(result.id)) return external;
883
+ resolution = result.id;
896
884
  }
897
- if (!resolvePaths && (RE_NODE_MODULES.test(id) || !isRelative(id))) return resolveDependency(id, importer);
898
- let resolution = await this.resolve(id, importer, options);
899
- if (!resolution && !id.endsWith(".d")) resolution = await this.resolve(`${id}.d`, importer, options);
900
- if (resolution?.id) {
901
- if (RE_CSS.test(resolution.id)) return {
902
- id,
903
- external: true,
904
- moduleSideEffects: false
905
- };
906
- if (resolution.id.startsWith("\0")) return {
907
- ...resolution,
908
- meta
909
- };
885
+ if (!RE_NODE_MODULES.test(importer) && RE_NODE_MODULES.test(resolution)) {
886
+ let shouldResolve;
887
+ if (typeof resolve === "boolean") shouldResolve = resolve;
888
+ else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
889
+ if (!shouldResolve) return external;
910
890
  }
911
- if (resolvePaths && (RE_NODE_MODULES.test(resolution?.id || id) || !isRelative(resolution?.id || id))) return resolveDependency(id, importer);
912
- if (!resolution || resolution.external) return resolution;
913
- if (RE_JS.test(resolution.id)) {
914
- resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, options);
915
- if (!resolution) return;
916
- } else if (RE_TS.test(resolution.id) && !RE_DTS.test(resolution.id)) {
917
- await Promise.any([this.load(resolution), new Promise((resolve$1) => setTimeout(resolve$1, 200))]);
918
- resolution.id = filename_ts_to_dts(resolution.id);
891
+ if (RE_TS.test(resolution) && !RE_DTS.test(resolution)) {
892
+ await Promise.any([this.load({ id: resolution }), new Promise((resolve$1) => setTimeout(resolve$1, 200))]);
893
+ resolution = filename_ts_to_dts(resolution);
919
894
  }
920
- if (RE_DTS.test(resolution.id)) return {
921
- ...resolution,
922
- meta
895
+ if (RE_DTS.test(resolution)) return {
896
+ id: resolution,
897
+ meta,
898
+ moduleSideEffects: false
923
899
  };
924
900
  }
925
901
  }
@@ -939,7 +915,7 @@ function dts(options = {}) {
939
915
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
940
916
  return plugins;
941
917
  }
942
- function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, resolvePaths }) {
918
+ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false }) {
943
919
  if (tsconfig === true || tsconfig == null) {
944
920
  const { config, path: path$1 } = getTsconfig(cwd) || {};
945
921
  tsconfig = path$1;
@@ -971,8 +947,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, i
971
947
  sourcemap,
972
948
  dtsInput,
973
949
  emitDtsOnly,
974
- resolve,
975
- resolvePaths: resolvePaths ?? !!compilerOptions?.paths
950
+ resolve
976
951
  };
977
952
  }
978
953
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.9.10",
3
+ "version": "0.10.0",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "@babel/types": "^7.27.1",
43
43
  "ast-kit": "^1.4.3",
44
44
  "debug": "^4.4.0",
45
- "dts-resolver": "^1.0.1",
45
+ "dts-resolver": "^1.1.0",
46
46
  "get-tsconfig": "^4.10.0",
47
47
  "oxc-transform": "^0.67.0"
48
48
  },