vite-plugin-dts 3.4.0 → 3.5.1

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
@@ -402,7 +402,7 @@ const dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
402
402
  const simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
403
403
  const simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
404
404
  function transformAliasImport(filePath, content, aliases, exclude = []) {
405
- if (!aliases.length)
405
+ if (!aliases?.length)
406
406
  return content;
407
407
  return content.replace(globalImportRE, (str) => {
408
408
  let matchResult = str.match(staticImportRE);
@@ -471,6 +471,7 @@ function dtsPlugin(options = {}) {
471
471
  pathsToAliases = true,
472
472
  aliasesExclude = [],
473
473
  copyDtsFiles = false,
474
+ declarationOnly = false,
474
475
  strictOutput = true,
475
476
  afterDiagnostic = noop,
476
477
  beforeWriteFile = noop,
@@ -548,13 +549,11 @@ function dtsPlugin(options = {}) {
548
549
  }
549
550
  } else {
550
551
  logger.warn(
551
- kolorist.yellow(
552
- `
553
- ${kolorist.cyan(
554
- "[vite:dts]"
555
- )} You are building a library that may not need to generate declaration files.
552
+ `
553
+ ${logPrefix} ${kolorist.yellow(
554
+ "You are building a library that may not need to generate declaration files."
555
+ )}
556
556
  `
557
- )
558
557
  );
559
558
  libName = "_default";
560
559
  indexName = defaultIndex;
@@ -594,7 +593,8 @@ ${kolorist.cyan(
594
593
  ...content?.options || {},
595
594
  ...options.compilerOptions || {},
596
595
  ...fixedCompilerOptions,
597
- outDir: "."
596
+ outDir: ".",
597
+ declarationDir: "."
598
598
  };
599
599
  rawCompilerOptions = content?.raw.compilerOptions || {};
600
600
  if (!outDirs) {
@@ -804,7 +804,17 @@ ${logPrefix} Start generate declaration files...`));
804
804
  const entryNames = Object.keys(entries);
805
805
  const types = pkg.types || pkg.typings || pkg.publishConfig?.types || pkg.publishConfig?.typings || (pkg.exports?.["."] || pkg.exports?.["./"])?.types;
806
806
  const multiple = entryNames.length > 1;
807
- const typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
807
+ let typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
808
+ if (!multiple && !dtsRE.test(typesPath)) {
809
+ logger.warn(
810
+ `
811
+ ${logPrefix} ${kolorist.yellow(
812
+ "The resolved path of type entry is not ending with '.d.ts'."
813
+ )}
814
+ `
815
+ );
816
+ typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
817
+ }
808
818
  for (const name of entryNames) {
809
819
  const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
810
820
  if (node_fs.existsSync(path))
@@ -914,6 +924,13 @@ export default ${libName}
914
924
  kolorist.green(`${logPrefix} Declaration files built in ${timeRecord + Date.now() - startTime}ms.
915
925
  `)
916
926
  );
927
+ },
928
+ generateBundle(_, bundle) {
929
+ if (declarationOnly) {
930
+ for (const id of Object.keys(bundle)) {
931
+ delete bundle[id];
932
+ }
933
+ }
917
934
  }
918
935
  };
919
936
  }
package/dist/index.d.ts CHANGED
@@ -171,6 +171,14 @@ interface PluginOptions {
171
171
  * @remarks Before 2.0, the default was `true`
172
172
  */
173
173
  copyDtsFiles?: boolean;
174
+ /**
175
+ * Whether to emit declaration files only
176
+ *
177
+ * When `true`, all the original outputs of vite (rollup) will be force removed
178
+ *
179
+ * @default false
180
+ */
181
+ declarationOnly?: boolean;
174
182
  /**
175
183
  * Logging level for this plugin
176
184
  *
package/dist/index.mjs CHANGED
@@ -402,7 +402,7 @@ const dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
402
402
  const simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
403
403
  const simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
404
404
  function transformAliasImport(filePath, content, aliases, exclude = []) {
405
- if (!aliases.length)
405
+ if (!aliases?.length)
406
406
  return content;
407
407
  return content.replace(globalImportRE, (str) => {
408
408
  let matchResult = str.match(staticImportRE);
@@ -471,6 +471,7 @@ function dtsPlugin(options = {}) {
471
471
  pathsToAliases = true,
472
472
  aliasesExclude = [],
473
473
  copyDtsFiles = false,
474
+ declarationOnly = false,
474
475
  strictOutput = true,
475
476
  afterDiagnostic = noop,
476
477
  beforeWriteFile = noop,
@@ -548,13 +549,11 @@ function dtsPlugin(options = {}) {
548
549
  }
549
550
  } else {
550
551
  logger.warn(
551
- yellow(
552
- `
553
- ${cyan(
554
- "[vite:dts]"
555
- )} You are building a library that may not need to generate declaration files.
552
+ `
553
+ ${logPrefix} ${yellow(
554
+ "You are building a library that may not need to generate declaration files."
555
+ )}
556
556
  `
557
- )
558
557
  );
559
558
  libName = "_default";
560
559
  indexName = defaultIndex;
@@ -594,7 +593,8 @@ ${cyan(
594
593
  ...content?.options || {},
595
594
  ...options.compilerOptions || {},
596
595
  ...fixedCompilerOptions,
597
- outDir: "."
596
+ outDir: ".",
597
+ declarationDir: "."
598
598
  };
599
599
  rawCompilerOptions = content?.raw.compilerOptions || {};
600
600
  if (!outDirs) {
@@ -804,7 +804,17 @@ ${logPrefix} Start generate declaration files...`));
804
804
  const entryNames = Object.keys(entries);
805
805
  const types = pkg.types || pkg.typings || pkg.publishConfig?.types || pkg.publishConfig?.typings || (pkg.exports?.["."] || pkg.exports?.["./"])?.types;
806
806
  const multiple = entryNames.length > 1;
807
- const typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
807
+ let typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
808
+ if (!multiple && !dtsRE.test(typesPath)) {
809
+ logger.warn(
810
+ `
811
+ ${logPrefix} ${yellow(
812
+ "The resolved path of type entry is not ending with '.d.ts'."
813
+ )}
814
+ `
815
+ );
816
+ typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
817
+ }
808
818
  for (const name of entryNames) {
809
819
  const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
810
820
  if (existsSync(path))
@@ -914,6 +924,13 @@ export default ${libName}
914
924
  green(`${logPrefix} Declaration files built in ${timeRecord + Date.now() - startTime}ms.
915
925
  `)
916
926
  );
927
+ },
928
+ generateBundle(_, bundle) {
929
+ if (declarationOnly) {
930
+ for (const id of Object.keys(bundle)) {
931
+ delete bundle[id];
932
+ }
933
+ }
917
934
  }
918
935
  };
919
936
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.4.0",
3
+ "version": "3.5.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",