vite-plugin-dts 4.1.0 → 4.2.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
@@ -10,78 +10,19 @@ const languageCore = require('@vue/language-core');
10
10
  const typescript = require('@volar/typescript');
11
11
  const ts = require('typescript');
12
12
  const localPkg = require('local-pkg');
13
- const vueTsc = require('vue-tsc');
14
13
  const pluginutils = require('@rollup/pluginutils');
15
14
  const debug = require('debug');
16
15
  const kolorist = require('kolorist');
17
16
  const apiExtractor = require('@microsoft/api-extractor');
18
- const node_module = require('node:module');
19
17
  const compareVersions = require('compare-versions');
20
18
  const MagicString = require('magic-string');
21
19
 
22
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
23
20
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
24
21
 
25
22
  const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
26
23
  const debug__default = /*#__PURE__*/_interopDefaultCompat(debug);
27
24
  const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
28
25
 
29
- let hasVue = false;
30
- try {
31
- hasVue = !!(localPkg.getPackageInfoSync("vue") ?? localPkg.getPackageInfoSync("svelte", { paths: [localPkg.resolveModule("svelte") || process.cwd()] }));
32
- } catch (e) {
33
- }
34
- const _createProgram = !hasVue ? ts__default.createProgram : typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
35
- const { configFilePath } = options.options;
36
- const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
37
- if (options.host) {
38
- const writeFile = options.host.writeFile.bind(options.host);
39
- options.host.writeFile = (fileName, contents, ...args) => {
40
- return writeFile(fileName, vueTsc.removeEmitGlobalTypes(contents), ...args);
41
- };
42
- }
43
- const vueLanguagePlugin = languageCore.createVueLanguagePlugin2(
44
- ts2,
45
- (id) => id,
46
- languageCore.createRootFileChecker(
47
- void 0,
48
- () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
49
- options.host?.useCaseSensitiveFileNames?.() ?? false
50
- ),
51
- options.options,
52
- vueOptions
53
- );
54
- return [vueLanguagePlugin];
55
- });
56
- const createProgram = !hasVue ? ts__default.createProgram : (options) => {
57
- const program = _createProgram(options);
58
- const emit = program.emit;
59
- program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
60
- if (writeFile) {
61
- return emit(
62
- targetSourceFile,
63
- (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
64
- if (fileName.endsWith(".d.ts")) {
65
- data = vueTsc.removeEmitGlobalTypes(data);
66
- }
67
- return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
68
- },
69
- cancellationToken,
70
- emitOnlyDtsFiles,
71
- customTransformers
72
- );
73
- }
74
- return emit(
75
- targetSourceFile,
76
- writeFile,
77
- cancellationToken,
78
- emitOnlyDtsFiles,
79
- customTransformers
80
- );
81
- };
82
- return program;
83
- };
84
-
85
26
  const windowsSlashRE = /\\+/g;
86
27
  function slash(p) {
87
28
  return p.replace(windowsSlashRE, "/");
@@ -205,25 +146,9 @@ function getTsConfig(tsConfigPath, readFileSync) {
205
146
  Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
206
147
  return tsConfig;
207
148
  }
208
- function getTsLibFolder({ root, entryRoot }) {
209
- let libFolder;
210
- try {
211
- libFolder = normalizePath(node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).resolve("typescript")).replace(
212
- /node_modules\/typescript.*/,
213
- "node_modules/typescript"
214
- );
215
- } catch {
216
- libFolder = resolve(root, "node_modules/typescript");
217
- if (!node_fs.existsSync(libFolder)) {
218
- if (root !== entryRoot) {
219
- libFolder = resolve(entryRoot, "node_modules/typescript");
220
- if (!node_fs.existsSync(libFolder))
221
- libFolder = void 0;
222
- }
223
- libFolder = void 0;
224
- }
225
- }
226
- return libFolder;
149
+ function getTsLibFolder() {
150
+ const libFolder = tryGetPackageInfo("typescript")?.rootPath;
151
+ return libFolder && normalizePath(libFolder);
227
152
  }
228
153
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
229
154
  function base64Encode(number) {
@@ -346,6 +271,51 @@ function parseTsAliases(basePath, paths) {
346
271
  }
347
272
  return result;
348
273
  }
274
+ function tryGetPackageInfo(name) {
275
+ try {
276
+ return localPkg.getPackageInfoSync(name) ?? localPkg.getPackageInfoSync(name, { paths: [localPkg.resolveModule(name) || process.cwd()] });
277
+ } catch (e) {
278
+ }
279
+ }
280
+
281
+ const hasVue = !!tryGetPackageInfo("vue");
282
+ const _createProgram = !hasVue ? ts__default.createProgram : typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
283
+ const { configFilePath } = options.options;
284
+ const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
285
+ const vueLanguagePlugin = languageCore.createVueLanguagePlugin(
286
+ ts2,
287
+ options.options,
288
+ vueOptions,
289
+ (id) => id
290
+ );
291
+ return [vueLanguagePlugin];
292
+ });
293
+ const createProgram = !hasVue ? ts__default.createProgram : (options) => {
294
+ const program = _createProgram(options);
295
+ const emit = program.emit;
296
+ program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
297
+ if (writeFile) {
298
+ return emit(
299
+ targetSourceFile,
300
+ (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
301
+ if (fileName.endsWith(".d.ts")) ;
302
+ return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
303
+ },
304
+ cancellationToken,
305
+ emitOnlyDtsFiles,
306
+ customTransformers
307
+ );
308
+ }
309
+ return emit(
310
+ targetSourceFile,
311
+ writeFile,
312
+ cancellationToken,
313
+ emitOnlyDtsFiles,
314
+ customTransformers
315
+ );
316
+ };
317
+ return program;
318
+ };
349
319
 
