vite-plugin-dts 3.5.4 → 3.6.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/README.md CHANGED
@@ -90,7 +90,7 @@ This is an existing [TypeScript issue](https://github.com/microsoft/TypeScript/i
90
90
 
91
91
  ```ts
92
92
  import type ts from 'typescript'
93
- import type { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor'
93
+ import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
94
94
  import type { LogLevel } from 'vite'
95
95
 
96
96
  type MaybePromise<T> = T | Promise<T>
@@ -278,6 +278,14 @@ export interface PluginOptions {
278
278
  */
279
279
  rollupConfig?: RollupConfig,
280
280
 
281
+ /**
282
+ * Override the invoke options of `@microsoft/api-extractor`
283
+ *
284
+ * @default null
285
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
286
+ */
287
+ rollupOptions?: IExtractorInvokeOptions,
288
+
281
289
  /**
282
290
  * Whether to copy .d.ts source files to `outDir`
283
291
  *
package/README.zh-CN.md CHANGED
@@ -90,7 +90,7 @@ export default defineConfig({
90
90
 
91
91
  ```ts
92
92
  import type ts from 'typescript'
93
- import type { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor'
93
+ import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
94
94
  import type { LogLevel } from 'vite'
95
95
 
96
96
  type MaybePromise<T> = T | Promise<T>
@@ -278,6 +278,14 @@ export interface PluginOptions {
278
278
  */
279
279
  rollupConfig?: RollupConfig,
280
280
 
281
+ /**
282
+ * 覆写 `@microsoft/api-extractor` 的调用选项
283
+ *
284
+ * @default null
285
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
286
+ */
287
+ rollupOptions?: IExtractorInvokeOptions,
288
+
281
289
  /**
282
290
  * 是否将源码里的 .d.ts 文件复制到 `outDir`
283
291
  *
package/dist/index.cjs CHANGED
@@ -195,7 +195,8 @@ function rollupDeclarationFiles({
195
195
  entryPath,
196
196
  fileName,
197
197
  libFolder,
198
- rollupConfig = {}
198
+ rollupConfig = {},
199
+ rollupOptions = {}
199
200
  }) {
200
201
  const configObjectFullPath = node_path.resolve(root, "api-extractor.json");
201
202
  if (!dtsRE$1.test(fileName)) {
@@ -251,7 +252,8 @@ function rollupDeclarationFiles({
251
252
  localBuild: false,
252
253
  showVerboseMessages: false,
253
254
  showDiagnostics: false,
254
- typescriptCompilerFolder: libFolder ? node_path.resolve(libFolder) : void 0
255
+ typescriptCompilerFolder: libFolder ? node_path.resolve(libFolder) : void 0,
256
+ ...rollupOptions
255
257
  });
256
258
  return result.succeeded;
257
259
  }
@@ -480,6 +482,7 @@ function dtsPlugin(options = {}) {
480
482
  rollupTypes = false,
481
483
  pathsToAliases = true,
482
484
  aliasesExclude = [],
485
+ rollupOptions = {},
483
486
  copyDtsFiles = false,
484
487
  declarationOnly = false,
485
488
  strictOutput = true,
@@ -600,6 +603,9 @@ ${logPrefix} ${kolorist.yellow(
600
603
  configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts__default.findConfigFile(root, ts__default.sys.fileExists);
601
604
  const content = configPath ? languageCore.createParsedCommandLine(ts__default, ts__default.sys, configPath) : void 0;
602
605
  compilerOptions = {
606
+ // (#277) If user don't specify `moduleResolution` in top config file,
607
+ // declaration of Vue files will be inferred to `any` type.
608
+ moduleResolution: ts__default.ModuleResolutionKind.Node10,
603
609
  ...content?.options || {},
604
610
  ...options.compilerOptions || {},
605
611
  ...fixedCompilerOptions,
@@ -637,9 +643,18 @@ ${logPrefix} ${kolorist.yellow(
637
643
  include = computeGlobs(options.include, content?.raw.include, "**/*");
638
644
  exclude = computeGlobs(options.exclude, content?.raw.exclude, "node_modules/**");
639
645
  filter = pluginutils.createFilter(include, exclude);
640
- const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
641
- host = ts__default.createCompilerHost(compilerOptions, true);
642
- program = vueTsc.createProgram({ host, rootNames, options: compilerOptions });
646
+ const rootNames = [
647
+ ...new Set(
648
+ Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath)
649
+ )
650
+ ];
651
+ host = ts__default.createCompilerHost(compilerOptions);
652
+ program = vueTsc.createProgram({
653
+ host,
654
+ rootNames,
655
+ projectReferences: content?.projectReferences,
656
+ options: compilerOptions
657
+ });
643
658
  libName = toCapitalCase(libName || "_default");
644
659
  indexName = indexName || defaultIndex;
645
660
  const maybeEmitted = (sourceFile) => {
@@ -774,6 +789,7 @@ ${logPrefix} Start generate declaration files...`));
774
789
  }
775
790
  bundleDebug("emit output patch");
776
791
  const currentDir = host.getCurrentDirectory();
792
+ const vuePathRE = /['"](.+)\.vue['"]/g;
777
793
  await runParallel(
778
794
  node_os.cpus().length,
779
795
  Array.from(outputFiles.entries()),
@@ -789,7 +805,7 @@ ${logPrefix} Start generate declaration files...`));
789
805
  outDir,
790
806
  node_path.relative(entryRoot, cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path)
791
807
  );
