vite-plugin-dts 3.9.1 → 4.0.0-beta.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
@@ -7,6 +7,7 @@ const node_fs = require('node:fs');
7
7
  const promises = require('node:fs/promises');
8
8
  const node_os = require('node:os');
9
9
  const languageCore = require('@vue/language-core');
10
+ const typescript = require('@volar/typescript');
10
11
  const ts = require('typescript');
11
12
  const pluginutils = require('@rollup/pluginutils');
12
13
  const vueTsc = require('vue-tsc');
@@ -124,9 +125,10 @@ function removeDirIfEmpty(dir) {
124
125
  return onlyHasDir;
125
126
  }
126
127
  function getTsConfig(tsConfigPath, readFileSync) {
128
+ const baseConfig = ts__default.readConfigFile(tsConfigPath, readFileSync).config ?? {};
127
129
  const tsConfig = {
128
- compilerOptions: {},
129
- ...ts__default.readConfigFile(tsConfigPath, readFileSync).config ?? {}
130
+ ...baseConfig,
131
+ compilerOptions: {}
130
132
  };
131
133
  if (tsConfig.extends) {
132
134
  ensureArray(tsConfig.extends).forEach((configPath) => {
@@ -140,6 +142,7 @@ function getTsConfig(tsConfigPath, readFileSync) {
140
142
  }
141
143
  });
142
144
  }
145
+ Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
143
146
  return tsConfig;
144
147
  }
145
148
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
@@ -203,7 +206,7 @@ function findTypesPath(...pkgs) {
203
206
  for (const pkg of pkgs) {
204
207
  if (typeof pkg !== "object")
205
208
  continue;
206
- path = pkg.types || pkg.typings || pkg.exports?.["."]?.types || pkg.exports?.["./"]?.types;
209
+ path = pkg.types || pkg.typings || pkg.exports?.types || pkg.exports?.["."]?.types || pkg.exports?.["./"]?.types;
207
210
  if (path)
208
211
  return path;
209
212
  }
@@ -244,8 +247,27 @@ function editSourceMapDir(content, fromDir, toDir) {
244
247
  }
245
248
  return true;
246
249
  }
250
+ const regexpSymbolRE = /([$.\\+?()[\]!<=|{}^,])/g;
251
+ const asteriskRE = /[*]+/g;
252
+ function parseTsAliases(basePath, paths) {
253
+ const result = [];
254
+ for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
255
+ const find = new RegExp(
256
+ `^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "([^\\/]+)")}$`
257
+ );
258
+ let index = 1;
259
+ result.push({
260
+ find,
261
+ replacement: ensureAbsolute(
262
+ replacements[0].replace(asteriskRE, () => `$${index++}`),
263
+ basePath
264
+ )
265
+ });
266
+ }
267
+ return result;
268
+ }
247
269
 
