rolldown-plugin-dts 0.9.11 → 0.10.1

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
@@ -264,24 +261,6 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
264
261
  }
265
262
  return {
266
263
  name: "rolldown-plugin-dts:fake-js",
267
- options: dtsInput ? (options) => {
268
- return {
269
- ...options,
270
- resolve: {
271
- extensions: [
272
- ".d.ts",
273
- ".d.mts",
274
- ".d.cts"
275
- ],
276
- extensionAlias: {
277
- ".js": [".d.ts"],
278
- ".mjs": [".d.mts"],
279
- ".cjs": [".d.cts"]
280
- },
281
- ...options.resolve
282
- }
283
- };
284
- } : void 0,
285
264
  outputOptions(options) {
286
265
  if (options.format === "cjs" || options.format === "commonjs") throw new Error("[rolldown-plugin-dts] Cannot bundle dts files with `cjs` format.");
287
266
  return {
@@ -857,70 +836,44 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
857
836
 
858
837
  //#endregion
859
838
  //#region src/resolve.ts
860
- 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
- }
839
+ function createDtsResolvePlugin({ tsconfig, resolve }) {
840
+ const resolver = createResolver({
841
+ tsconfig,
842
+ resolveNodeModules: !!resolve
843
+ });
879
844
  return {
880
845
  name: "rolldown-plugin-dts:resolve",
881
846
  resolveId: {
882
847
  order: "pre",
883
848
  async handler(id, importer, options) {
884
- if (!importer || !RE_DTS.test(importer) && !this.getModuleInfo(importer)?.meta.dtsFile) return;
849
+ const external = {
850
+ id,
851
+ external: true,
852
+ moduleSideEffects: false
853
+ };
854
+ if (!importer || !RE_DTS.test(importer)) return;
885
855
  if (RE_CSS.test(id)) return {
886
856
  id,
887
857
  external: true,
888
858
  moduleSideEffects: false
889
859
  };
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
- };
860
+ let resolution = resolver(id, importer);
861
+ if (!resolution || !RE_TS.test(resolution)) {
862
+ const result = await this.resolve(id, importer, options);
863
+ if (!result || !RE_TS.test(result.id)) return external;
864
+ resolution = result.id;
896
865
  }
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
- };
866
+ if (!RE_NODE_MODULES.test(importer) && RE_NODE_MODULES.test(resolution)) {
867
+ let shouldResolve;
868
+ if (typeof resolve === "boolean") shouldResolve = resolve;
869
+ else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
870
+ if (!shouldResolve) return external;
910
871
  }
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);
872
+ if (RE_TS.test(resolution) && !RE_DTS.test(resolution)) {
873
+ await Promise.any([this.load({ id: resolution }), new Promise((resolve$1) => setTimeout(resolve$1, 200))]);
874
+ resolution = filename_ts_to_dts(resolution);
919
875
  }
920
- if (RE_DTS.test(resolution.id)) return {
921
- ...resolution,
922
- meta
923
- };
876
+ if (RE_DTS.test(resolution)) return resolution;
924
877
  }
925
878
  }
926
879
  };
@@ -939,7 +892,7 @@ function dts(options = {}) {
939
892
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
940
893
  return plugins;
941
894
  }
942
- function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, resolvePaths }) {
895
+ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false }) {
943
896
  if (tsconfig === true || tsconfig == null) {
944
897
  const { config, path: path$1 } = getTsconfig(cwd) || {};
945
898
  tsconfig = path$1;
@@ -971,8 +924,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, i
971
924
  sourcemap,
972
925
  dtsInput,
973
926
  emitDtsOnly,
974
- resolve,
975
- resolvePaths: resolvePaths ?? !!compilerOptions?.paths
927
+ resolve
976
928
  };
977
929
  }
978
930
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.9.11",
3
+ "version": "0.10.1",
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
  },