792
- content = cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content;
808
+ content = cleanVueFileName ? content.replace(vuePathRE, '"$1"') : content;
793
809
  if (isMapFile) {
794
810
  try {
795
811
  const sourceMap = JSON.parse(content);
@@ -820,7 +836,10 @@ ${logPrefix} Start generate declaration files...`));
820
836
  const entryNames = Object.keys(entries);
821
837
  const types = fileTypesPath(pkg.publishConfig, pkg);
822
838
  const multiple = entryNames.length > 1;
823
- let typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
839
+ const cleanPath = (path) => {
840
+ return cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path;
841
+ };
842
+ let typesPath = cleanPath(types ? resolve(root, types) : resolve(outDir, indexName));
824
843
  if (!multiple && !dtsRE.test(typesPath)) {
825
844
  logger.warn(
826
845
  `
@@ -832,12 +851,11 @@ ${logPrefix} ${kolorist.yellow(
832
851
  typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
833
852
  }
834
853
  for (const name of entryNames) {
835
- const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
854
+ const path = multiple ? cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`)) : typesPath;
836
855
  if (node_fs.existsSync(path))
837
856
  continue;
838
- const index = resolve(
839
- outDir,
840
- node_path.relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`)
857
+ const index = cleanPath(
858
+ resolve(outDir, node_path.relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`))
841
859
  );
842
860
  let fromPath = normalizePath(node_path.relative(node_path.dirname(path), index));
843
861
  fromPath = fromPath.replace(dtsRE, "");
@@ -852,7 +870,7 @@ export default ${libName}
852
870
  `;
853
871
  }
854
872
  }
855
- await writeOutput(path, content, outDir);
873
+ await writeOutput(cleanPath(path), content, outDir);
856
874
  }
857
875
  bundleDebug("insert index");
858
876
  if (rollupTypes) {
@@ -869,7 +887,7 @@ export default ${libName}
869
887
  const rollupFiles = /* @__PURE__ */ new Set();
870
888
  if (multiple) {
871
889
  for (const name of entryNames) {
872
- const path = resolve(outDir, `${name.replace(tsRE, "")}.d.ts`);
890
+ const path = cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`));
873
891
  rollupDeclarationFiles({
874
892
  root,
875
893
  configPath,
@@ -878,7 +896,8 @@ export default ${libName}
878
896
  entryPath: path,
879
897
  fileName: node_path.basename(path),
880
898
  libFolder,
881
- rollupConfig
899
+ rollupConfig,
900
+ rollupOptions
882
901
  });
883
902
  emittedFiles.delete(path);
884
903
  rollupFiles.add(path);
@@ -892,7 +911,8 @@ export default ${libName}
892
911
  entryPath: typesPath,
893
912
  fileName: node_path.basename(typesPath),
894
913
  libFolder,
895
- rollupConfig
914
+ rollupConfig,
915
+ rollupOptions
896
916
  });
897
917
  emittedFiles.delete(typesPath);
898
918
  rollupFiles.add(typesPath);
@@ -0,0 +1,226 @@
1
+ import * as vite from 'vite';
2
+ import { LogLevel } from 'vite';
3
+ import ts from 'typescript';
4
+ import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
5
+
6
+ type MaybePromise<T> = T | Promise<T>;
7
+ type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
8
+ interface Resolver {
9
+ /**
10
+ * The name of the resolver
11
+ *
12
+ * The later resolver with the same name will overwrite the earlier
13
+ */
14
+ name: string;
15
+ /**
16
+ * Determine whether the resolver supports the file
17
+ */
18
+ supports: (id: string) => void | boolean;
19
+ /**
20
+ * Transform source to declaration files
21
+ *
22
+ * Note that the path of the returns should base on `outDir`, or relative path to `root`
23
+ */
24
+ transform: (payload: {
25
+ id: string;
26
+ code: string;
27
+ root: string;
28
+ outDir: string;
29
+ host: ts.CompilerHost;
30
+ program: ts.Program;
31
+ service: ts.LanguageService;
32
+ }) => MaybePromise<{
33
+ path: string;
34
+ content: string;
35
+ }[]>;
36
+ }
37
+ interface PluginOptions {
38
+ /**
39
+ * Specify root directory
40
+ *
41
+ * Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
42
+ */
43
+ root?: string;
44
+ /**
45
+ * Output directory for declaration files
46
+ *
47
+ * Can be an array to output to multiple directories
48
+ *
49
+ * Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
50
+ */
51
+ outDir?: string | string[];
52
+ /**
53
+ * Override root path of entry files (useful in monorepos)
54
+ *
55
+ * The output path of each file will be calculated based on the value provided
56
+ *
57
+ * The default is the smallest public path for all source files
58
+ */
59
+ entryRoot?: string;
60
+ /**
61
+ * Restrict declaration files output to `outDir`
62
+ *
63
+ * If true, generated declaration files outside `outDir` will be ignored
64
+ *
65
+ * @default true
66
+ */
67
+ strictOutput?: boolean;
68
+ /**
69
+ * Override compilerOptions
70
+ *
71
+ * @default null
72
+ */
73
+ compilerOptions?: ts.CompilerOptions | null;
74
+ /**
75
+ * Specify tsconfig.json path
76
+ *
77
+ * Plugin resolves `include` and `exclude` globs from tsconfig.json
78
+ *
79
+ * If not specified, plugin will find config file from root
80
+ */
81
+ tsconfigPath?: string;
82
+ /**
83
+ * Specify custom resolvers
84
+ *
85
+ * @default []
86
+ */
87
+ resolvers?: Resolver[];
88
+ /**
89
+ * Parsing `paths` of tsconfig.json to aliases
90
+ *
91
+ * Note that these aliases only use for declaration files
92
+ *
93
+ * @default true
94
+ * @remarks Only use first replacement of each path
95
+ */
96
+ pathsToAliases?: boolean;
97
+ /**
98
+ * Set which paths should be excluded when transforming aliases
99
+ *
100
+ * @default []
101
+ */
102
+ aliasesExclude?: (string | RegExp)[];
103
+ /**
104
+ * Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
105
+ *
106
+ * @default false
107
+ */
108
+ cleanVueFileName?: boolean;
109
+ /**
110
+ * Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
111
+ *
112
+ * Value is forced to `true` when `rollupTypes` is `true`
113
+ *
114
+ * @default false
115
+ */
116
+ staticImport?: boolean;
117
+ /**
118
+ * Override `include` glob (relative to root)
119
+ *
120
+ * Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
121
+ */
122
+ include?: string | string[];
123
+ /**
124
+ * Override `exclude` glob
125
+ *
126
+ * Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
127
+ */
128
+ exclude?: string | string[];
129
+ /**
130
+ * Whether to remove `import 'xxx'`
131
+ *
132
+ * @default true
133
+ */
134
+ clearPureImport?: boolean;
135
+ /**
136
+ * Whether to generate types entry file(s)
137
+ *
138
+ * When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
139
+ *
140
+ * Value is forced to `true` when `rollupTypes` is `true`
141
+ *
142
+ * @default false
143
+ */
144
+ insertTypesEntry?: boolean;
145
+ /**
146
+ * Rollup type declaration files after emitting them
147
+ *
148
+ * Powered by `@microsoft/api-extractor` - time-intensive operation
149
+ *
150
+ * @default false
151
+ */
152
+ rollupTypes?: boolean;
153
+ /**
154
+ * Bundled packages for `@microsoft/api-extractor`
155
+ *
156
+ * @default []
157
+ * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
158
+ */
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;
167
+ /**
168
+ * Override the invoke options of `@microsoft/api-extractor`
169
+ *
170
+ * @default null
171
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
172
+ */
173
+ rollupOptions?: IExtractorInvokeOptions;
174
+ /**
175
+ * Whether to copy .d.ts source files to `outDir`
176
+ *
177
+ * @default false
178
+ * @remarks Before 2.0, the default was `true`
179
+ */
180
+ copyDtsFiles?: boolean;
181
+ /**
182
+ * Whether to emit declaration files only
183
+ *
184
+ * When `true`, all the original outputs of vite (rollup) will be force removed
185
+ *
186
+ * @default false
187
+ */
188
+ declarationOnly?: boolean;
189
+ /**
190
+ * Logging level for this plugin
191
+ *
192
+ * Defaults to the 'logLevel' property of your Vite config
193
+ */
194
+ logLevel?: LogLevel;
195
+ /**
196
+ * Hook called after diagnostic is emitted
197
+ *
198
+ * According to the `diagnostics.length`, you can judge whether there is any type error
199
+ *
200
+ * @default () => {}
201
+ */
202
+ afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
203
+ /**
204
+ * Hook called prior to writing each declaration file
205
+ *
206
+ * This allows you to transform the path or content
207
+ *
208
+ * The file will be skipped when the return value `false` or `Promise<false>`
209
+ *
210
+ * @default () => {}
211
+ */
212
+ beforeWriteFile?: (filePath: string, content: string) => MaybePromise<void | false | {
213
+ filePath?: string;
214
+ content?: string;
215
+ }>;
216
+ /**
217
+ * Hook called after all declaration files are written
218
+ *
219
+ * @default () => {}
220
+ */
221
+ afterBuild?: () => MaybePromise<void>;
222
+ }
223
+
224
+ declare function dtsPlugin(options?: PluginOptions): vite.Plugin;
225
+
226
+ export { type PluginOptions, dtsPlugin as default };
@@ -0,0 +1,226 @@
1
+ import * as vite from 'vite';
2
+ import { LogLevel } from 'vite';
3
+ import ts from 'typescript';
4
+ import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
5
+
6
+ type MaybePromise<T> = T | Promise<T>;
7
+ type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
8
+ interface Resolver {
9
+ /**
10
+ * The name of the resolver
11
+ *
12
+ * The later resolver with the same name will overwrite the earlier
13
+ */
14
+ name: string;
15
+ /**
16
+ * Determine whether the resolver supports the file
17
+ */
18
+ supports: (id: string) => void | boolean;
19
+ /**
20
+ * Transform source to declaration files
21
+ *
22
+ * Note that the path of the returns should base on `outDir`, or relative path to `root`
23
+ */
24
+ transform: (payload: {
25
+ id: string;
26
+ code: string;
27
+ root: string;
28
+ outDir: string;
29
+ host: ts.CompilerHost;
30
+ program: ts.Program;
31
+ service: ts.LanguageService;
32
+ }) => MaybePromise<{
33
+ path: string;
34
+ content: string;
35
+ }[]>;
36
+ }
37
+ interface PluginOptions {
38
+ /**
39
+ * Specify root directory
40
+ *
41
+ * Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
42
+ */
43
+ root?: string;
44
+ /**
45
+ * Output directory for declaration files
46
+ *
47
+ * Can be an array to output to multiple directories
48
+ *
49
+ * Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
50
+ */
51
+ outDir?: string | string[];
52
+ /**
53
+ * Override root path of entry files (useful in monorepos)
54
+ *
55
+ * The output path of each file will be calculated based on the value provided
56
+ *
57
+ * The default is the smallest public path for all source files
58
+ */
59
+ entryRoot?: string;
60
+ /**
61
+ * Restrict declaration files output to `outDir`
62
+ *
63
+ * If true, generated declaration files outside `outDir` will be ignored
64
+ *
65
+ * @default true
66
+ */
67
+ strictOutput?: boolean;
68
+ /**
69
+ * Override compilerOptions
70
+ *
71
+ * @default null
72
+ */
73
+ compilerOptions?: ts.CompilerOptions | null;
74
+ /**
75
+ * Specify tsconfig.json path
76
+ *
77
+ * Plugin resolves `include` and `exclude` globs from tsconfig.json
78
+ *
79
+ * If not specified, plugin will find config file from root
80
+ */
81
+ tsconfigPath?: string;
82
+ /**
83
+ * Specify custom resolvers
84
+ *
85
+ * @default []
86
+ */
87
+ resolvers?: Resolver[];
88
+ /**
89
+ * Parsing `paths` of tsconfig.json to aliases
90
+ *
91
+ * Note that these aliases only use for declaration files
92
+ *
93
+ * @default true
94
+ * @remarks Only use first replacement of each path
95
+ */
96
+ pathsToAliases?: boolean;
97
+ /**
98
+ * Set which paths should be excluded when transforming aliases
99
+ *
100
+ * @default []
101
+ */
102
+ aliasesExclude?: (string | RegExp)[];
103
+ /**
104
+ * Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
105
+ *
106
+ * @default false
107
+ */
108
+ cleanVueFileName?: boolean;
109
+ /**
110
+ * Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
111
+ *
112
+ * Value is forced to `true` when `rollupTypes` is `true`
113
+ *
114
+ * @default false
115
+ */
116
+ staticImport?: boolean;
117
+ /**
118
+ * Override `include` glob (relative to root)
119
+ *
120
+ * Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
121
+ */
122
+ include?: string | string[];
123
+ /**
124
+ * Override `exclude` glob
125
+ *
126
+ * Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
127
+ */
128
+ exclude?: string | string[];
129
+ /**
130
+ * Whether to remove `import 'xxx'`
131
+ *
132
+ * @default true
133
+ */
134
+ clearPureImport?: boolean;
135
+ /**
136
+ * Whether to generate types entry file(s)
137
+ *
138
+ * When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
139
+ *
140
+ * Value is forced to `true` when `rollupTypes` is `true`
141
+ *
142
+ * @default false
143
+ */
144
+ insertTypesEntry?: boolean;
145
+ /**
146
+ * Rollup type declaration files after emitting them
147
+ *
148
+ * Powered by `@microsoft/api-extractor` - time-intensive operation
149
+ *
150
+ * @default false
151
+ */
152
+ rollupTypes?: boolean;
153
+ /**
154
+ * Bundled packages for `@microsoft/api-extractor`
155
+ *
156
+ * @default []
157
+ * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
158
+ */
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;
167
+ /**
168
+ * Override the invoke options of `@microsoft/api-extractor`
169
+ *
170
+ * @default null
171
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
172
+ */
173
+ rollupOptions?: IExtractorInvokeOptions;
174
+ /**
175
+ * Whether to copy .d.ts source files to `outDir`
176
+ *
177
+ * @default false
178
+ * @remarks Before 2.0, the default was `true`
179
+ */
180
+ copyDtsFiles?: boolean;
181
+ /**
182
+ * Whether to emit declaration files only
183
+ *
184
+ * When `true`, all the original outputs of vite (rollup) will be force removed
185
+ *
186
+ * @default false
187
+ */
188
+ declarationOnly?: boolean;
189
+ /**
190
+ * Logging level for this plugin
191
+ *
192
+ * Defaults to the 'logLevel' property of your Vite config
193
+ */
194
+ logLevel?: LogLevel;
195
+ /**
196
+ * Hook called after diagnostic is emitted
197
+ *
198
+ * According to the `diagnostics.length`, you can judge whether there is any type error
199
+ *
200
+ * @default () => {}
201
+ */
202
+ afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>;
203
+ /**
204
+ * Hook called prior to writing each declaration file
205
+ *
206
+ * This allows you to transform the path or content
207
+ *
208
+ * The file will be skipped when the return value `false` or `Promise<false>`
209
+ *
210
+ * @default () => {}
211
+ */
212
+ beforeWriteFile?: (filePath: string, content: string) => MaybePromise<void | false | {
213
+ filePath?: string;
214
+ content?: string;
215
+ }>;
216
+ /**
217
+ * Hook called after all declaration files are written
218
+ *
219
+ * @default () => {}
220
+ */
221
+ afterBuild?: () => MaybePromise<void>;
222
+ }
223
+
224
+ declare function dtsPlugin(options?: PluginOptions): vite.Plugin;
225
+
226
+ export { type PluginOptions, dtsPlugin as default };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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
+ import { IExtractorInvokeOptions, IExtractorConfigPrepareOptions } from '@microsoft/api-extractor';
5
5
 
6
6
  type MaybePromise<T> = T | Promise<T>;
7
7
  type RollupConfig = Omit<IExtractorConfigPrepareOptions['configObject'], 'projectFolder' | 'mainEntryPointFilePath' | 'compiler' | 'dtsRollup'>;
@@ -164,6 +164,13 @@ interface PluginOptions {
164
164
  * @see https://api-extractor.com/pages/setup/configure_api_report/
165
165
  */
166
166
  rollupConfig?: RollupConfig;
167
+ /**
168
+ * Override the invoke options of `@microsoft/api-extractor`
169
+ *
170
+ * @default null
171
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
172
+ */
173
+ rollupOptions?: IExtractorInvokeOptions;
167
174
  /**
168
175
  * Whether to copy .d.ts source files to `outDir`
169
176
  *
@@ -216,4 +223,4 @@ interface PluginOptions {
216
223
 
217
224
  declare function dtsPlugin(options?: PluginOptions): vite.Plugin;
218
225
 
219
- export { PluginOptions, dtsPlugin as default };
226
+ export { type PluginOptions, dtsPlugin as default };
package/dist/index.mjs CHANGED
@@ -195,7 +195,8 @@ function rollupDeclarationFiles({
195
195
  entryPath,
196
196
  fileName,
197
197
  libFolder,
198
- rollupConfig = {}
198
+ rollupConfig = {},
199
+ rollupOptions = {}
199
200
  }) {
200
201
  const configObjectFullPath = resolve$1(root, "api-extractor.json");
201
202
  if (!dtsRE$1.test(fileName)) {
@@ -251,7 +252,8 @@ function rollupDeclarationFiles({
251
252
  localBuild: false,
252
253
  showVerboseMessages: false,
253
254
  showDiagnostics: false,
254
- typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0
255
+ typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0,
256
+ ...rollupOptions
255
257
  });
256
258
  return result.succeeded;
257
259
  }
@@ -480,6 +482,7 @@ function dtsPlugin(options = {}) {
480
482
  rollupTypes = false,
481
483
  pathsToAliases = true,
482
484
  aliasesExclude = [],
485
+ rollupOptions = {},
483
486
  copyDtsFiles = false,
484
487
  declarationOnly = false,
485
488
  strictOutput = true,
@@ -600,6 +603,9 @@ ${logPrefix} ${yellow(
600
603
  configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts.findConfigFile(root, ts.sys.fileExists);
601
604
  const content = configPath ? createParsedCommandLine(ts, ts.sys, configPath) : void 0;
602
605
  compilerOptions = {
606
+ // (#277) If user don't specify `moduleResolution` in top config file,
607
+ // declaration of Vue files will be inferred to `any` type.
608
+ moduleResolution: ts.ModuleResolutionKind.Node10,
603
609
  ...content?.options || {},
604
610
  ...options.compilerOptions || {},
605
611
  ...fixedCompilerOptions,
@@ -637,9 +643,18 @@ ${logPrefix} ${yellow(
637
643
  include = computeGlobs(options.include, content?.raw.include, "**/*");
638
644
  exclude = computeGlobs(options.exclude, content?.raw.exclude, "node_modules/**");
639
645
  filter = createFilter(include, exclude);
640
- const rootNames = Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath);
641
- host = ts.createCompilerHost(compilerOptions, true);
642
- program = createProgram({ host, rootNames, options: compilerOptions });
646
+ const rootNames = [
647
+ ...new Set(
648
+ Object.values(entries).map((entry) => ensureAbsolute(entry, root)).concat(content?.fileNames.filter(filter) || []).map(normalizePath)
649
+ )
650
+ ];
651
+ host = ts.createCompilerHost(compilerOptions);
652
+ program = createProgram({
653
+ host,
654
+ rootNames,
655
+ projectReferences: content?.projectReferences,
656
+ options: compilerOptions
657
+ });
643
658
  libName = toCapitalCase(libName || "_default");
644
659
  indexName = indexName || defaultIndex;
645
660
  const maybeEmitted = (sourceFile) => {
@@ -774,6 +789,7 @@ ${logPrefix} Start generate declaration files...`));
774
789
  }
775
790
  bundleDebug("emit output patch");
776
791
  const currentDir = host.getCurrentDirectory();
792
+ const vuePathRE = /['"](.+)\.vue['"]/g;
777
793
  await runParallel(
778
794
  cpus().length,
779
795
  Array.from(outputFiles.entries()),
@@ -789,7 +805,7 @@ ${logPrefix} Start generate declaration files...`));
789
805
  outDir,
790
806
  relative(entryRoot, cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path)
791
807
  );
792
- content = cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content;
808
+ content = cleanVueFileName ? content.replace(vuePathRE, '"$1"') : content;
793
809
  if (isMapFile) {
794
810
  try {
795
811
  const sourceMap = JSON.parse(content);
@@ -820,7 +836,10 @@ ${logPrefix} Start generate declaration files...`));
820
836
  const entryNames = Object.keys(entries);
821
837
  const types = fileTypesPath(pkg.publishConfig, pkg);
822
838
  const multiple = entryNames.length > 1;
823
- let typesPath = types ? resolve(root, types) : resolve(outDir, indexName);
839
+ const cleanPath = (path) => {
840
+ return cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path;
841
+ };
842
+ let typesPath = cleanPath(types ? resolve(root, types) : resolve(outDir, indexName));
824
843
  if (!multiple && !dtsRE.test(typesPath)) {
825
844
  logger.warn(
826
845
  `
@@ -832,12 +851,11 @@ ${logPrefix} ${yellow(
832
851
  typesPath = `${typesPath.replace(tjsRE, "")}.d.${extPrefix(typesPath)}ts`;
833
852
  }
834
853
  for (const name of entryNames) {
835
- const path = multiple ? resolve(outDir, `${name.replace(tsRE, "")}.d.ts`) : typesPath;
854
+ const path = multiple ? cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`)) : typesPath;
836
855
  if (existsSync(path))
837
856
  continue;
838
- const index = resolve(
839
- outDir,
840
- relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`)
857
+ const index = cleanPath(
858
+ resolve(outDir, relative(entryRoot, `${entries[name].replace(tsRE, "")}.d.ts`))
841
859
  );
842
860
  let fromPath = normalizePath(relative(dirname(path), index));
843
861
  fromPath = fromPath.replace(dtsRE, "");
@@ -852,7 +870,7 @@ export default ${libName}
852
870
  `;
853
871
  }
854
872
  }
855
- await writeOutput(path, content, outDir);
873
+ await writeOutput(cleanPath(path), content, outDir);
856
874
  }
