vite-plugin-dts 3.6.2 → 3.6.4

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
@@ -185,6 +185,27 @@ function findTypesPath(...pkgs) {
185
185
  return path;
186
186
  }
187
187
  }
188
+ function setModuleResolution(options) {
189
+ if (options.moduleResolution)
190
+ return;
191
+ const module = typeof options.module === "number" ? options.module : options.target ?? ts__default.ScriptTarget.ES5 >= 2 ? ts__default.ModuleKind.ES2015 : ts__default.ModuleKind.CommonJS;
192
+ let moduleResolution;
193
+ switch (module) {
194
+ case ts__default.ModuleKind.CommonJS:
195
+ moduleResolution = ts__default.ModuleResolutionKind.Node10;
196
+ break;
197
+ case ts__default.ModuleKind.Node16:
198
+ moduleResolution = ts__default.ModuleResolutionKind.Node16;
199
+ break;
200
+ case ts__default.ModuleKind.NodeNext:
201
+ moduleResolution = ts__default.ModuleResolutionKind.NodeNext;
202
+ break;
203
+ default:
204
+ moduleResolution = ts__default.version.startsWith("5") ? ts__default.ModuleResolutionKind.Bundler : ts__default.ModuleResolutionKind.Classic;
205
+ break;
206
+ }
207
+ options.moduleResolution = moduleResolution;
208
+ }
188
209
 
189
210
  const dtsRE$1 = /\.d\.tsx?$/;
