rolldown-plugin-dts 0.9.4 → 0.9.6

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
@@ -587,7 +587,8 @@ function rewriteImportExport(node, set) {
587
587
  return false;
588
588
  }
589
589
  function importNamespace(node, imported, source, getIdentifierIndex, prepend) {
590
- let local = t.identifier(`_${getIdentifierIndex()}`);
590
+ const sourceText = source.value.replaceAll(/\W/g, "_");
591
+ let local = t.identifier(`${sourceText}${getIdentifierIndex()}`);
591
592
  prepend(t.importDeclaration([t.importNamespaceSpecifier(local)], source));
592
593
  if (imported) {
593
594
  const importedLeft = getIdFromTSEntityName(imported);
@@ -853,8 +854,24 @@ function createGeneratePlugin({ compilerOptions = {}, isolatedDeclarations, emit
853
854
  //#endregion
854
855
  //#region src/resolve.ts
855
856
  const meta = { dtsFile: true };
856
- function createDtsResolvePlugin({ tsconfig, resolve }) {
857
+ function createDtsResolvePlugin({ tsconfig, resolve, resolvePaths }) {
857
858
  const resolver = createResolver({ tsconfig: tsconfig ? tsconfig : void 0 });
859
+ function resolveDependency(id, importer) {
860
+ let shouldResolve;
861
+ if (typeof resolve === "boolean") shouldResolve = resolve;
862
+ else shouldResolve = resolve.some((pattern) => typeof pattern === "string" ? id === pattern : pattern.test(id));
863
+ if (shouldResolve) {
864
+ const resolution = resolver(id, importer);
865
+ if (resolution) return {
866
+ id: resolution,
867
+ meta
868
+ };
869
+ } else return {
870
+ id,
871
+ external: true,
872
+ meta
873
+ };
874
+ }
858
875
  return {
859
876
  name: "rolldown-plugin-dts:resolve",
860
877
  resolveId: {
@@ -868,28 +885,14 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
868
885
  meta
869
886
  };
870
887
  }
888
+ if (!resolvePaths && (RE_NODE_MODULES.test(id) || !isRelative(id))) return resolveDependency(id, importer);
871
889
  let resolution = await this.resolve(id, importer, options);
872
890
  if (!resolution && !id.endsWith(".d")) resolution = await this.resolve(`${id}.d`, importer, options);
873
891
  if (resolution?.id.startsWith("\0")) return {
874
892
  ...resolution,
875
893
  meta
876
894
  };
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
- }
895
+ if (resolvePaths && (RE_NODE_MODULES.test(resolution?.id || id) || !isRelative(resolution?.id || id))) return resolveDependency(id, importer);
893
896
  if (!resolution || resolution.external) return resolution;
894
897
  if (RE_JS.test(resolution.id)) {
895
898
  resolution = await this.resolve(filename_js_to_dts(resolution.id), importer, options);
@@ -920,7 +923,7 @@ function dts(options = {}) {
920
923
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
921
924
  return plugins;
922
925
  }
923
- function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false }) {
926
+ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, resolvePaths }) {
924
927
  if (tsconfig === true || tsconfig == null) {
925
928
  const { config, path: path$1 } = getTsconfig(cwd) || {};
926
929
  tsconfig = path$1;
@@ -952,7 +955,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, i
952
955
  sourcemap,
953
956
  dtsInput,
954
957
  emitDtsOnly,
955
- resolve
958
+ resolve,
959
+ resolvePaths: resolvePaths ?? !!compilerOptions?.paths
956
960
  };
957
961
  }
958
962
 
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.6",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",