248
- const dtsRE$1 = /\.d\.tsx?$/;
270
+ const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
249
271
  function rollupDeclarationFiles({
250
272
  root,
251
273
  configPath,
@@ -365,16 +387,19 @@ function VueResolver() {
365
387
  supports(id) {
366
388
  return vueRE.test(id);
367
389
  },
368
- transform({ id, code, program, service }) {
390
+ transform({ id, code, program }) {
369
391
  const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
370
392
  if (!sourceFile)
371
393
  return [];
372
- const outputs = service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
373
- return {
374
- path: file.name,
375
- content: file.text
376
- };
377
- });
394
+ const outputs = [];
395
+ program.emit(
396
+ sourceFile,
397
+ (path, content) => {
398
+ outputs.push({ path, content });
399
+ },
400
+ void 0,
401
+ true
402
+ );
378
403
  if (!program.getCompilerOptions().declarationMap)
379
404
  return outputs;
380
405
  const [beforeScript] = code.split(/\s*<script.*>/);
@@ -570,6 +595,26 @@ function hasExportDefault(content) {
570
595
  return has;
571
596
  }
572
597
 
598
+ const createProgram = typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
599
+ const { configFilePath } = options.options;
600
+ const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
601
+ if (options.host) {
602
+ const writeFile2 = options.host.writeFile.bind(options.host);
603
+ options.host.writeFile = (fileName, contents, ...args) => {
604
+ return writeFile2(fileName, vueTsc.removeEmitGlobalTypes(contents), ...args);
605
+ };
606
+ }
607
+ const vueLanguagePlugin = languageCore.createVueLanguagePlugin(
608
+ ts2,
609
+ (id) => id,
610
+ options.host?.useCaseSensitiveFileNames?.() ?? false,
611
+ () => "",
612
+ () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
613
+ options.options,
614
+ vueOptions
615
+ );
616
+ return [vueLanguagePlugin];
617
+ });
573
618
  const jsRE = /\.(m|c)?jsx?$/;
574
619
  const tsRE = /\.(m|c)?tsx?$/;
575
620
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -596,8 +641,6 @@ const noop = () => {
596
641
  };
597
642
  const extPrefix = (file) => mtjsRE.test(file) ? "m" : ctjsRE.test(file) ? "c" : "";
598
643
  const tsToDts = (path) => `${path.replace(tsRE, "")}.d.ts`;
599
- const regexpSymbolRE = /([$.\\+?()[\]!<=|{}^,])/g;
600
- const asteriskRE = /[*]+/g;
601
644
  function dtsPlugin(options = {}) {
602
645
  const {
603
646
  tsconfigPath,
@@ -635,6 +678,7 @@ function dtsPlugin(options = {}) {
635
678
  let host;
636
679
  let program;
637
680
  let filter;
681
+ let rebuildProgram;
638
682
  let bundled = false;
639
683
  let timeRecord = 0;
640
684
  const resolvers = parseResolvers([
@@ -645,6 +689,9 @@ function dtsPlugin(options = {}) {
645
689
  ]);
646
690
  const rootFiles = /* @__PURE__ */ new Set();
647
691
  const outputFiles = /* @__PURE__ */ new Map();
692
+ const setOutputFile = (path, content) => {
693
+ outputFiles.set(path, content);
694
+ };
648
695
  const rollupConfig = { ...options.rollupConfig || {} };
649
696
  rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
650
697
  const cleanPath = (path) => {
@@ -758,20 +805,9 @@ ${logPrefix} ${kolorist.yellow(
758
805
  }
759
806
  const { baseUrl, paths } = compilerOptions;
760
807
  if (pathsToAliases && baseUrl && paths) {
761
- const basePath = ensureAbsolute(baseUrl, configPath ? node_path.dirname(configPath) : root);
762
- for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
763
- const find = new RegExp(
764
- `^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
765
- );
766
- let index = 1;
767
- aliases.push({
768
- find,
769
- replacement: ensureAbsolute(
770
- replacements[0].replace(asteriskRE, () => `$${index++}`),
771
- basePath
772
- )
773
- });
774
- }
808
+ aliases.push(
809
+ ...parseTsAliases(ensureAbsolute(baseUrl, configPath ? node_path.dirname(configPath) : root), paths)
810
+ );
775
811
  }
776
812
  const computeGlobs = (rootGlobs, tsGlobs, defaultGlob) => {
777
813
  if (rootGlobs?.length) {
@@ -790,11 +826,12 @@ ${logPrefix} ${kolorist.yellow(
790
826
  )
791
827
  ];
792
828
  host = ts__default.createCompilerHost(compilerOptions);
793
- program = vueTsc.createProgram({
829
+ program = (rebuildProgram = () => createProgram({
794
830
  host,
795
831
  rootNames,
796
- options: compilerOptions
797
- });
832
+ options: compilerOptions,
833
+ projectReferences: content?.projectReferences
834
+ }))();
798
835
  libName = toCapitalCase(libName || "_default");
799
836
  indexName = indexName || defaultIndex;
800
837
  const maybeEmitted = (sourceFile) => {
@@ -832,7 +869,6 @@ ${logPrefix} ${kolorist.yellow(
832
869
  }
833
870
  const startTime = Date.now();
834
871
  const outDir = outDirs[0];
835
- const service = program.__vue.languageService;
836
872
  id = id.split("?")[0];
837
873
  rootFiles.delete(id);
838
874
  if (resolver) {
@@ -842,11 +878,10 @@ ${logPrefix} ${kolorist.yellow(
842
878
  root: publicRoot,
843
879
  outDir,
844
880
  host,
845
- program,
846
- service
881
+ program
847
882
  });
848
883
  for (const { path, content } of result) {
849
- outputFiles.set(
884
+ setOutputFile(
850
885
  resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(path, outDir))),
851
886
  content
852
887
  );
@@ -854,17 +889,22 @@ ${logPrefix} ${kolorist.yellow(
854
889
  } else {
855
890
  const sourceFile = program.getSourceFile(id);
856
891
  if (sourceFile) {
857
- for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
858
- outputFiles.set(
859
- resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(outputFile.name, outDir))),
860
- outputFile.text
861
- );
862
- }
892
+ program.emit(
893
+ sourceFile,
894
+ (name, text) => {
895
+ setOutputFile(
896
+ resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(name, outDir))),
897
+ text
898
+ );
899
+ },
900
+ void 0,
901
+ true
902
+ );
863
903
  }
864
904
  }
865
905
  const dtsId = id.replace(tjsRE, "") + ".d.ts";
866
906
  const dtsSourceFile = program.getSourceFile(dtsId);
867
- dtsSourceFile && filter(dtsSourceFile.fileName) && outputFiles.set(normalizePath(dtsSourceFile.fileName), dtsSourceFile.getFullText());
907
+ dtsSourceFile && filter(dtsSourceFile.fileName) && setOutputFile(normalizePath(dtsSourceFile.fileName), dtsSourceFile.getFullText());
868
908
  timeRecord += Date.now() - startTime;
869
909
  },
870
910
  watchChange(id) {
@@ -876,9 +916,9 @@ ${logPrefix} ${kolorist.yellow(
876
916
  const sourceFile = host.getSourceFile(id, ts__default.ScriptTarget.ESNext);
877
917
  if (sourceFile) {
878
918
  rootFiles.add(sourceFile.fileName);
879
- program.__vue.projectVersion++;
880
919
  bundled = false;
881
920
  timeRecord = 0;
921
+ program = rebuildProgram();
882
922
  }
883
923
  },
884
924
  async writeBundle() {
@@ -914,21 +954,25 @@ ${logPrefix} Start generate declaration files...`));
914
954
  await promises.writeFile(path, content, "utf-8");
915
955
  record && emittedFiles.set(path, content);
916
956
  };
917
- const service = program.__vue.languageService;
918
957
  const sourceFiles = program.getSourceFiles();
919
958
  for (const sourceFile of sourceFiles) {
920
959
  if (!filter(sourceFile.fileName))
921
960
  continue;
922
961
  if (copyDtsFiles && dtsRE.test(sourceFile.fileName)) {
923
- outputFiles.set(normalizePath(sourceFile.fileName), sourceFile.getFullText());
962
+ setOutputFile(normalizePath(sourceFile.fileName), sourceFile.getFullText());
924
963
  }
925
964
  if (rootFiles.has(sourceFile.fileName)) {
926
- for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
927
- outputFiles.set(
928
- resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(outputFile.name, outDir))),
929
- outputFile.text
930
- );
931
- }
965
+ program.emit(
966
+ sourceFile,
967
+ (name, text) => {
968
+ setOutputFile(
969
+ resolve(publicRoot, node_path.relative(outDir, ensureAbsolute(name, outDir))),
970
+ text
971
+ );
972
+ },
973
+ void 0,
974
+ true
975
+ );
932
976
  rootFiles.delete(sourceFile.fileName);
933
977
  }
934
978
  }
package/dist/index.d.cts CHANGED
@@ -28,7 +28,6 @@ interface Resolver {
28
28
  outDir: string;
29
29
  host: ts.CompilerHost;
30
30
  program: ts.Program;
31
- service: ts.LanguageService;
32
31
  }) => MaybePromise<{
33
32
  path: string;
34
33
  content: string;
package/dist/index.d.mts CHANGED
@@ -28,7 +28,6 @@ interface Resolver {
28
28
  outDir: string;
29
29
  host: ts.CompilerHost;
30
30
  program: ts.Program;
31
- service: ts.LanguageService;
32
31
  }) => MaybePromise<{
33
32
  path: string;
34
33
  content: string;
package/dist/index.d.ts CHANGED
@@ -28,7 +28,6 @@ interface Resolver {
28
28
  outDir: string;
29
29
  host: ts.CompilerHost;
30
30
  program: ts.Program;
31
- service: ts.LanguageService;
32
31
  }) => MaybePromise<{
33
32
  path: string;
34
33
  content: string;
package/dist/index.mjs CHANGED
@@ -9,10 +9,11 @@ import { relative, posix, resolve as resolve$1, isAbsolute, dirname, normalize,
9
9
  import { existsSync, readdirSync, lstatSync, rmdirSync } from 'node:fs';
10
10
  import { readFile, mkdir, writeFile, unlink } from 'node:fs/promises';
11
11
  import { cpus } from 'node:os';
12
- import { createParsedCommandLine } from '@vue/language-core';
12
+ import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePlugin } from '@vue/language-core';
13
+ import { proxyCreateProgram } from '@volar/typescript';
13
14
  import ts from 'typescript';
14
15
  import { createFilter } from '@rollup/pluginutils';
15
- import { createProgram } from 'vue-tsc';
16
+ import { removeEmitGlobalTypes } from 'vue-tsc';
16
17
  import debug from 'debug';
17
18
  import { cyan, yellow, green } from 'kolorist';
18
19
  import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
@@ -121,9 +122,10 @@ function removeDirIfEmpty(dir) {
121
122
  return onlyHasDir;
122
123
  }
123
124
  function getTsConfig(tsConfigPath, readFileSync) {
125
+ const baseConfig = ts.readConfigFile(tsConfigPath, readFileSync).config ?? {};
124
126
  const tsConfig = {
125
- compilerOptions: {},
126
- ...ts.readConfigFile(tsConfigPath, readFileSync).config ?? {}
127
+ ...baseConfig,
128
+ compilerOptions: {}
127
129
  };
128
130
  if (tsConfig.extends) {
129
131
  ensureArray(tsConfig.extends).forEach((configPath) => {
@@ -137,6 +139,7 @@ function getTsConfig(tsConfigPath, readFileSync) {
137
139
  }
138
140
  });
139
141
  }
142
+ Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
140
143
  return tsConfig;
141
144
  }
142
145
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
@@ -200,7 +203,7 @@ function findTypesPath(...pkgs) {
200
203
  for (const pkg of pkgs) {
201
204
  if (typeof pkg !== "object")
202
205
  continue;
203
- path = pkg.types || pkg.typings || pkg.exports?.["."]?.types || pkg.exports?.["./"]?.types;
206
+ path = pkg.types || pkg.typings || pkg.exports?.types || pkg.exports?.["."]?.types || pkg.exports?.["./"]?.types;
204
207
  if (path)
205
208
  return path;
206
209
  }
@@ -241,8 +244,27 @@ function editSourceMapDir(content, fromDir, toDir) {
241
244
  }
242
245
  return true;
243
246
  }
247
+ const regexpSymbolRE = /([$.\\+?()[\]!<=|{}^,])/g;
248
+ const asteriskRE = /[*]+/g;
249
+ function parseTsAliases(basePath, paths) {
250
+ const result = [];
251
+ for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
252
+ const find = new RegExp(
253
+ `^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "([^\\/]+)")}$`
254
+ );
255
+ let index = 1;
256
+ result.push({
257
+ find,
258
+ replacement: ensureAbsolute(
259
+ replacements[0].replace(asteriskRE, () => `$${index++}`),
260
+ basePath
261
+ )
262
+ });
263
+ }
264
+ return result;
265
+ }
244
266
 
245
- const dtsRE$1 = /\.d\.tsx?$/;
267
+ const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
246
268
  function rollupDeclarationFiles({
247
269
  root,
248
270
  configPath,
@@ -362,16 +384,19 @@ function VueResolver() {
362
384
  supports(id) {
363
385
  return vueRE.test(id);
364
386
  },
365
- transform({ id, code, program, service }) {
387
+ transform({ id, code, program }) {
366
388
  const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
367
389
  if (!sourceFile)
368
390
  return [];
369
- const outputs = service.getEmitOutput(sourceFile.fileName, true).outputFiles.map((file) => {
370
- return {
371
- path: file.name,
372
- content: file.text
373
- };
374
- });
391
+ const outputs = [];
392
+ program.emit(
393
+ sourceFile,
394
+ (path, content) => {
395
+ outputs.push({ path, content });
396
+ },
397
+ void 0,
398
+ true
399
+ );
375
400
  if (!program.getCompilerOptions().declarationMap)
376
401
  return outputs;
377
402
  const [beforeScript] = code.split(/\s*<script.*>/);
@@ -567,6 +592,26 @@ function hasExportDefault(content) {
567
592
  return has;
568
593
  }
569
594
 
595
+ const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
596
+ const { configFilePath } = options.options;
597
+ const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
598
+ if (options.host) {
599
+ const writeFile2 = options.host.writeFile.bind(options.host);
600
+ options.host.writeFile = (fileName, contents, ...args) => {
601
+ return writeFile2(fileName, removeEmitGlobalTypes(contents), ...args);
602
+ };
603
+ }
604
+ const vueLanguagePlugin = createVueLanguagePlugin(
605
+ ts2,
606
+ (id) => id,
607
+ options.host?.useCaseSensitiveFileNames?.() ?? false,
608
+ () => "",
609
+ () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
610
+ options.options,
611
+ vueOptions
612
+ );
613
+ return [vueLanguagePlugin];
614
+ });
570
615
  const jsRE = /\.(m|c)?jsx?$/;
571
616
  const tsRE = /\.(m|c)?tsx?$/;
572
617
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -593,8 +638,6 @@ const noop = () => {
593
638
  };
594
639
  const extPrefix = (file) => mtjsRE.test(file) ? "m" : ctjsRE.test(file) ? "c" : "";
595
640
  const tsToDts = (path) => `${path.replace(tsRE, "")}.d.ts`;
596
- const regexpSymbolRE = /([$.\\+?()[\]!<=|{}^,])/g;
597
- const asteriskRE = /[*]+/g;
598
641
  function dtsPlugin(options = {}) {
599
642
  const {
600
643
  tsconfigPath,
@@ -632,6 +675,7 @@ function dtsPlugin(options = {}) {
632
675
  let host;
633
676
  let program;
634
677
  let filter;
678
+ let rebuildProgram;
635
679
  let bundled = false;
636
680
  let timeRecord = 0;
637
681
  const resolvers = parseResolvers([
@@ -642,6 +686,9 @@ function dtsPlugin(options = {}) {
642
686
  ]);
643
687
  const rootFiles = /* @__PURE__ */ new Set();
644
688
  const outputFiles = /* @__PURE__ */ new Map();
689
+ const setOutputFile = (path, content) => {
690
+ outputFiles.set(path, content);
691
+ };
645
692
  const rollupConfig = { ...options.rollupConfig || {} };
646
693
  rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || [];
647
694
  const cleanPath = (path) => {
@@ -755,20 +802,9 @@ ${logPrefix} ${yellow(
755
802
  }
756
803
  const { baseUrl, paths } = compilerOptions;
757
804
  if (pathsToAliases && baseUrl && paths) {
758
- const basePath = ensureAbsolute(baseUrl, configPath ? dirname(configPath) : root);
759
- for (const [pathWithAsterisk, replacements] of Object.entries(paths)) {
760
- const find = new RegExp(
761
- `^${pathWithAsterisk.replace(regexpSymbolRE, "\\$1").replace(asteriskRE, "(.+)")}$`
762
- );
763
- let index = 1;
764
- aliases.push({
765
- find,
766
- replacement: ensureAbsolute(
767
- replacements[0].replace(asteriskRE, () => `$${index++}`),
768
- basePath
769
- )
770
- });
771
- }
805
+ aliases.push(
806
+ ...parseTsAliases(ensureAbsolute(baseUrl, configPath ? dirname(configPath) : root), paths)
807
+ );
772
808
  }
773
809
  const computeGlobs = (rootGlobs, tsGlobs, defaultGlob) => {
774
810
  if (rootGlobs?.length) {
@@ -787,11 +823,12 @@ ${logPrefix} ${yellow(
787
823
  )
788
824
  ];
789
825
  host = ts.createCompilerHost(compilerOptions);
790
- program = createProgram({
826
+ program = (rebuildProgram = () => createProgram({
791
827
  host,
792
828
  rootNames,
793
- options: compilerOptions
794
- });
829
+ options: compilerOptions,
830
+ projectReferences: content?.projectReferences
831
+ }))();
795
832
  libName = toCapitalCase(libName || "_default");
796
833
  indexName = indexName || defaultIndex;
797
834
  const maybeEmitted = (sourceFile) => {
@@ -829,7 +866,6 @@ ${logPrefix} ${yellow(
829
866
  }
830
867
  const startTime = Date.now();
831
868
  const outDir = outDirs[0];
832
- const service = program.__vue.languageService;
833
869
  id = id.split("?")[0];
834
870
  rootFiles.delete(id);
835
871
  if (resolver) {
@@ -839,11 +875,10 @@ ${logPrefix} ${yellow(
839
875
  root: publicRoot,
840
876
  outDir,
841
877
  host,
842
- program,
843
- service
878
+ program
844
879
  });
845
880
  for (const { path, content } of result) {
846
- outputFiles.set(
881
+ setOutputFile(
847
882
  resolve(publicRoot, relative(outDir, ensureAbsolute(path, outDir))),
848
883
  content
849
884
  );
@@ -851,17 +886,22 @@ ${logPrefix} ${yellow(
851
886
  } else {
852
887
  const sourceFile = program.getSourceFile(id);
853
888
  if (sourceFile) {
854
- for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
855
- outputFiles.set(
856
- resolve(publicRoot, relative(outDir, ensureAbsolute(outputFile.name, outDir))),
857
- outputFile.text
858
- );
859
- }
889
+ program.emit(
890
+ sourceFile,
891
+ (name, text) => {
892
+ setOutputFile(
893
+ resolve(publicRoot, relative(outDir, ensureAbsolute(name, outDir))),
894
+ text
895
+ );
896
+ },
897
+ void 0,
898
+ true
899
+ );
860
900
  }
861
901
  }
862
902
  const dtsId = id.replace(tjsRE, "") + ".d.ts";
863
903
  const dtsSourceFile = program.getSourceFile(dtsId);
864
- dtsSourceFile && filter(dtsSourceFile.fileName) && outputFiles.set(normalizePath(dtsSourceFile.fileName), dtsSourceFile.getFullText());
904
+ dtsSourceFile && filter(dtsSourceFile.fileName) && setOutputFile(normalizePath(dtsSourceFile.fileName), dtsSourceFile.getFullText());
865
905
  timeRecord += Date.now() - startTime;
866
906
  },
867
907
  watchChange(id) {
@@ -873,9 +913,9 @@ ${logPrefix} ${yellow(
873
913
  const sourceFile = host.getSourceFile(id, ts.ScriptTarget.ESNext);
874
914
  if (sourceFile) {
875
915
  rootFiles.add(sourceFile.fileName);
876
- program.__vue.projectVersion++;
877
916
  bundled = false;
878
917
  timeRecord = 0;
918
+ program = rebuildProgram();
879
919
  }
880
920
  },
881
921
  async writeBundle() {
@@ -911,21 +951,25 @@ ${logPrefix} Start generate declaration files...`));
911
951
  await writeFile(path, content, "utf-8");
912
952
  record && emittedFiles.set(path, content);
913
953
  };
914
- const service = program.__vue.languageService;
915
954
  const sourceFiles = program.getSourceFiles();
916
955
  for (const sourceFile of sourceFiles) {
917
956
  if (!filter(sourceFile.fileName))
918
957
  continue;
919
958
  if (copyDtsFiles && dtsRE.test(sourceFile.fileName)) {
920
- outputFiles.set(normalizePath(sourceFile.fileName), sourceFile.getFullText());
959
+ setOutputFile(normalizePath(sourceFile.fileName), sourceFile.getFullText());
921
960
  }
922
961
  if (rootFiles.has(sourceFile.fileName)) {
923
- for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
924
- outputFiles.set(
925
- resolve(publicRoot, relative(outDir, ensureAbsolute(outputFile.name, outDir))),
926
- outputFile.text
927
- );
928
- }
962
+ program.emit(
963
+ sourceFile,
964
+ (name, text) => {
965
+ setOutputFile(
966
+ resolve(publicRoot, relative(outDir, ensureAbsolute(name, outDir))),
967
+ text
968
+ );
969
+ },
970
+ void 0,
971
+ true
972
+ );
929
973
  rootFiles.delete(sourceFile.fileName);
930
974
  }
931
975
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "3.9.1",
3
+ "version": "4.0.0-beta.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",
@@ -58,44 +58,45 @@
58
58
  "volar"
59
59
  ],
60
60
  "dependencies": {
61
- "@microsoft/api-extractor": "7.43.0",
61
+ "@microsoft/api-extractor": "7.47.2",
62
62
  "@rollup/pluginutils": "^5.1.0",
63
- "@vue/language-core": "^1.8.27",
64
- "debug": "^4.3.4",
63
+ "@volar/typescript": "^2.3.4",
64
+ "@vue/language-core": "2.0.19",
65
+ "debug": "^4.3.5",
65
66
  "kolorist": "^1.8.0",
66
- "magic-string": "^0.30.8",
67
- "vue-tsc": "^1.8.27"
67
+ "magic-string": "^0.30.10",
68
+ "vue-tsc": "2.0.19"
68
69
  },
69
70
  "devDependencies": {
70
- "@commitlint/cli": "^19.2.1",
71
+ "@commitlint/cli": "^19.3.0",
71
72
  "@types/debug": "^4.1.12",
72
73
  "@types/minimist": "^1.2.5",
73
- "@types/node": "^20.11.30",
74
+ "@types/node": "^20.14.11",
74
75
  "@types/prompts": "^2.4.9",
75
76
  "@types/semver": "^7.5.8",
76
- "@vexip-ui/commitlint-config": "^0.4.0",
77
- "@vexip-ui/eslint-config": "^0.12.0",
77
+ "@vexip-ui/commitlint-config": "^0.5.0",
78
+ "@vexip-ui/eslint-config": "^0.12.1",
78
79
  "@vexip-ui/prettier-config": "^0.2.0",
79
80
  "@vue/eslint-config-standard": "^8.0.1",
80
81
  "@vue/eslint-config-typescript": "^13.0.0",
81
- "conventional-changelog-cli": "^4.1.0",
82
+ "conventional-changelog-cli": "^5.0.0",
82
83
  "eslint": "^8.57.0",
83
84
  "execa": "^8.0.1",
84
- "husky": "^9.0.11",
85
+ "husky": "^8.0.3",
85
86
  "is-ci": "^3.0.1",
86
- "lint-staged": "^15.2.2",
87
+ "lint-staged": "^15.2.7",
87
88
  "minimist": "^1.2.8",
88
89
  "pinst": "^3.0.0",
89
- "prettier": "^3.2.5",
90
+ "prettier": "^3.3.3",
90
91
  "pretty-quick": "^4.0.0",
91
92
  "prompts": "^2.4.2",
92
- "rimraf": "^5.0.5",
93
- "semver": "^7.6.0",
94
- "tsx": "^4.7.1",
95
- "typescript": "5.4.3",
93
+ "rimraf": "^6.0.1",
94
+ "semver": "^7.6.3",
95
+ "tsx": "^4.16.2",
96
+ "typescript": "5.5.3",
96
97
  "unbuild": "^2.0.0",
97
- "vite": "^5.2.6",
98
- "vitest": "^1.4.0"
98
+ "vite": "^5.3.4",
99
+ "vitest": "^2.0.3"
99
100
  },
100
101
  "peerDependencies": {
101
102
  "typescript": "*",
@@ -108,7 +109,7 @@
108
109
  },
109
110
  "pnpm": {
110
111
  "patchedDependencies": {
111
- "@microsoft/api-extractor@7.43.0": "patches/@microsoft__api-extractor@7.43.0.patch"
112
+ "@microsoft/api-extractor@7.47.2": "patches/@microsoft__api-extractor@7.47.2.patch"
112
113
  }
113
114
  }
114
115
  }