vite-plugin-dts 3.7.0 → 3.7.2

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
@@ -121,6 +121,25 @@ function removeDirIfEmpty(dir) {
121
121
  }
122
122
  return onlyHasDir;
123
123
  }
124
+ function getTsConfig(tsConfigPath, readFileSync) {
125
+ const tsConfig = {
126
+ compilerOptions: {},
127
+ ...ts__default.readConfigFile(tsConfigPath, readFileSync).config ?? {}
128
+ };
129
+ if (tsConfig.extends) {
130
+ ensureArray(tsConfig.extends).forEach((configPath) => {
131
+ const config = getTsConfig(ensureAbsolute(configPath, node_path.dirname(tsConfigPath)), readFileSync);
132
+ Object.assign(tsConfig.compilerOptions, config.compilerOptions);
133
+ if (!tsConfig.include) {
134
+ tsConfig.include = config.include;
135
+ }
136
+ if (!tsConfig.exclude) {
137
+ tsConfig.exclude = config.exclude;
138
+ }
139
+ });
140
+ }
141
+ return tsConfig;
142
+ }
124
143
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
125
144
  function base64Encode(number) {
126
145
  if (number >= 0 && number < BASE64_ALPHABET.length) {
@@ -472,7 +491,7 @@ function transformAliasImport(filePath, content, aliases, exclude = []) {
472
491
  }
473
492
  const dir = node_path.dirname(filePath);
474
493
  const replacement = node_path.isAbsolute(matchedAlias.replacement) ? normalizePath(node_path.relative(dir, matchedAlias.replacement)) : normalizePath(matchedAlias.replacement);
475
- const endSlash = matchResult[1].match(matchedAlias.find)[0].endsWith("/");
494
+ const endSlash = typeof matchedAlias.find === "string" ? matchedAlias.find.endsWith("/") : matchResult[1].match(matchedAlias.find)[0].endsWith("/");
476
495
  const truthPath = matchResult[1].replace(
477
496
  matchedAlias.find,
478
497
  replacement + (endSlash ? "/" : "")
@@ -520,6 +539,8 @@ const fixedCompilerOptions = {
520
539
  const noop = () => {
521
540
  };
522
541
  const extPrefix = (file) => mtjsRE.test(file) ? "m" : ctjsRE.test(file) ? "c" : "";
542
+ const regexpSymbolRE = /([$.\\+?()[\]!<=|{}^,])/g;
543
+ const asteriskRE = /[*]+/g;
523
544
  function dtsPlugin(options = {}) {
524
545
  const {
525
546
  tsconfigPath,
@@ -677,16 +698,17 @@ ${logPrefix} ${kolorist.yellow(
677
698
  const { baseUrl, paths } = compilerOptions;
678
699
  if (pathsToAliases && baseUrl && paths) {
679
700
  const basePath = ensureAbsolute(baseUrl, configPath ? node_path.dirname(configPath) : root);
680
- const existsFinds = new Set(
681
- aliases.map((alias) => alias.find).filter((find) => typeof find === "string")
682
- );
683
- for (const [findWithAsterisk, replacements] of Object.entries(paths)) {
684
- const find = findWithAsterisk.replace("/*", "");
685
- if (!replacements.length || existsFinds.has(find))
686
- continue;
701
+ for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
702
+ const find = new RegExp(
703
+ `^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
704
+ );
705
+ let index = 1;
687
706
  aliases.push({
688
707
  find,
689
- replacement: ensureAbsolute(replacements[0].replace("/*", ""), basePath)
708
+ replacement: ensureAbsolute(
709
+ replacements[0].replace(asteriskRE, () => `$${index++}`),
710
+ basePath
711
+ )
690
712
  });
691
713
  }
692
714
  }
@@ -939,13 +961,14 @@ export default ${libName}
939
961
  libFolder = void 0;
940
962
  }
941
963
  const rollupFiles = /* @__PURE__ */ new Set();
964
+ const compilerOptions2 = configPath ? getTsConfig(configPath, host.readFile).compilerOptions : rawCompilerOptions;
942
965
  if (multiple) {
943
966
  for (const name of entryNames) {
944
967
  const path = cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`));
945
968
  rollupDeclarationFiles({
946
969
  root,
947
970
  configPath,
948
- compilerOptions: rawCompilerOptions,
971
+ compilerOptions: compilerOptions2,
949
972
  outDir,
950
973
  entryPath: path,
951
974
  fileName: node_path.basename(path),
@@ -960,7 +983,7 @@ export default ${libName}
960
983
  rollupDeclarationFiles({
961
984
  root,
962
985
  configPath,
963
- compilerOptions: rawCompilerOptions,
986
+ compilerOptions: compilerOptions2,
964
987
  outDir,
965
988
  entryPath: typesPath,
966
989
  fileName: node_path.basename(typesPath),
package/dist/index.mjs CHANGED
@@ -119,6 +119,25 @@ function removeDirIfEmpty(dir) {
119
119
  }
120
120
  return onlyHasDir;
121
121
  }
122
+ function getTsConfig(tsConfigPath, readFileSync) {
123
+ const tsConfig = {
124
+ compilerOptions: {},
125
+ ...ts.readConfigFile(tsConfigPath, readFileSync).config ?? {}
126
+ };
127
+ if (tsConfig.extends) {
128
+ ensureArray(tsConfig.extends).forEach((configPath) => {
129
+ const config = getTsConfig(ensureAbsolute(configPath, dirname(tsConfigPath)), readFileSync);
130
+ Object.assign(tsConfig.compilerOptions, config.compilerOptions);
131
+ if (!tsConfig.include) {
132
+ tsConfig.include = config.include;
133
+ }
134
+ if (!tsConfig.exclude) {
135
+ tsConfig.exclude = config.exclude;
136
+ }
137
+ });
138
+ }
139
+ return tsConfig;
140
+ }
122
141
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
123
142
  function base64Encode(number) {
124
143
  if (number >= 0 && number < BASE64_ALPHABET.length) {
@@ -470,7 +489,7 @@ function transformAliasImport(filePath, content, aliases, exclude = []) {
470
489
  }
471
490
  const dir = dirname(filePath);
472
491
  const replacement = isAbsolute(matchedAlias.replacement) ? normalizePath(relative(dir, matchedAlias.replacement)) : normalizePath(matchedAlias.replacement);
473
- const endSlash = matchResult[1].match(matchedAlias.find)[0].endsWith("/");
492
+ const endSlash = typeof matchedAlias.find === "string" ? matchedAlias.find.endsWith("/") : matchResult[1].match(matchedAlias.find)[0].endsWith("/");
474
493
  const truthPath = matchResult[1].replace(
475
494
  matchedAlias.find,
476
495
  replacement + (endSlash ? "/" : "")
@@ -518,6 +537,8 @@ const fixedCompilerOptions = {
518
537
  const noop = () => {
519
538
  };
520
539
  const extPrefix = (file) => mtjsRE.test(file) ? "m" : ctjsRE.test(file) ? "c" : "";
540
+ const regexpSymbolRE = /([$.\\+?()[\]!<=|{}^,])/g;
541
+ const asteriskRE = /[*]+/g;
521
542
  function dtsPlugin(options = {}) {
522
543
  const {
523
544
  tsconfigPath,
@@ -675,16 +696,17 @@ ${logPrefix} ${yellow(
675
696
  const { baseUrl, paths } = compilerOptions;
676
697
  if (pathsToAliases && baseUrl && paths) {
677
698
  const basePath = ensureAbsolute(baseUrl, configPath ? dirname(configPath) : root);
678
- const existsFinds = new Set(
679
- aliases.map((alias) => alias.find).filter((find) => typeof find === "string")
680
- );
681
- for (const [findWithAsterisk, replacements] of Object.entries(paths)) {
682
- const find = findWithAsterisk.replace("/*", "");
683
- if (!replacements.length || existsFinds.has(find))
684
- continue;
699
+ for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
700
+ const find = new RegExp(
701
+ `^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
702
+ );
703
+ let index = 1;
685
704
  aliases.push({
686
705
  find,
687
- replacement: ensureAbsolute(replacements[0].replace("/*", ""), basePath)
706
+ replacement: ensureAbsolute(
707
+ replacements[0].replace(asteriskRE, () => `$${index++}`),
708
+ basePath
709
+ )
688
710
  });
689
711
  }
690
712
  }
@@ -937,13 +959,14 @@ export default ${libName}
937
959
  libFolder = void 0;
938
960
  }
939
961
  const rollupFiles = /* @__PURE__ */ new Set();
962
+ const compilerOptions2 = configPath ? getTsConfig(configPath, host.readFile).compilerOptions : rawCompilerOptions;
940
963
  if (multiple) {
941
964
  for (const name of entryNames) {
942
965
  const path = cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`));
943
966
  rollupDeclarationFiles({
944
967
  root,
945
968
  configPath,
946
- compilerOptions: rawCompilerOptions,
969
+ compilerOptions: compilerOptions2,
947
970
  outDir,
948
971
  entryPath: path,
949
972
  fileName: basename(path),
@@ -958,7 +981,7 @@ export default ${libName}
958
981
  rollupDeclarationFiles({
959
982
  root,
960
983
  configPath,
961
- compilerOptions: rawCompilerOptions,
984
+ compilerOptions: compilerOptions2,
962
985
  outDir,
963
986
  entryPath: typesPath,
964
987
  fileName: basename(typesPath),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.7.0",
3
+ "version": "3.7.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",