rolldown-plugin-dts 0.9.4 → 0.9.5

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,6 +63,12 @@ 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;
66
72
  }
67
73
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
68
74
  type OptionsResolved = Overwrite<Required<Options>, {
@@ -78,7 +84,8 @@ declare function resolveOptions({
78
84
  sourcemap,
79
85
  dtsInput,
80
86
  emitDtsOnly,
81
- resolve
87
+ resolve,
88
+ resolvePaths
82
89
  }: Options): OptionsResolved;
83
90
 
84
91
  //#endregion
package/dist/index.js CHANGED
@@ -853,8 +853,24 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
853
853
  //#endregion
854
854
  //#region src/resolve.ts
855
855
  const meta = { dtsFile: true };
856
- function createDtsResolvePlugin({ tsconfig, resolve }) {
856
+ function createDtsResolvePlugin({ tsconfig, resolve, resolvePaths }) {
857
857
  const resolver = createResolver({ tsconfig: tsconfig ? tsconfig : void 0 });
858
+ function resolveDependency(id, importer) {
859
+ let shouldResolve;
860
+ if (typeof resolve === "boolean") shouldResolve = resolve;
861
+ else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
862
+ if (shouldResolve) {
863
+ const resolution = resolver(id, importer);
864
+ if (resolution) return {
865
+ id: resolution,
866
+ meta
867
+ };
868
+ } else return {
869
+ id,
870
+ external: true,
871
+ meta
872
+ };
873
+ }
858
874
  return {
859
875
  name: "rolldown-plugin-dts:resolve",
860
876
  resolveId: {
@@ -868,28 +884,14 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
868
884
  meta
869
885
  };
870
886
  }
887
+ if (!resolvePaths && (RE_NODE_MODULES.test(id) || !isRelative(id))) return resolveDependency(id, importer);
871
888
  let resolution = await this.resolve(id, importer, options);
872
889
  if (!resolution && !id.endsWith(".d")) resolution = await this.resolve(`${id}.d`, importer, options);
873
890
  if (resolution?.id.startsWith("\0")) return {
874
891
  ...resolution,
875
892
  meta
876
893
  };
877
- if (RE_NODE_MODULES.test(resolution?.id || id) || !isRelative(resolution?.id || id)) {
878
- let shouldResolve;
879
- if (typeof resolve === "boolean") shouldResolve = resolve;
880
- else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
881
- if (shouldResolve) {
882
- const resolution$1 = resolver(id, importer);
883
- if (resolution$1) return {
884
- id: resolution$1,
885
- meta
886
- };
887
- } else return {
888
- id,
889
- external: true,
890
- meta
891
- };
892
- }
894
+ if (resolvePaths && (RE_NODE_MODULES.test(resolution?.id || id) || !isRelative(resolution?.id || id))) return resolveDependency(resolution?.id || id, importer);
893
895
  if (!resolution || resolution.external) return resolution;
894
896
  if (RE_JS.test(resolution.id)) {
895
897
  resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, options);
@@ -920,7 +922,7 @@ function dts(options = {}) {
920
922
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
921
923
  return plugins;
922
924
  }
923
- function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false }) {
925
+ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, resolvePaths }) {
924
926
  if (tsconfig === true || tsconfig == null) {
925
927
  const { config, path: path$1 } = getTsconfig(cwd) || {};
926
928
  tsconfig = path$1;
@@ -952,7 +954,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, i
952
954
  sourcemap,
953
955
  dtsInput,
954
956
  emitDtsOnly,
955
- resolve
957
+ resolve,
958
+ resolvePaths: resolvePaths ?? !!compilerOptions?.paths
956
959
  };
957
960
  }
958
961
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",