vite-plugin-dts 4.3.0 → 4.4.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.cjs CHANGED
@@ -29,6 +29,9 @@ const windowsSlashRE = /\\+/g;
29
29
  function slash(p) {
30
30
  return p.replace(windowsSlashRE, "/");
31
31
  }
32
+ function resolveConfigDir(path, configDir) {
33
+ return path.replace("${configDir}", configDir);
34
+ }
32
35
  function normalizePath(id) {
33
36
  return node_path.posix.normalize(slash(id));
34
37
  }
@@ -273,6 +276,38 @@ function parseTsAliases(basePath, paths) {
273
276
  }
274
277
  return result;
275
278
  }
279
+ const rootAsteriskImportRE = /^(?!\.{1,2}\/)([^*]+)$/;
280
+ function isAliasGlobal(alias) {
281
+ return alias.find.toString() === rootAsteriskImportRE.toString();
282
+ }
283
+ function importResolves(path) {
284
+ const files = [
285
+ // js
286
+ ".js",
287
+ ".jsx",
288
+ ".mjs",
289
+ ".cjs",
290
+ // ts
291
+ ".ts",
292
+ ".tsx",
293
+ ".mts",
294
+ ".cts",
295
+ ".d.ts",
296
+ // json
297
+ ".json",
298
+ // vue
299
+ ".vue",
300
+ ".vue.d.ts",
301
+ // svelte
302
+ ".svelte"
303
+ ];
304
+ for (const ext of files) {
305
+ if (node_fs.existsSync(path + ext)) {
306
+ return true;
307
+ }
308
+ }
309
+ return false;
310
+ }
276
311
  function tryGetPackageInfo(name) {
277
312
  if (process.versions.pnp) {
278
313
  const targetRequire = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
@@ -519,8 +554,13 @@ function transformAlias(importer, dir, aliases, aliasesExclude) {
519
554
  matchedAlias.find,
520
555
  replacement + (endsWithSlash ? "/" : "")
521
556
  );
522
- const normalizedPath = normalizePath(node_path.relative(dir, node_path.resolve(dir, truthPath)));
523
- return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
557
+ const absolutePath = node_path.resolve(dir, truthPath);
558
+ const normalizedPath = normalizePath(node_path.relative(dir, absolutePath));
559
+ const resultPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
560
+ if (!isAliasGlobal(matchedAlias))
561
+ return resultPath;
562
+ if (importResolves(absolutePath))
563
+ return resultPath;
524
564
  }
525
565
  }
526
566
  return importer;
@@ -769,6 +809,7 @@ function dtsPlugin(options = {}) {
769
809
  ]);
770
810
  const rootFiles = /* @__PURE__ */ new Set();
771
811
  const outputFiles = /* @__PURE__ */ new Map();
812
+ const transformedFiles = /* @__PURE__ */ new Set();
772
813
  const setOutputFile = (path, content) => {
773
814
  outputFiles.set(path, content);
774
815
  };
