vite-plugin-dts 3.3.1 → 3.5.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
@@ -185,7 +185,7 @@ function rollupDeclarationFiles({
185
185
  entryPath,
186
186
  fileName,
187
187
  libFolder,
188
- bundledPackages
188
+ rollupConfig = {}
189
189
  }) {
190
190
  const configObjectFullPath = node_path.resolve(root, "api-extractor.json");
191
191
  if (!dtsRE$1.test(fileName)) {
@@ -193,9 +193,9 @@ function rollupDeclarationFiles({
193
193
  }
194
194
  const extractorConfig = apiExtractor.ExtractorConfig.prepare({
195
195
  configObject: {
196
+ ...rollupConfig,
196
197
  projectFolder: root,
197
198
  mainEntryPointFilePath: entryPath,
198
- bundledPackages,
199
199
  compiler: {
200
200
  tsconfigFilePath: configPath,
201
201
  overrideTsconfig: {
@@ -205,17 +205,20 @@ function rollupDeclarationFiles({
205
205
  },
206
206
  apiReport: {
207
207
  enabled: false,
208
- reportFileName: "<unscopedPackageName>.api.md"
208
+ reportFileName: "<unscopedPackageName>.api.md",
209
+ ...rollupConfig.apiReport
209
210
  },
210
211
  docModel: {
211
- enabled: false
212
+ enabled: false,
213
+ ...rollupConfig.docModel
212
214
  },
213
215
  dtsRollup: {
214
216
  enabled: true,
215
217
  publicTrimmedFilePath: node_path.resolve(outDir, fileName)
216
218
  },
217
219
  tsdocMetadata: {
218
- enabled: false
220
+ enabled: false,
221
+ ...rollupConfig.tsdocMetadata
219
222
  },
220
223
  messages: {
221
224
  compilerMessageReporting: {
@@ -227,7 +230,8 @@ function rollupDeclarationFiles({
227
230
  default: {
228
231
  logLevel: "none"
229
232
  }
230
- }
233
+ },
234
+ ...rollupConfig.messages
231
235
  }
232
236
  },
233
237
  configObjectFullPath,
@@ -398,7 +402,7 @@ const dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
398
402
  const simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
399
403
  const simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
400
404
  function transformAliasImport(filePath, content, aliases, exclude = []) {
401
- if (!aliases.length)
405
+ if (!aliases?.length)
402
406
  return content;
403
407
  return content.replace(globalImportRE, (str) => {
404
408
  let matchResult = str.match(staticImportRE);
@@ -464,10 +468,10 @@ function dtsPlugin(options = {}) {
464
468
  cleanVueFileName = false,
465
469
  insertTypesEntry = false,
466
470
  rollupTypes = false,
467
- bundledPackages = [],
468
471
  pathsToAliases = true,
469
472
  aliasesExclude = [],
470
473
  copyDtsFiles = false,
474
+ declarationOnly = false,
471
475
  strictOutput = true,
472
476
  afterDiagnostic = noop,
473
477
  beforeWriteFile = noop,
@@ -500,6 +504,8 @@ function dtsPlugin(options = {}) {
500
504
  ]);
501
505
  const rootFiles = /* @__PURE__ */ new Set();
502
506
  const outputFiles = /* @__PURE__ */ new Map();
507
+ const rollupConfig = { ...options.rollupConfig || {} };
508
+ rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
503
509
  return {
504
510
  name: "vite:dts",
505
511
  apply: "build",
@@ -543,13 +549,11 @@ function dtsPlugin(options = {}) {
543
549
  }
544
550
  } else {
545
551
  logger.warn(
546
- kolorist.yellow(
547
- `
548
- ${kolorist.cyan(
549
- "[vite:dts]"
550
- )} 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
+ )}
551
556
  `
552
- )
553
557
  );
554
558
  libName = "_default";
555
559
  indexName = defaultIndex;
@@ -674,7 +678,7 @@ ${kolorist.cyan(
674
678
  } else {
675
679
  const sourceFile = program.getSourceFile(id);
676
680
  if (sourceFile) {
677
- for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
681
+ for (const outputFile of service.getEmitOutput(sourceFile.fileName, true, true).outputFiles) {
678
682
  outputFiles.set(
679
683
  resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(outputFile.name, outDir))),
680
684
  outputFile.text
@@ -799,7 +803,17 @@ ${logPrefix} Start generate declaration files...`));
799
803
  const entryNames = Object.keys(entries);
800
804
  const types = pkg.types || pkg.typings || pkg.publishConfig?.types || pkg.publishConfig?.typings || (pkg.exports?.["."] || pkg.exports?.["./"])?.types;
801
805
  const multiple = entryNames.length > 1;
802
- const typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
806
+ let typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
807
+ if (!multiple && !dtsRE.test(typesPath)) {
808
+ logger.warn(
809
+ `
810
+ ${logPrefix} ${kolorist.yellow(
811
+ "The resolved path of type entry is not ending with '.d.ts'."
812
+ )}
813
+ `
814
+ );
815
+ typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
816
+ }
803
817
  for (const name of entryNames) {
804
818
  const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
805
819
  if (node_fs.existsSync(path))
@@ -847,7 +861,7 @@ export default ${libName}
847
861
  entryPath: path,
848
862
  fileName: node_path.basename(path),
849
863
  libFolder,
850
- bundledPackages
864
+ rollupConfig
851
865
  });
852
866
  emittedFiles.delete(path);
853
867
  rollupFiles.add(path);
@@ -861,7 +875,7 @@ export default ${libName}
861
875
  entryPath: typesPath,
862
876
  fileName: node_path.basename(typesPath),
863
877
  libFolder,
864
- bundledPackages
878
+ rollupConfig
865
879
  });
866
880
  emittedFiles.delete(typesPath);
867
881
  rollupFiles.add(typesPath);
@@ -909,6 +923,13 @@ export default ${libName}
909
923
  kolorist.green(`${logPrefix} Declaration files built in ${timeRecord + Date.now() - startTime}ms.
910
924
  `)
911
925
  );
926
+ },
927
+ generateBundle(_, bundle) {
928
+ if (declarationOnly) {
929
+ for (const id of Object.keys(bundle)) {
930
+ delete bundle[id];
931
+ }
932
+ }
912
933
  }
913
934
  };
914
935
  }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import * as vite from 'vite';
2
2
  import { LogLevel } from 'vite';
3
3
  import ts from 'typescript';
4
+ import { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
4
5
 
5
6
  type MaybePromise<T> = T | Promise<T>;
7
+ type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
6
8
  interface Resolver {
7
9
  /**
8
10
  * The name of the resolver
@@ -155,6 +157,13 @@ interface PluginOptions {
155
157
  * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
156
158
  */
157
159
  bundledPackages?: string[];
160
+ /**
161
+ * Override the config of `@microsoft/api-extractor`
162
+ *
163
+ * @default null
164
+ * @see https://api-extractor.com/pages/setup/configure_api_report/
165
+ */
166
+ rollupConfig?: RollupConfig;
158
167
  /**
159
168
  * Whether to copy .d.ts source files to `outDir`
160
169
  *
@@ -162,6 +171,14 @@ interface PluginOptions {
162
171
  * @remarks Before 2.0, the default was `true`
163
172
  */
164
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;
165
182
  /**
166
183
  * Logging level for this plugin
167
184
  *
package/dist/index.mjs CHANGED
@@ -185,7 +185,7 @@ function rollupDeclarationFiles({
185
185
  entryPath,
186
186
  fileName,
187
187
  libFolder,
188
- bundledPackages
188
+ rollupConfig = {}
189
189
  }) {
190
190
  const configObjectFullPath = resolve$1(root, "api-extractor.json");
191
191
  if (!dtsRE$1.test(fileName)) {
@@ -193,9 +193,9 @@ function rollupDeclarationFiles({
193
193
  }
194
194
  const extractorConfig = ExtractorConfig.prepare({
195
195
  configObject: {
196
+ ...rollupConfig,
196
197
  projectFolder: root,
197
198
  mainEntryPointFilePath: entryPath,
198
- bundledPackages,
199
199
  compiler: {
200
200
  tsconfigFilePath: configPath,
201
201
  overrideTsconfig: {
@@ -205,17 +205,20 @@ function rollupDeclarationFiles({
205
205
  },
206
206
  apiReport: {
207
207
  enabled: false,
208
- reportFileName: "<unscopedPackageName>.api.md"
208
+ reportFileName: "<unscopedPackageName>.api.md",
209
+ ...rollupConfig.apiReport
209
210
  },
210
211
  docModel: {
211
- enabled: false
212
+ enabled: false,
213
+ ...rollupConfig.docModel
212
214
  },
213
215
  dtsRollup: {
214
216
  enabled: true,
215
217
  publicTrimmedFilePath: resolve$1(outDir, fileName)
216
218
  },
217
219
  tsdocMetadata: {
218
- enabled: false
220
+ enabled: false,
221
+ ...rollupConfig.tsdocMetadata
219
222
  },
220
223
  messages: {
221
224
  compilerMessageReporting: {
@@ -227,7 +230,8 @@ function rollupDeclarationFiles({
227
230
  default: {
228
231
  logLevel: "none"
229
232
  }
230
- }
233
+ },
234
+ ...rollupConfig.messages
231
235
  }
232
236
  },
233
237
  configObjectFullPath,
@@ -398,7 +402,7 @@ const dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
398
402
  const simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
399
403
  const simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
400
404
  function transformAliasImport(filePath, content, aliases, exclude = []) {
401
- if (!aliases.length)
405
+ if (!aliases?.length)
402
406
  return content;
403
407
  return content.replace(globalImportRE, (str) => {
404
408
  let matchResult = str.match(staticImportRE);
@@ -464,10 +468,10 @@ function dtsPlugin(options = {}) {
464
468
  cleanVueFileName = false,
465
469
  insertTypesEntry = false,
466
470
  rollupTypes = false,
467
- bundledPackages = [],
468
471
  pathsToAliases = true,
469
472
  aliasesExclude = [],
470
473
  copyDtsFiles = false,
474
+ declarationOnly = false,
471
475
  strictOutput = true,
472
476
  afterDiagnostic = noop,
473
477
  beforeWriteFile = noop,
@@ -500,6 +504,8 @@ function dtsPlugin(options = {}) {
500
504
  ]);
501
505
  const rootFiles = /* @__PURE__ */ new Set();
502
506
  const outputFiles = /* @__PURE__ */ new Map();
507
+ const rollupConfig = { ...options.rollupConfig || {} };
508
+ rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
503
509
  return {
504
510
  name: "vite:dts",
505
511
  apply: "build",
@@ -543,13 +549,11 @@ function dtsPlugin(options = {}) {
543
549
  }
544
550
  } else {
545
551
  logger.warn(
546
- yellow(
547
- `
548
- ${cyan(
549
- "[vite:dts]"
550
- )} 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
+ )}
551
556
  `
552
- )
553
557
  );
554
558
  libName = "_default";
555
559
  indexName = defaultIndex;
@@ -674,7 +678,7 @@ ${cyan(
674
678
  } else {
675
679
  const sourceFile = program.getSourceFile(id);
676
680
  if (sourceFile) {
677
- for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
681
+ for (const outputFile of service.getEmitOutput(sourceFile.fileName, true, true).outputFiles) {
678
682
  outputFiles.set(
679
683
  resolve(publicRoot, relative(outDir, ensureAbsolute(outputFile.name, outDir))),
680
684
  outputFile.text
@@ -799,7 +803,17 @@ ${logPrefix} Start generate declaration files...`));
799
803
  const entryNames = Object.keys(entries);
800
804
  const types = pkg.types || pkg.typings || pkg.publishConfig?.types || pkg.publishConfig?.typings || (pkg.exports?.["."] || pkg.exports?.["./"])?.types;
801
805
  const multiple = entryNames.length > 1;
802
- const typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
806
+ let typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
807
+ if (!multiple && !dtsRE.test(typesPath)) {
808
+ logger.warn(
809
+ `
810
+ ${logPrefix} ${yellow(
811
+ "The resolved path of type entry is not ending with '.d.ts'."
812
+ )}
813
+ `
814
+ );
815
+ typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
816
+ }
803
817
  for (const name of entryNames) {
804
818
  const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
805
819
  if (existsSync(path))
@@ -847,7 +861,7 @@ export default ${libName}
847
861
  entryPath: path,
848
862
  fileName: basename(path),
849
863
  libFolder,
850
- bundledPackages
864
+ rollupConfig
851
865
  });
852
866
  emittedFiles.delete(path);
853
867
  rollupFiles.add(path);
@@ -861,7 +875,7 @@ export default ${libName}
861
875
  entryPath: typesPath,
862
876
  fileName: basename(typesPath),
863
877
  libFolder,
864
- bundledPackages
878
+ rollupConfig
865
879
  });
866
880
  emittedFiles.delete(typesPath);
867
881
  rollupFiles.add(typesPath);
@@ -909,6 +923,13 @@ export default ${libName}
909
923
  green(`${logPrefix} Declaration files built in ${timeRecord + Date.now() - startTime}ms.
910
924
  `)
911
925
  );
926
+ },
927
+ generateBundle(_, bundle) {
928
+ if (declarationOnly) {
929
+ for (const id of Object.keys(bundle)) {
930
+ delete bundle[id];
931
+ }
932
+ }
912
933
  }
913
934
  };
914
935
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.3.1",
3
+ "version": "3.5.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",
@@ -53,46 +53,43 @@
53
53
  "typescript"
54
54
  ],
55
55
  "dependencies": {
56
- "@microsoft/api-extractor": "^7.36.0",
56
+ "@microsoft/api-extractor": "^7.36.3",
57
57
  "@rollup/pluginutils": "^5.0.2",
58
- "@vue/language-core": "^1.8.1",
58
+ "@vue/language-core": "^1.8.8",
59
59
  "debug": "^4.3.4",
60
60
  "kolorist": "^1.8.0",
61
- "vue-tsc": "^1.8.1"
61
+ "vue-tsc": "^1.8.8"
62
62
  },
63
63
  "devDependencies": {
64
- "@commitlint/cli": "^17.6.6",
65
- "@commitlint/config-conventional": "^17.6.6",
64
+ "@commitlint/cli": "^17.6.7",
66
65
  "@types/debug": "^4.1.8",
67
66
  "@types/minimist": "^1.2.2",
68
- "@types/node": "^20.3.1",
67
+ "@types/node": "^20.4.5",
69
68
  "@types/prompts": "^2.4.4",
70
69
  "@types/semver": "^7.5.0",
71
- "@typescript-eslint/eslint-plugin": "^5.60.0",
72
- "@typescript-eslint/parser": "^5.60.0",
73
- "@vexip-ui/commitlint-config": "^0.1.0",
74
- "@vexip-ui/eslint-config": "^0.6.3",
70
+ "@vexip-ui/commitlint-config": "^0.2.0",
71
+ "@vexip-ui/eslint-config": "^0.8.1",
75
72
  "@vexip-ui/prettier-config": "^0.2.0",
76
73
  "@vue/eslint-config-standard": "^8.0.1",
77
74
  "@vue/eslint-config-typescript": "^11.0.3",
78
75
  "conventional-changelog-cli": "^3.0.0",
79
- "eslint": "^8.43.0",
80
- "execa": "^7.1.1",
76
+ "eslint": "^8.46.0",
77
+ "execa": "^7.2.0",
81
78
  "husky": "^8.0.3",
82
79
  "is-ci": "^3.0.1",
83
- "lint-staged": "^13.2.2",
80
+ "lint-staged": "^13.2.3",
84
81
  "minimist": "^1.2.8",
85
82
  "pinst": "^3.0.0",
86
83
  "prettier": "^2.8.8",
87
84
  "pretty-quick": "^3.1.3",
88
85
  "prompts": "^2.4.2",
89
86
  "rimraf": "^5.0.1",
90
- "semver": "^7.5.3",
87
+ "semver": "^7.5.4",
91
88
  "tsx": "^3.12.7",
92
89
  "typescript": "5.0.4",
93
90
  "unbuild": "^1.2.1",
94
- "vite": "^4.3.9",
95
- "vitest": "^0.32.2"
91
+ "vite": "^4.4.7",
92
+ "vitest": "^0.33.0"
96
93
  },
97
94
  "peerDependencies": {
98
95
  "typescript": "*",