vite-plugin-dts 1.6.6 → 1.7.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.mjs CHANGED
@@ -17,6 +17,7 @@ import require$$1$1 from 'fs';
17
17
  import require$$1 from 'path';
18
18
  import require$$5 from 'buffer';
19
19
  import require$$7 from 'inspector';
20
+ import { createFilter } from '@rollup/pluginutils';
20
21
  import { existsSync, readdirSync, lstatSync, rmdirSync } from 'node:fs';
21
22
  import { createRequire } from 'node:module';
22
23
  import { ExtractorConfig, CompilerState } from '@microsoft/api-extractor';
@@ -176687,6 +176688,10 @@ function requireCompiler() {
176687
176688
  try {
176688
176689
  compiler = _require(_require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
176689
176690
  } catch (e) {
176691
+ try {
176692
+ compiler = _require(_require.resolve("@vue/compiler-sfc", { paths: [compileRoot] }));
176693
+ } catch (e2) {
176694
+ }
176690
176695
  }
176691
176696
  }
176692
176697
  if (!compiler) {
@@ -176770,7 +176775,7 @@ const _sfc_main = ${classMatch[1]}`;
176770
176775
  content = rewriteDefault(
176771
176776
  script.content,
176772
176777
  "_sfc_main",
176773
- script.lang === "ts" ? ["typescript"] : void 0
176778
+ script.lang === "ts" ? ["typescript", "decorators-legacy"] : void 0
176774
176779
  );
176775
176780
  content += "\nexport default _sfc_main\n";
176776
176781
  ext = script.lang || "js";
@@ -176865,13 +176870,12 @@ function rollupDeclarationFiles({
176865
176870
  }
176866
176871
 
176867
176872
  const noneExport = "export {};\n";
176868
- const virtualPrefix = "\0";
176869
176873
  const vueRE = /\.vue$/;
176870
- const tsRE = /\.tsx?$/;
176871
- const jsRE = /\.jsx?$/;
176874
+ const tsRE = /\.(m|c)?tsx?$/;
176875
+ const jsRE = /\.(m|c)?jsx?$/;
176872
176876
  const dtsRE = /\.d\.tsx?$/;
176873
- const tjsRE = /\.(t|j)sx?$/;
176874
- const watchExtensionRE = /\.(vue|(t|j)sx?)$/;
176877
+ const tjsRE = /\.(m|c)?(t|j)sx?$/;
176878
+ const watchExtensionRE = /\.(vue|(m|c)?(t|j)sx?)$/;
176875
176879
  const fullRelativeRE = /^\.\.?\//;
176876
176880
  const defaultIndex = "index.d.ts";
176877
176881
  const noop = () => {
@@ -176888,9 +176892,10 @@ function dtsPlugin(options = {}) {
176888
176892
  insertTypesEntry = false,
176889
176893
  rollupTypes = false,
176890
176894
  noEmitOnError = false,
176891
- skipDiagnostics = true,
176892
- logDiagnostics = false,
176895
+ skipDiagnostics = false,
176896
+ logDiagnostics = void 0,
176893
176897
  copyDtsFiles = true,
176898
+ libFolderPath = void 0,
176894
176899
  afterDiagnostic = noop,
176895
176900
  beforeWriteFile = noop,
176896
176901
  afterBuild = noop
@@ -176907,6 +176912,9 @@ function dtsPlugin(options = {}) {
176907
176912
  let tsConfigPath;
176908
176913
  let outputDirs;
176909
176914
  let isBundle = false;
176915
+ let include;
176916
+ let exclude;
176917
+ let filter;
176910
176918
  const sourceDtsFiles = /* @__PURE__ */ new Set();
176911
176919
  let hasJsVue = false;
176912
176920
  let allowJs = false;
@@ -176937,6 +176945,17 @@ function dtsPlugin(options = {}) {
176937
176945
  if (isBundle)
176938
176946
  return;
176939
176947
  logger = config.logger;
176948
+ if (logDiagnostics != null) {
176949
+ logger.warn(
176950
+ yellow(
176951
+ `
176952
+ ${cyan(
176953
+ "[vite:dts]"
176954
+ )} 'logDiagnostics' has been deprecated, the original feature now following 'skipDiagnostics'.
176955
+ `
176956
+ )
176957
+ );
176958
+ }
176940
176959
  if (!config.build.lib) {
176941
176960
  logger.warn(
176942
176961
  yellow(
@@ -176951,8 +176970,9 @@ ${cyan(
176951
176970
  indexName = defaultIndex;
176952
176971
  } else {
176953
176972
  const filename = config.build.lib.fileName ?? defaultIndex;
176973
+ const entry = typeof config.build.lib.entry === "string" ? config.build.lib.entry : Object.values(config.build.lib.entry)[0];
176954
176974
  libName = config.build.lib.name || "_default";
176955
- indexName = typeof filename === "string" ? filename : filename("es");
176975
+ indexName = typeof filename === "string" ? filename : filename("es", entry);
176956
176976
  if (!dtsRE.test(indexName)) {
176957
176977
  indexName = `${tjsRE.test(indexName) ? indexName.replace(tjsRE, "") : indexName}.d.ts`;
176958
176978
  }
@@ -176985,17 +177005,33 @@ ${cyan(
176985
177005
  emitDeclarationOnly: true
176986
177006
  }),
176987
177007
  tsConfigFilePath: tsConfigPath,
176988
- skipAddingFilesFromTsConfig: true
177008
+ skipAddingFilesFromTsConfig: true,
177009
+ libFolderPath: libFolderPath ? ensureAbsolute(libFolderPath, root) : void 0
176989
177010
  });
176990
177011
  allowJs = project.getCompilerOptions().allowJs ?? false;
177012
+ const tsConfig = typescript.readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
177013
+ const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
177014
+ const parentTsConfig = parentTsConfigPath ? typescript.readConfigFile(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
177015
+ include = ensureArray(
177016
+ options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*"
177017
+ ).map(normalizeGlob);
177018
+ exclude = ensureArray(
177019
+ options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**"
177020
+ ).map(normalizeGlob);
177021
+ filter = createFilter(include, exclude, { resolve: root });
176991
177022
  },
176992
177023
  buildStart(inputOptions) {
176993
- if (!isBundle && (insertTypesEntry || rollupTypes)) {
176994
- entries = Array.isArray(inputOptions.input) ? inputOptions.input : Object.values(inputOptions.input);
177024
+ if (Array.isArray(inputOptions.input)) {
177025
+ entries = inputOptions.input.reduce((prev, current) => {
177026
+ prev[basename(current)] = current;
177027
+ return prev;
177028
+ }, {});
177029
+ } else {
177030
+ entries = { ...inputOptions.input };
176995
177031
  }
176996
177032
  },
176997
177033
  transform(code, id) {
176998
- if (id.startsWith(virtualPrefix)) {
177034
+ if (!filter(id)) {
176999
177035
  return null;
177000
177036
  }
177001
177037
  if (vueRE.test(id)) {
@@ -177006,7 +177042,7 @@ ${cyan(
177006
177042
  project.createSourceFile(`${id}.${ext || "js"}`, content, { overwrite: true });
177007
177043
  }
177008
177044
  } else if (!id.includes(".vue?vue") && (tsRE.test(id) || allowJs && jsRE.test(id))) {
177009
- project.addSourceFileAtPath(id);
177045
+ project.createSourceFile(id, code, { overwrite: true });
177010
177046
  }
177011
177047
  return null;
177012
177048
  },
@@ -177028,18 +177064,12 @@ ${logPrefix} Start generate declaration files...`));
177028
177064
  isBundle = true;