350
320
  const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
351
321
  function rollupDeclarationFiles({
@@ -359,7 +329,7 @@ function rollupDeclarationFiles({
359
329
  rollupConfig = {},
360
330
  rollupOptions = {}
361
331
  }) {
362
- const configObjectFullPath = node_path.resolve(root, "api-extractor.json");
332
+ const configObjectFullPath = resolve(root, "api-extractor.json");
363
333
  if (!dtsRE$1.test(fileName)) {
364
334
  fileName += ".d.ts";
365
335
  }
@@ -389,7 +359,7 @@ function rollupDeclarationFiles({
389
359
  },
390
360
  dtsRollup: {
391
361
  enabled: true,
392
- publicTrimmedFilePath: node_path.resolve(outDir, fileName)
362
+ publicTrimmedFilePath: resolve(outDir, fileName)
393
363
  },
394
364
  tsdocMetadata: {
395
365
  enabled: false,
@@ -416,7 +386,7 @@ function rollupDeclarationFiles({
416
386
  localBuild: false,
417
387
  showVerboseMessages: false,
418
388
  showDiagnostics: false,
419
- typescriptCompilerFolder: libFolder ? node_path.resolve(libFolder) : void 0,
389
+ typescriptCompilerFolder: libFolder,
420
390
  ...rollupOptions
421
391
  });
422
392
  }
@@ -451,7 +421,7 @@ function querySvelteVersion() {
451
421
  if (typeof lowerVersion === "boolean")
452
422
  return;
453
423
  try {
454
- const version = localPkg.getPackageInfoSync("svelte")?.version ?? localPkg.getPackageInfoSync("svelte", { paths: [localPkg.resolveModule("svelte") || process.cwd()] })?.version;
424
+ const version = tryGetPackageInfo("svelte")?.version;
455
425
  lowerVersion = version ? compareVersions.compare(version, "4.0.0", "<") : false;
456
426
  } catch (e) {
457
427
  lowerVersion = false;
@@ -491,7 +461,7 @@ function VueResolver() {
491
461
  program.emit(
492
462
  sourceFile,
493
463
  (path, content) => {
494
- outputs.push({ path, content: vueTsc.removeEmitGlobalTypes(content) });
464
+ outputs.push({ path, content });
495
465
  },
496
466
  void 0,
497
467
  true
@@ -1224,7 +1194,7 @@ ${content}`;
1224
1194
  outDir,
1225
1195
  entryPath: path,
1226
1196
  fileName: node_path.basename(path),
1227
- libFolder: getTsLibFolder({ root, entryRoot }),
1197
+ libFolder: getTsLibFolder(),
1228
1198
  rollupConfig,
1229
1199
  rollupOptions
1230
1200
  });
package/dist/index.mjs CHANGED
@@ -9,75 +9,17 @@ 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, resolveVueCompilerOptions, createVueLanguagePlugin2, createRootFileChecker } from '@vue/language-core';
12
+ import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePlugin } from '@vue/language-core';
13
13
  import { proxyCreateProgram } from '@volar/typescript';
14
14
  import ts from 'typescript';
15
15
  import { getPackageInfoSync, resolveModule } from 'local-pkg';
16
- import { removeEmitGlobalTypes } from 'vue-tsc';
17
16
  import { createFilter } from '@rollup/pluginutils';
18
17
  import debug from 'debug';
19
18
  import { cyan, yellow, green } from 'kolorist';
20
19
  import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
21
- import { createRequire } from 'node:module';
22
20
  import { compare } from 'compare-versions';
23
21
  import MagicString from 'magic-string';
24
22
 
25
- let hasVue = false;
26
- try {
27
- hasVue = !!(getPackageInfoSync("vue") ?? getPackageInfoSync("svelte", { paths: [resolveModule("svelte") || process.cwd()] }));
28
- } catch (e) {
29
- }
30
- const _createProgram = !hasVue ? ts.createProgram : proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
31
- const { configFilePath } = options.options;
32
- const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
33
- if (options.host) {
34
- const writeFile = options.host.writeFile.bind(options.host);
35
- options.host.writeFile = (fileName, contents, ...args) => {
36
- return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
37
- };
38
- }
39
- const vueLanguagePlugin = createVueLanguagePlugin2(
40
- ts2,
41
- (id) => id,
42
- createRootFileChecker(
43
- void 0,
44
- () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
45
- options.host?.useCaseSensitiveFileNames?.() ?? false
46
- ),
47
- options.options,
48
- vueOptions
49
- );
50
- return [vueLanguagePlugin];
51
- });
52
- const createProgram = !hasVue ? ts.createProgram : (options) => {
53
- const program = _createProgram(options);
54
- const emit = program.emit;
55
- program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
56
- if (writeFile) {
57
- return emit(
58
- targetSourceFile,
59
- (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
60
- if (fileName.endsWith(".d.ts")) {
61
- data = removeEmitGlobalTypes(data);
62
- }
63
- return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
64
- },
65
- cancellationToken,
66
- emitOnlyDtsFiles,
67
- customTransformers
68
- );
69
- }
70
- return emit(
71
- targetSourceFile,
72
- writeFile,
73
- cancellationToken,
74
- emitOnlyDtsFiles,
75
- customTransformers
76
- );
77
- };
78
- return program;
79
- };
80
-
81
23
  const windowsSlashRE = /\\+/g;
82
24
  function slash(p) {
83
25
  return p.replace(windowsSlashRE, "/");
@@ -201,25 +143,9 @@ function getTsConfig(tsConfigPath, readFileSync) {
201
143
  Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
202
144
  return tsConfig;
203
145
  }
204
- function getTsLibFolder({ root, entryRoot }) {
205
- let libFolder;
206
- try {
207
- libFolder = normalizePath(createRequire(import.meta.url).resolve("typescript")).replace(
208
- /node_modules\/typescript.*/,
209
- "node_modules/typescript"
210
- );
211
- } catch {
212
- libFolder = resolve(root, "node_modules/typescript");
213
- if (!existsSync(libFolder)) {
214
- if (root !== entryRoot) {
215
- libFolder = resolve(entryRoot, "node_modules/typescript");
216
- if (!existsSync(libFolder))
217
- libFolder = void 0;
218
- }
219
- libFolder = void 0;
220
- }
221
- }
222
- return libFolder;
146
+ function getTsLibFolder() {
147
+ const libFolder = tryGetPackageInfo("typescript")?.rootPath;
148
+ return libFolder && normalizePath(libFolder);
223
149
  }
224
150
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
225
151
  function base64Encode(number) {
@@ -342,6 +268,51 @@ function parseTsAliases(basePath, paths) {
342
268
  }
343
269
  return result;
344
270
  }
271
+ function tryGetPackageInfo(name) {
272
+ try {
273
+ return getPackageInfoSync(name) ?? getPackageInfoSync(name, { paths: [resolveModule(name) || process.cwd()] });
274
+ } catch (e) {
275
+ }
276
+ }
277
+
278
+ const hasVue = !!tryGetPackageInfo("vue");
279
+ const _createProgram = !hasVue ? ts.createProgram : proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
280
+ const { configFilePath } = options.options;
281
+ const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
282
+ const vueLanguagePlugin = createVueLanguagePlugin(
283
+ ts2,
284
+ options.options,
285
+ vueOptions,
286
+ (id) => id
287
+ );
288
+ return [vueLanguagePlugin];
289
+ });
290
+ const createProgram = !hasVue ? ts.createProgram : (options) => {
291
+ const program = _createProgram(options);
292
+ const emit = program.emit;
293
+ program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
294
+ if (writeFile) {
295
+ return emit(
296
+ targetSourceFile,
297
+ (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
298
+ if (fileName.endsWith(".d.ts")) ;
299
+ return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
300
+ },
301
+ cancellationToken,
302
+ emitOnlyDtsFiles,
303
+ customTransformers
304
+ );
305
+ }
306
+ return emit(
307
+ targetSourceFile,
308
+ writeFile,
309
+ cancellationToken,
310
+ emitOnlyDtsFiles,
311
+ customTransformers
312
+ );
313
+ };
314
+ return program;
315
+ };
345
316
 
346
317
  const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
347
318
  function rollupDeclarationFiles({
@@ -355,7 +326,7 @@ function rollupDeclarationFiles({
355
326
  rollupConfig = {},
356
327
  rollupOptions = {}
357
328
  }) {
358
- const configObjectFullPath = resolve$1(root, "api-extractor.json");
329
+ const configObjectFullPath = resolve(root, "api-extractor.json");
359
330
  if (!dtsRE$1.test(fileName)) {
360
331
  fileName += ".d.ts";
361
332
  }
@@ -385,7 +356,7 @@ function rollupDeclarationFiles({
385
356
  },
386
357
  dtsRollup: {
387
358
  enabled: true,
388
- publicTrimmedFilePath: resolve$1(outDir, fileName)
359
+ publicTrimmedFilePath: resolve(outDir, fileName)
389
360
  },
390
361
  tsdocMetadata: {
391
362
  enabled: false,
@@ -412,7 +383,7 @@ function rollupDeclarationFiles({
412
383
  localBuild: false,
413
384
  showVerboseMessages: false,
414
385
  showDiagnostics: false,
415
- typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0,
386
+ typescriptCompilerFolder: libFolder,
416
387
  ...rollupOptions
417
388
  });
418
389
  }
@@ -447,7 +418,7 @@ function querySvelteVersion() {
447
418
  if (typeof lowerVersion === "boolean")
448
419
  return;
449
420
  try {
450
- const version = getPackageInfoSync("svelte")?.version ?? getPackageInfoSync("svelte", { paths: [resolveModule("svelte") || process.cwd()] })?.version;
421
+ const version = tryGetPackageInfo("svelte")?.version;
451
422
  lowerVersion = version ? compare(version, "4.0.0", "<") : false;
452
423
  } catch (e) {
453
424
  lowerVersion = false;
@@ -487,7 +458,7 @@ function VueResolver() {
487
458
  program.emit(
488
459
  sourceFile,
489
460
  (path, content) => {
490
- outputs.push({ path, content: removeEmitGlobalTypes(content) });
461
+ outputs.push({ path, content });
491
462
  },
492
463
  void 0,
493
464
  true
@@ -1220,7 +1191,7 @@ ${content}`;
1220
1191
  outDir,
1221
1192
  entryPath: path,
1222
1193
  fileName: basename(path),
1223
- libFolder: getTsLibFolder({ root, entryRoot }),
1194
+ libFolder: getTsLibFolder(),
1224
1195
  rollupConfig,
1225
1196
  rollupOptions
1226
1197
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "type": "module",
5
5
  "packageManager": "pnpm@9.9.0",
6
6
  "license": "MIT",
@@ -11,7 +11,7 @@
11
11
  "dev": "unbuild --stub",
12
12
  "_postinstall": "is-ci || husky install",
13
13
  "lint": "eslint --ext .js,.jsx,.ts,.tsx \"{src,tests}/**\"",
14
- "precommit": "lint-staged -c ./.husky/.lintstagedrc -q",
14
+ "precommit": "lint-staged -c ./.husky/.lintstagedrc -q --allow-empty",
15
15
  "prepublishOnly": "pinst --disable",
16
16
  "prettier": "pretty-quick --staged && pnpm run lint",
17
17
  "postpublish": "pinst --enable",
@@ -58,16 +58,15 @@
58
58
  "url": "https://github.com/qmhc/vite-plugin-dts/issues"
59
59
  },
60
60
  "dependencies": {
61
- "@microsoft/api-extractor": "7.47.4",
61
+ "@microsoft/api-extractor": "7.47.7",
62
62
  "@rollup/pluginutils": "^5.1.0",
63
- "@volar/typescript": "^2.3.4",
64
- "@vue/language-core": "2.0.29",
63
+ "@volar/typescript": "^2.4.4",
64
+ "@vue/language-core": "2.1.6",
65
65
  "compare-versions": "^6.1.1",
66
66
  "debug": "^4.3.6",
67
67
  "kolorist": "^1.8.0",
68
68
  "local-pkg": "^0.5.0",
69
- "magic-string": "^0.30.11",
70
- "vue-tsc": "2.0.29"
69
+ "magic-string": "^0.30.11"
71
70
  },
72
71
  "devDependencies": {
73
72
  "@commitlint/cli": "^19.3.0",