190
211
  function rollupDeclarationFiles({
@@ -446,6 +467,10 @@ const pureImportRE = /import\s?['"][^;\n]+?['"];?\n?/g;
446
467
  function removePureImport(content) {
447
468
  return content.replace(pureImportRE, "");
448
469
  }
470
+ const asDefaultRE = /export\s*\{.*\w+\s*\bas\s+default\b.*\}\s*from\s*['"].+['"]/;
471
+ function hasExportDefault(content) {
472
+ return content.includes("export default") || asDefaultRE.test(content);
473
+ }
449
474
 
450
475
  const jsRE = /\.(m|c)?jsx?$/;
451
476
  const tsRE = /\.(m|c)?tsx?$/;
@@ -609,9 +634,6 @@ ${logPrefix} ${kolorist.yellow(
609
634
  configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts__default.findConfigFile(root, ts__default.sys.fileExists);
610
635
  const content = configPath ? languageCore.createParsedCommandLine(ts__default, ts__default.sys, configPath) : void 0;
611
636
  compilerOptions = {
612
- // (#277) If user don't specify `moduleResolution` in top config file,
613
- // declaration of Vue files will be inferred to `any` type.
614
- moduleResolution: ts__default.ModuleResolutionKind.Node10,
615
637
  ...content?.options || {},
616
638
  ...options.compilerOptions || {},
617
639
  ...fixedCompilerOptions,
@@ -619,6 +641,9 @@ ${logPrefix} ${kolorist.yellow(
619
641
  declarationDir: "."
620
642
  };
621
643
  rawCompilerOptions = content?.raw.compilerOptions || {};
644
+ if (content?.fileNames.find((name) => name.endsWith(".vue"))) {
645
+ setModuleResolution(compilerOptions);
646
+ }
622
647
  if (!outDirs) {
623
648
  outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
624
649
  }
@@ -673,7 +698,7 @@ ${logPrefix} ${kolorist.yellow(
673
698
  entryRoot = ensureAbsolute(entryRoot, root);
674
699
  const diagnostics = program.getDeclarationDiagnostics();
675
700
  if (diagnostics?.length) {
676
- logger.error(ts__default.formatDiagnostics(diagnostics, host));
701
+ logger.error(ts__default.formatDiagnosticsWithColorAndContext(diagnostics, host));
677
702
  }
678
703
  if (typeof afterDiagnostic === "function") {
679
704
  await wrapPromise(afterDiagnostic(diagnostics));
@@ -867,13 +892,10 @@ ${logPrefix} ${kolorist.yellow(
867
892
  fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
868
893
  let content = `export * from '${fromPath}'
869
894
  `;
870
- if (node_fs.existsSync(index)) {
871
- const entryCodes = await promises.readFile(index, "utf-8");
872
- if (entryCodes.includes("export default")) {
873
- content += `import ${libName} from '${fromPath}'
895
+ if (node_fs.existsSync(index) && hasExportDefault(await promises.readFile(index, "utf-8"))) {
896
+ content += `import ${libName} from '${fromPath}'
874
897
  export default ${libName}
875
898
  `;
876
- }
877
899
  }
878
900
  await writeOutput(cleanPath(path), content, outDir);
879
901
  }
package/dist/index.mjs CHANGED
@@ -185,6 +185,27 @@ function findTypesPath(...pkgs) {
185
185
  return path;
186
186
  }
187
187
  }
188
+ function setModuleResolution(options) {
189
+ if (options.moduleResolution)
190
+ return;
191
+ const module = typeof options.module === "number" ? options.module : options.target ?? ts.ScriptTarget.ES5 >= 2 ? ts.ModuleKind.ES2015 : ts.ModuleKind.CommonJS;
192
+ let moduleResolution;
193
+ switch (module) {
194
+ case ts.ModuleKind.CommonJS:
195
+ moduleResolution = ts.ModuleResolutionKind.Node10;
196
+ break;
197
+ case ts.ModuleKind.Node16:
198
+ moduleResolution = ts.ModuleResolutionKind.Node16;
199
+ break;
200
+ case ts.ModuleKind.NodeNext:
201
+ moduleResolution = ts.ModuleResolutionKind.NodeNext;
202
+ break;
203
+ default:
204
+ moduleResolution = ts.version.startsWith("5") ? ts.ModuleResolutionKind.Bundler : ts.ModuleResolutionKind.Classic;
205
+ break;
206
+ }
207
+ options.moduleResolution = moduleResolution;
208
+ }
188
209
 
189
210
  const dtsRE$1 = /\.d\.tsx?$/;
190
211
  function rollupDeclarationFiles({
@@ -446,6 +467,10 @@ const pureImportRE = /import\s?['"][^;\n]+?['"];?\n?/g;
446
467
  function removePureImport(content) {
447
468
  return content.replace(pureImportRE, "");
448
469
  }
470
+ const asDefaultRE = /export\s*\{.*\w+\s*\bas\s+default\b.*\}\s*from\s*['"].+['"]/;
471
+ function hasExportDefault(content) {
472
+ return content.includes("export default") || asDefaultRE.test(content);
473
+ }
449
474
 
450
475
  const jsRE = /\.(m|c)?jsx?$/;
451
476
  const tsRE = /\.(m|c)?tsx?$/;
@@ -609,9 +634,6 @@ ${logPrefix} ${yellow(
609
634
  configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts.findConfigFile(root, ts.sys.fileExists);
610
635
  const content = configPath ? createParsedCommandLine(ts, ts.sys, configPath) : void 0;
611
636
  compilerOptions = {
612
- // (#277) If user don't specify `moduleResolution` in top config file,
613
- // declaration of Vue files will be inferred to `any` type.
614
- moduleResolution: ts.ModuleResolutionKind.Node10,
615
637
  ...content?.options || {},
616
638
  ...options.compilerOptions || {},
617
639
  ...fixedCompilerOptions,
@@ -619,6 +641,9 @@ ${logPrefix} ${yellow(
619
641
  declarationDir: "."
620
642
  };
621
643
  rawCompilerOptions = content?.raw.compilerOptions || {};
644
+ if (content?.fileNames.find((name) => name.endsWith(".vue"))) {
645
+ setModuleResolution(compilerOptions);
646
+ }
622
647
  if (!outDirs) {
623
648
  outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
624
649
  }
@@ -673,7 +698,7 @@ ${logPrefix} ${yellow(
673
698
  entryRoot = ensureAbsolute(entryRoot, root);
674
699
  const diagnostics = program.getDeclarationDiagnostics();
675
700
  if (diagnostics?.length) {
676
- logger.error(ts.formatDiagnostics(diagnostics, host));
701
+ logger.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, host));
677
702
  }
678
703
  if (typeof afterDiagnostic === "function") {
679
704
  await wrapPromise(afterDiagnostic(diagnostics));
@@ -867,13 +892,10 @@ ${logPrefix} ${yellow(
867
892
  fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
868
893
  let content = `export * from '${fromPath}'
869
894
  `;
870
- if (existsSync(index)) {
871
- const entryCodes = await readFile(index, "utf-8");
872
- if (entryCodes.includes("export default")) {
873
- content += `import ${libName} from '${fromPath}'
895
+ if (existsSync(index) && hasExportDefault(await readFile(index, "utf-8"))) {
896
+ content += `import ${libName} from '${fromPath}'
874
897
  export default ${libName}
875
898
  `;
876
- }
877
899
  }
878
900
  await writeOutput(cleanPath(path), content, outDir);
879
901
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.6.2",
3
+ "version": "3.6.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",