177029
177065
  sourceDtsFiles.clear();
177030
177066
  const startTime = Date.now();
177031
- const tsConfig = typescript.readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
177032
- const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
177033
- const parentTsConfig = parentTsConfigPath ? typescript.readConfigFile(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
177034
- const include = options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*";
177035
- const exclude = options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**";
177036
- bundleDebug("read config");
177037
177067
  const includedFileSet = /* @__PURE__ */ new Set();
177038
177068
  if (include && include.length) {
177039
- const files = await glob(ensureArray(include).map(normalizeGlob), {
177069
+ const files = await glob(include, {
177040
177070
  cwd: root,
177041
177071
  absolute: true,
177042
- ignore: ensureArray(exclude).map(normalizeGlob)
177072
+ ignore: exclude
177043
177073
  });
177044
177074
  files.forEach((file) => {
177045
177075
  if (dtsRE.test(file)) {
@@ -177070,7 +177100,7 @@ ${logPrefix} Start generate declaration files...`));
177070
177100
  bundleDebug("resolve");
177071
177101
  if (!skipDiagnostics) {
177072
177102
  const diagnostics = project.getPreEmitDiagnostics();
177073
- if (diagnostics?.length && logDiagnostics) {
177103
+ if (diagnostics?.length) {
177074
177104
  logger.warn(project.formatDiagnosticsWithColorAndContext(diagnostics));
177075
177105
  }
177076
177106
  if (typeof afterDiagnostic === "function") {
@@ -177134,54 +177164,82 @@ ${logPrefix} Start generate declaration files...`));
177134
177164
  if (insertTypesEntry || rollupTypes) {
177135
177165
  const pkgPath = resolve(root, "package.json");
177136
177166
  const pkg = fs.existsSync(pkgPath) ? JSON.parse(await fs.readFile(pkgPath, "utf-8")) : {};
177167
+ const entryNames = Object.keys(entries);
177137
177168
  const types = pkg.types || pkg.typings;
177138
- let typesPath = types ? resolve(root, types) : resolve(outputDir, indexName);
177139
- if (!fs.existsSync(typesPath)) {
177140
- const entry = entries[0];
177141
- const outputIndex = resolve(outputDir, relative(entryRoot, entry.replace(tsRE, ".d.ts")));
177142
- let filePath = normalizePath(relative(dirname(typesPath), outputIndex));
177143
- filePath = filePath.replace(dtsRE, "");
177144
- filePath = fullRelativeRE.test(filePath) ? filePath : `./${filePath}`;
177145
- let content = `export * from '${filePath}'
177169
+ const multiple = entryNames.length > 1;
177170
+ const typesPath = types ? resolve(root, types) : resolve(outputDir, indexName);
177171
+ for (const name of entryNames) {
177172
+ let filePath = multiple ? resolve(outputDir, name.replace(tsRE, ".d.ts")) : typesPath;
177173
+ if (fs.existsSync(filePath))
177174
+ continue;
177175
+ const index = resolve(
177176
+ outputDir,
177177
+ relative(entryRoot, entries[name].replace(tsRE, ".d.ts"))
177178
+ );
177179
+ let fromPath = normalizePath(relative(dirname(filePath), index));
177180
+ fromPath = fromPath.replace(dtsRE, "");
177181
+ fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
177182
+ let content = `export * from '${fromPath}'
177146
177183
  `;
177147
- if (fs.existsSync(outputIndex)) {
177148
- const entryCodes = await fs.readFile(outputIndex, "utf-8");
177184
+ if (fs.existsSync(index)) {
177185
+ const entryCodes = await fs.readFile(index, "utf-8");
177149
177186
  if (entryCodes.includes("export default")) {
177150
- content += `import ${libName} from '${filePath}'
177187
+ content += `import ${libName} from '${fromPath}'
177151
177188
  export default ${libName}
177152
177189
  `;
177153
177190
  }
177154
177191
  }
177155
177192
  let result;
177156
177193
  if (typeof beforeWriteFile === "function") {
177157
- result = beforeWriteFile(typesPath, content);
177194
+ result = beforeWriteFile(filePath, content);
177158
177195
  if (result && isNativeObj(result)) {
177159
- typesPath = result.filePath ?? typesPath;
177196
+ filePath = result.filePath ?? filePath;
177160
177197
  content = result.content ?? content;
177161
177198
  }
177162
177199
  }
177163
177200
  if (result !== false) {
177164
- await fs.writeFile(typesPath, content, "utf-8");
177165
- wroteFiles.add(normalizePath(typesPath));
177201
+ await fs.writeFile(filePath, content, "utf-8");
177202
+ wroteFiles.add(normalizePath(filePath));
177166
177203
  }
177167
177204
  }
177168
177205
  bundleDebug("insert index");
177169
177206
  if (rollupTypes) {
177170
177207
  logger.info(green(`${logPrefix} Start rollup declaration files...`));
177171
- rollupDeclarationFiles({
177172
- root,
177173
- tsConfigPath,
177174
- compilerOptions,
177175
- outputDir,
177176
- entryPath: typesPath,
177177
- fileName: basename(typesPath)
177178
- });
177179
- const wroteFile = normalizePath(typesPath);
177180
- wroteFiles.delete(wroteFile);
177208
+ const rollupFiles = /* @__PURE__ */ new Set();
177209
+ if (multiple) {
177210
+ for (const name of entryNames) {
177211
+ const path = resolve(outputDir, name.replace(tsRE, ".d.ts"));
177212
+ rollupDeclarationFiles({
177213
+ root,
177214
+ tsConfigPath,
177215
+ compilerOptions,
177216
+ outputDir,
177217
+ entryPath: path,
177218
+ fileName: basename(path)
177219
+ });
177220
+ const wroteFile = normalizePath(path);
177221
+ wroteFiles.delete(wroteFile);
177222
+ rollupFiles.add(wroteFile);
177223
+ }
177224
+ } else {
177225
+ rollupDeclarationFiles({
177226
+ root,
177227
+ tsConfigPath,
177228
+ compilerOptions,
177229
+ outputDir,
177230
+ entryPath: typesPath,
177231
+ fileName: basename(typesPath)
177232
+ });
177233
+ const wroteFile = normalizePath(typesPath);
177234
+ wroteFiles.delete(wroteFile);
177235
+ rollupFiles.add(wroteFile);
177236
+ }
177181
177237
  await runParallel(os.cpus().length, Array.from(wroteFiles), (f) => fs.unlink(f));
177182
177238
  removeDirIfEmpty(outputDir);
177183
177239
  wroteFiles.clear();
177184
- wroteFiles.add(wroteFile);
177240
+ for (const file of rollupFiles) {
177241
+ wroteFiles.add(file);
177242
+ }
177185
177243
  if (copyDtsFiles) {
177186
177244
  await runParallel(os.cpus().length, dtsOutputFiles, async ({ path, content }) => {
177187
177245
  const filePath = resolve(outputDir, basename(path));
package/package.json CHANGED
@@ -6,7 +6,8 @@
6
6
  "url": "https://github.com/qmhc/vite-plugin-dts/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@microsoft/api-extractor": "^7.33.1",
9
+ "@microsoft/api-extractor": "^7.33.5",
10
+ "@rollup/pluginutils": "^5.0.2",
10
11
  "@rushstack/node-core-library": "^3.53.2",
11
12
  "debug": "^4.3.4",
12
13
  "fast-glob": "^3.2.12",
@@ -20,20 +21,20 @@
20
21
  "@types/debug": "^4.1.7",
21
22
  "@types/fs-extra": "^9.0.13",
22
23
  "@types/minimist": "^1.2.2",
23
- "@types/node": "^18.8.5",
24
+ "@types/node": "^18.11.7",
24
25
  "@types/prompts": "^2.4.1",
25
- "@types/semver": "^7.3.12",
26
- "@typescript-eslint/eslint-plugin": "^5.40.0",
27
- "@typescript-eslint/parser": "^5.40.0",
28
- "@vitejs/plugin-vue": "^3.1.2",
26
+ "@types/semver": "^7.3.13",
27
+ "@typescript-eslint/eslint-plugin": "^5.41.0",
28
+ "@typescript-eslint/parser": "^5.41.0",
29
+ "@vitejs/plugin-vue": "^3.2.0",
29
30
  "@vue/eslint-config-standard": "^8.0.1",
30
31
  "@vue/eslint-config-typescript": "^11.0.2",
31
32
  "conventional-changelog-cli": "^2.2.2",
32
33
  "cross-env": "^7.0.3",
33
- "eslint": "^8.25.0",
34
+ "eslint": "^8.26.0",
34
35
  "eslint-plugin-import": "^2.26.0",
35
36
  "eslint-plugin-node": "^11.1.0",
36
- "eslint-plugin-promise": "^6.1.0",
37
+ "eslint-plugin-promise": "^6.1.1",
37
38
  "eslint-plugin-vue": "^9.6.0",
38
39
  "execa": "^6.1.0",
39
40
  "husky": "^8.0.1",
@@ -46,18 +47,19 @@
46
47
  "prompts": "^2.4.2",
47
48
  "rimraf": "^3.0.2",
48
49
  "semver": "^7.3.8",
49
- "tsx": "^3.10.1",
50
+ "tsx": "^3.11.0",
50
51
  "typescript": "4.8.4",
51
- "unbuild": "^0.8.11",
52
- "vite": "^3.1.8",
53
- "vitest": "^0.24.1",
54
- "vue": "3.2.40"
52
+ "unbuild": "^0.9.4",
53
+ "vite": "^3.2.1",
54
+ "vitest": "^0.24.3",
55
+ "vue": "3.2.41"
55
56
  },
56
57
  "engines": {
57
58
  "node": "^14.18.0 || >=16.0.0"
58
59
  },
59
60
  "exports": {
60
61
  ".": {
62
+ "types": "./dist/index.d.ts",
61
63
  "require": "./dist/index.cjs",
62
64
  "import": "./dist/index.mjs"
63
65
  }
@@ -101,5 +103,5 @@
101
103
  },
102
104
  "type": "module",
103
105
  "types": "dist/index.d.ts",
104
- "version": "1.6.6"
106
+ "version": "1.7.1"
105
107
  }