@@ -882,7 +923,12 @@ ${logPrefix} ${kolorist.yellow(
882
923
  setModuleResolution(compilerOptions);
883
924
  }
884
925
  if (!outDirs) {
885
- outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
926
+ outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [
927
+ ensureAbsolute(
928
+ content?.raw.compilerOptions?.outDir ? resolveConfigDir(content.raw.compilerOptions.outDir, root) : "dist",
929
+ root
930
+ )
931
+ ];
886
932
  }
887
933
  const {
888
934
  // Here we are using the default value to set the `baseUrl` to the current directory if no value exists. This is
@@ -893,15 +939,25 @@ ${logPrefix} ${kolorist.yellow(
893
939
  } = compilerOptions;
894
940
  if (pathsToAliases && baseUrl && paths) {
895
941
  aliases.push(
896
- ...parseTsAliases(ensureAbsolute(baseUrl, configPath ? node_path.dirname(configPath) : root), paths)
942
+ ...parseTsAliases(
943
+ ensureAbsolute(
944
+ resolveConfigDir(baseUrl, root),
945
+ configPath ? node_path.dirname(configPath) : root
946
+ ),
947
+ paths
948
+ )
897
949
  );
898
950
  }
899
951
  const computeGlobs = (rootGlobs, tsGlobs, defaultGlob) => {
900
952
  if (rootGlobs?.length) {
901
- return ensureArray(rootGlobs).map((glob) => normalizeGlob(ensureAbsolute(glob, root)));
953
+ return ensureArray(rootGlobs).map(
954
+ (glob) => normalizeGlob(ensureAbsolute(resolveConfigDir(glob, root), root))
955
+ );
902
956
  }
903
957
  return ensureArray(tsGlobs?.length ? tsGlobs : defaultGlob).map(
904
- (glob) => normalizeGlob(ensureAbsolute(glob, configPath ? node_path.dirname(configPath) : root))
958
+ (glob) => normalizeGlob(
959
+ ensureAbsolute(resolveConfigDir(glob, root), configPath ? node_path.dirname(configPath) : root)
960
+ )
905
961
  );
906
962
  };
907
963
  include = computeGlobs(
@@ -928,7 +984,7 @@ ${logPrefix} ${kolorist.yellow(
928
984
  const maybeEmitted = (sourceFile) => {
929
985
  return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
930
986
  };
931
- publicRoot = compilerOptions.rootDir ? ensureAbsolute(compilerOptions.rootDir, root) : compilerOptions.composite && compilerOptions.configFilePath ? node_path.dirname(compilerOptions.configFilePath) : queryPublicPath(
987
+ publicRoot = compilerOptions.rootDir ? ensureAbsolute(resolveConfigDir(compilerOptions.rootDir, root), root) : compilerOptions.composite && compilerOptions.configFilePath ? node_path.dirname(compilerOptions.configFilePath) : queryPublicPath(
932
988
  program.getSourceFiles().filter(maybeEmitted).map((sourceFile) => sourceFile.fileName)
933
989
  );
934
990
  publicRoot = normalizePath(publicRoot);
@@ -954,14 +1010,14 @@ ${logPrefix} ${kolorist.yellow(
954
1010
  },
955
1011
  async transform(code, id) {
956
1012
  let resolver;
957
- id = normalizePath(id);
958
- if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id)) {
1013
+ id = normalizePath(id).split("?")[0];
1014
+ if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id) || transformedFiles.has(id)) {
959
1015
  return;
960
1016
  }
961
1017
  const startTime = Date.now();
962
1018
  const outDir = outDirs[0];
963
- id = id.split("?")[0];
964
1019
  rootFiles.delete(id);
1020
+ transformedFiles.add(id);
965
1021
  if (resolver) {
966
1022
  const result = await resolver.transform({
967
1023
  id,
@@ -1016,6 +1072,7 @@ ${logPrefix} ${kolorist.yellow(
1016
1072
  }
1017
1073
  },
1018
1074
  async writeBundle() {
1075
+ transformedFiles.clear();
1019
1076
  if (!host || !program || bundled)
1020
1077
  return;
1021
1078
  bundled = true;
package/dist/index.mjs CHANGED
@@ -25,6 +25,9 @@ const windowsSlashRE = /\\+/g;
25
25
  function slash(p) {
26
26
  return p.replace(windowsSlashRE, "/");
27
27
  }
28
+ function resolveConfigDir(path, configDir) {
29
+ return path.replace("${configDir}", configDir);
30
+ }
28
31
  function normalizePath(id) {
29
32
  return posix.normalize(slash(id));
30
33
  }
@@ -269,6 +272,38 @@ function parseTsAliases(basePath, paths) {
269
272
  }
270
273
  return result;
271
274
  }
275
+ const rootAsteriskImportRE = /^(?!\.{1,2}\/)([^*]+)$/;
276
+ function isAliasGlobal(alias) {
277
+ return alias.find.toString() === rootAsteriskImportRE.toString();
278
+ }
279
+ function importResolves(path) {
280
+ const files = [
281
+ // js
282
+ ".js",
283
+ ".jsx",
284
+ ".mjs",
285
+ ".cjs",
286
+ // ts
287
+ ".ts",
288
+ ".tsx",
289
+ ".mts",
290
+ ".cts",
291
+ ".d.ts",
292
+ // json
293
+ ".json",
294
+ // vue
295
+ ".vue",
296
+ ".vue.d.ts",
297
+ // svelte
298
+ ".svelte"
299
+ ];
300
+ for (const ext of files) {
301
+ if (existsSync(path + ext)) {
302
+ return true;
303
+ }
304
+ }
305
+ return false;
306
+ }
272
307
  function tryGetPackageInfo(name) {
273
308
  if (process.versions.pnp) {
274
309
  const targetRequire = createRequire(import.meta.url);
@@ -515,8 +550,13 @@ function transformAlias(importer, dir, aliases, aliasesExclude) {
515
550
  matchedAlias.find,
516
551
  replacement + (endsWithSlash ? "/" : "")
517
552
  );
518
- const normalizedPath = normalizePath(relative(dir, resolve$1(dir, truthPath)));
519
- return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
553
+ const absolutePath = resolve$1(dir, truthPath);
554
+ const normalizedPath = normalizePath(relative(dir, absolutePath));
555
+ const resultPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
556
+ if (!isAliasGlobal(matchedAlias))
557
+ return resultPath;
558
+ if (importResolves(absolutePath))
559
+ return resultPath;
520
560
  }
521
561
  }
522
562
  return importer;
@@ -765,6 +805,7 @@ function dtsPlugin(options = {}) {
765
805
  ]);
766
806
  const rootFiles = /* @__PURE__ */ new Set();
767
807
  const outputFiles = /* @__PURE__ */ new Map();
808
+ const transformedFiles = /* @__PURE__ */ new Set();
768
809
  const setOutputFile = (path, content) => {
769
810
  outputFiles.set(path, content);
770
811
  };
@@ -878,7 +919,12 @@ ${logPrefix} ${yellow(
878
919
  setModuleResolution(compilerOptions);
879
920
  }
880
921
  if (!outDirs) {
881
- outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
922
+ outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [
923
+ ensureAbsolute(
924
+ content?.raw.compilerOptions?.outDir ? resolveConfigDir(content.raw.compilerOptions.outDir, root) : "dist",
925
+ root
926
+ )
927
+ ];
882
928
  }
883
929
  const {
884
930
  // Here we are using the default value to set the `baseUrl` to the current directory if no value exists. This is
@@ -889,15 +935,25 @@ ${logPrefix} ${yellow(
889
935
  } = compilerOptions;
890
936
  if (pathsToAliases && baseUrl && paths) {
891
937
  aliases.push(
892
- ...parseTsAliases(ensureAbsolute(baseUrl, configPath ? dirname(configPath) : root), paths)
938
+ ...parseTsAliases(
939
+ ensureAbsolute(
940
+ resolveConfigDir(baseUrl, root),
941
+ configPath ? dirname(configPath) : root
942
+ ),
943
+ paths
944
+ )
893
945
  );
894
946
  }
895
947
  const computeGlobs = (rootGlobs, tsGlobs, defaultGlob) => {
896
948
  if (rootGlobs?.length) {
897
- return ensureArray(rootGlobs).map((glob) => normalizeGlob(ensureAbsolute(glob, root)));
949
+ return ensureArray(rootGlobs).map(
950
+ (glob) => normalizeGlob(ensureAbsolute(resolveConfigDir(glob, root), root))
951
+ );
898
952
  }
899
953
  return ensureArray(tsGlobs?.length ? tsGlobs : defaultGlob).map(
900
- (glob) => normalizeGlob(ensureAbsolute(glob, configPath ? dirname(configPath) : root))
954
+ (glob) => normalizeGlob(
955
+ ensureAbsolute(resolveConfigDir(glob, root), configPath ? dirname(configPath) : root)
956
+ )
901
957
  );
902
958
  };
903
959
  include = computeGlobs(
@@ -924,7 +980,7 @@ ${logPrefix} ${yellow(
924
980
  const maybeEmitted = (sourceFile) => {
925
981
  return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
926
982
  };
927
- publicRoot = compilerOptions.rootDir ? ensureAbsolute(compilerOptions.rootDir, root) : compilerOptions.composite && compilerOptions.configFilePath ? dirname(compilerOptions.configFilePath) : queryPublicPath(
983
+ publicRoot = compilerOptions.rootDir ? ensureAbsolute(resolveConfigDir(compilerOptions.rootDir, root), root) : compilerOptions.composite && compilerOptions.configFilePath ? dirname(compilerOptions.configFilePath) : queryPublicPath(
928
984
  program.getSourceFiles().filter(maybeEmitted).map((sourceFile) => sourceFile.fileName)
929
985
  );
930
986
  publicRoot = normalizePath(publicRoot);
@@ -950,14 +1006,14 @@ ${logPrefix} ${yellow(
950
1006
  },
951
1007
  async transform(code, id) {
952
1008
  let resolver;
953
- id = normalizePath(id);
954
- if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id)) {
1009
+ id = normalizePath(id).split("?")[0];
1010
+ if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id) || transformedFiles.has(id)) {
955
1011
  return;
956
1012
  }
957
1013
  const startTime = Date.now();
958
1014
  const outDir = outDirs[0];
959
- id = id.split("?")[0];
960
1015
  rootFiles.delete(id);
1016
+ transformedFiles.add(id);
961
1017
  if (resolver) {
962
1018
  const result = await resolver.transform({
963
1019
  id,
@@ -1012,6 +1068,7 @@ ${logPrefix} ${yellow(
1012
1068
  }
1013
1069
  },
1014
1070
  async writeBundle() {
1071
+ transformedFiles.clear();
1015
1072
  if (!host || !program || bundled)
1016
1073
  return;
1017
1074
  bundled = true;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "type": "module",
5
- "packageManager": "pnpm@9.9.0",
5
+ "packageManager": "pnpm@9.13.2",
6
6
  "license": "MIT",
7
7
  "author": "qmhc",
8
8
  "scripts": {
@@ -58,21 +58,21 @@
58
58
  "url": "https://github.com/qmhc/vite-plugin-dts/issues"
59
59
  },
60
60
  "dependencies": {
61
- "@microsoft/api-extractor": "^7.47.11",
62
- "@rollup/pluginutils": "^5.1.0",
63
- "@volar/typescript": "^2.4.4",
64
- "@vue/language-core": "2.1.6",
61
+ "@microsoft/api-extractor": "^7.48.1",
62
+ "@rollup/pluginutils": "^5.1.4",
63
+ "@volar/typescript": "^2.4.11",
64
+ "@vue/language-core": "2.1.10",
65
65
  "compare-versions": "^6.1.1",
66
- "debug": "^4.3.6",
66
+ "debug": "^4.4.0",
67
67
  "kolorist": "^1.8.0",
68
- "local-pkg": "^0.5.0",
69
- "magic-string": "^0.30.11"
68
+ "local-pkg": "^0.5.1",
69
+ "magic-string": "^0.30.17"
70
70
  },
71
71
  "devDependencies": {
72
- "@commitlint/cli": "^19.3.0",
72
+ "@commitlint/cli": "^19.5.0",
73
73
  "@types/debug": "^4.1.12",
74
74
  "@types/minimist": "^1.2.5",
75
- "@types/node": "^20.14.11",
75
+ "@types/node": "^22.9.0",
76
76
  "@types/prompts": "^2.4.9",
77
77
  "@types/semver": "^7.5.8",
78
78
  "@vexip-ui/commitlint-config": "^0.5.0",
@@ -85,7 +85,7 @@
85
85
  "execa": "^8.0.1",
86
86
  "husky": "^8.0.3",
87
87
  "is-ci": "^3.0.1",
88
- "lint-staged": "^15.2.7",
88
+ "lint-staged": "^15.2.10",
89
89
  "minimist": "^1.2.8",
90
90
  "pinst": "^3.0.0",
91
91
  "prettier": "^3.3.3",
@@ -93,11 +93,11 @@
93
93
  "prompts": "^2.4.2",
94
94
  "rimraf": "^6.0.1",
95
95
  "semver": "^7.6.3",
96
- "tsx": "^4.16.2",
96
+ "tsx": "^4.19.2",
97
97
  "typescript": "5.6.3",
98
98
  "unbuild": "^2.0.0",
99
- "vite": "^5.3.5",
100
- "vitest": "^2.0.4"
99
+ "vite": "^5.4.11",
100
+ "vitest": "^2.1.5"
101
101
  },
102
102
  "peerDependencies": {
103
103
  "typescript": "*",