857
875
  bundleDebug("insert index");
858
876
  if (rollupTypes) {
@@ -869,7 +887,7 @@ export default ${libName}
869
887
  const rollupFiles = /* @__PURE__ */ new Set();
870
888
  if (multiple) {
871
889
  for (const name of entryNames) {
872
- const path = resolve(outDir, `${name.replace(tsRE, "")}.d.ts`);
890
+ const path = cleanPath(resolve(outDir, `${name.replace(tsRE, "")}.d.ts`));
873
891
  rollupDeclarationFiles({
874
892
  root,
875
893
  configPath,
@@ -878,7 +896,8 @@ export default ${libName}
878
896
  entryPath: path,
879
897
  fileName: basename(path),
880
898
  libFolder,
881
- rollupConfig
899
+ rollupConfig,
900
+ rollupOptions
882
901
  });
883
902
  emittedFiles.delete(path);
884
903
  rollupFiles.add(path);
@@ -892,7 +911,8 @@ export default ${libName}
892
911
  entryPath: typesPath,
893
912
  fileName: basename(typesPath),
894
913
  libFolder,
895
- rollupConfig
914
+ rollupConfig,
915
+ rollupOptions
896
916
  });
897
917
  emittedFiles.delete(typesPath);
898
918
  rollupFiles.add(typesPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.5.4",
3
+ "version": "3.6.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",
@@ -50,46 +50,50 @@
50
50
  "vite-plugin",
51
51
  "ts",
52
52
  "dts",
53
- "typescript"
53
+ "typescript",
54
+ "vue",
55
+ "tsc",
56
+ "vue-tsc",
57
+ "volar"
54
58
  ],
55
59
  "dependencies": {
56
- "@microsoft/api-extractor": "^7.36.4",
57
- "@rollup/pluginutils": "^5.0.2",
58
- "@vue/language-core": "^1.8.8",
60
+ "@microsoft/api-extractor": "^7.38.0",
61
+ "@rollup/pluginutils": "^5.0.5",
62
+ "@vue/language-core": "^1.8.20",
59
63
  "debug": "^4.3.4",
60
64
  "kolorist": "^1.8.0",
61
- "vue-tsc": "^1.8.8"
65
+ "vue-tsc": "^1.8.20"
62
66
  },
63
67
  "devDependencies": {
64
- "@commitlint/cli": "^17.7.1",
65
- "@types/debug": "^4.1.8",
66
- "@types/minimist": "^1.2.2",
67
- "@types/node": "^20.4.10",
68
- "@types/prompts": "^2.4.4",
69
- "@types/semver": "^7.5.0",
68
+ "@commitlint/cli": "^18.0.0",
69
+ "@types/debug": "^4.1.10",
70
+ "@types/minimist": "^1.2.4",
71
+ "@types/node": "^20.8.8",
72
+ "@types/prompts": "^2.4.7",
73
+ "@types/semver": "^7.5.4",
70
74
  "@vexip-ui/commitlint-config": "^0.2.0",
71
75
  "@vexip-ui/eslint-config": "^0.8.1",
72
76
  "@vexip-ui/prettier-config": "^0.2.0",
73
77
  "@vue/eslint-config-standard": "^8.0.1",
74
- "@vue/eslint-config-typescript": "^11.0.3",
75
- "conventional-changelog-cli": "^3.0.0",
76
- "eslint": "^8.47.0",
77
- "execa": "^7.2.0",
78
+ "@vue/eslint-config-typescript": "^12.0.0",
79
+ "conventional-changelog-cli": "^4.1.0",
80
+ "eslint": "^8.52.0",
81
+ "execa": "^8.0.1",
78
82
  "husky": "^8.0.3",
79
83
  "is-ci": "^3.0.1",
80
- "lint-staged": "^13.2.3",
84
+ "lint-staged": "^15.0.2",
81
85
  "minimist": "^1.2.8",
82
86
  "pinst": "^3.0.0",
83
- "prettier": "^2.8.8",
87
+ "prettier": "^3.0.3",
84
88
  "pretty-quick": "^3.1.3",
85
89
  "prompts": "^2.4.2",
86
- "rimraf": "^5.0.1",
90
+ "rimraf": "^5.0.5",
87
91
  "semver": "^7.5.4",
88
- "tsx": "^3.12.7",
89
- "typescript": "5.1.6",
90
- "unbuild": "^1.2.1",
91
- "vite": "^4.4.9",
92
- "vitest": "^0.34.1"
92
+ "tsx": "^3.14.0",
93
+ "typescript": "5.2.2",
94
+ "unbuild": "^2.0.0",
95
+ "vite": "^4.5.0",
96
+ "vitest": "^0.34.6"
93
97
  },
94
98
  "peerDependencies": {
95
99
  "typescript": "*",
@@ -102,7 +106,7 @@
102
106
  },
103
107
  "pnpm": {
104
108
  "patchedDependencies": {
105
- "@microsoft/api-extractor@7.36.4": "patches/@microsoft__api-extractor@7.36.4.patch"
109
+ "@microsoft/api-extractor@7.38.0": "patches/@microsoft__api-extractor@7.38.0.patch"
106
110
  }
107
111
  }
108
112
  }