vite-plugin-dts 4.1.0 → 4.1.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.cjs CHANGED
@@ -9,79 +9,21 @@ const node_os = require('node:os');
9
9
  const languageCore = require('@vue/language-core');
10
10
  const typescript = require('@volar/typescript');
11
11
  const ts = require('typescript');
12
- const localPkg = require('local-pkg');
13
12
  const vueTsc = require('vue-tsc');
13
+ const localPkg = require('local-pkg');
14
14
  const pluginutils = require('@rollup/pluginutils');
15
15
  const debug = require('debug');
16
16
  const kolorist = require('kolorist');
17
17
  const apiExtractor = require('@microsoft/api-extractor');
18
- const node_module = require('node:module');
19
18
  const compareVersions = require('compare-versions');
20
19
  const MagicString = require('magic-string');
21
20
 
22
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
23
21
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
24
22
 
25
23
  const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
26
24
  const debug__default = /*#__PURE__*/_interopDefaultCompat(debug);
27
25
  const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
28
26
 
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
27
  const windowsSlashRE = /\\+/g;
86
28
  function slash(p) {
87
29
  return p.replace(windowsSlashRE, "/");
@@ -205,25 +147,9 @@ function getTsConfig(tsConfigPath, readFileSync) {
205
147
  Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
206
148
  return tsConfig;
207
149
  }
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;
150
+ function getTsLibFolder() {
151
+ const libFolder = tryGetPackageInfo("typescript")?.rootPath;
152
+ return libFolder && normalizePath(libFolder);
227
153
  }
228
154
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
229
155
  function base64Encode(number) {
@@ -346,6 +272,64 @@ function parseTsAliases(basePath, paths) {
346
272
  }
347
273
  return result;
348
274
  }
275
+ function tryGetPackageInfo(name) {
276
+ try {
277
+ return localPkg.getPackageInfoSync(name) ?? localPkg.getPackageInfoSync(name, { paths: [localPkg.resolveModule(name) || process.cwd()] });
278
+ } catch (e) {
279
+ }
280
+ }
281
+
282
+ const hasVue = !!tryGetPackageInfo("vue");
283
+ const _createProgram = !hasVue ? ts__default.createProgram : typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
284
+ const { configFilePath } = options.options;
285
+ const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
286
+ if (options.host) {
287
+ const writeFile = options.host.writeFile.bind(options.host);
288
+ options.host.writeFile = (fileName, contents, ...args) => {
289
+ return writeFile(fileName, vueTsc.removeEmitGlobalTypes(contents), ...args);
290
+ };
291
+ }
292
+ const vueLanguagePlugin = languageCore.createVueLanguagePlugin2(
293
+ ts2,
294
+ (id) => id,
295
+ languageCore.createRootFileChecker(
296
+ void 0,
297
+ () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
298
+ options.host?.useCaseSensitiveFileNames?.() ?? false
299
+ ),
300
+ options.options,
301
+ vueOptions
302
+ );
303
+ return [vueLanguagePlugin];
304
+ });
305
+ const createProgram = !hasVue ? ts__default.createProgram : (options) => {
306
+ const program = _createProgram(options);
307
+ const emit = program.emit;
308
+ program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
309
+ if (writeFile) {
310
+ return emit(
311
+ targetSourceFile,
312
+ (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
313
+ if (fileName.endsWith(".d.ts")) {
314
+ data = vueTsc.removeEmitGlobalTypes(data);
315
+ }
316
+ return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
317
+ },
318
+ cancellationToken,
319
+ emitOnlyDtsFiles,
320
+ customTransformers
321
+ );
322
+ }
323
+ return emit(
324
+ targetSourceFile,
325
+ writeFile,
326
+ cancellationToken,
327
+ emitOnlyDtsFiles,
328
+ customTransformers
329
+ );
330
+ };
331
+ return program;
332
+ };
349
333
 
350
334
  const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
351
335
  function rollupDeclarationFiles({
@@ -359,7 +343,7 @@ function rollupDeclarationFiles({
359
343
  rollupConfig = {},
360
344
  rollupOptions = {}
361
345
  }) {
362
- const configObjectFullPath = node_path.resolve(root, "api-extractor.json");
346
+ const configObjectFullPath = resolve(root, "api-extractor.json");
363
347
  if (!dtsRE$1.test(fileName)) {
364
348
  fileName += ".d.ts";
365
349
  }
@@ -389,7 +373,7 @@ function rollupDeclarationFiles({
389
373
  },
390
374
  dtsRollup: {
391
375
  enabled: true,
392
- publicTrimmedFilePath: node_path.resolve(outDir, fileName)
376
+ publicTrimmedFilePath: resolve(outDir, fileName)
393
377
  },
394
378
  tsdocMetadata: {
395
379
  enabled: false,
@@ -416,7 +400,7 @@ function rollupDeclarationFiles({
416
400
  localBuild: false,
417
401
  showVerboseMessages: false,
418
402
  showDiagnostics: false,
419
- typescriptCompilerFolder: libFolder ? node_path.resolve(libFolder) : void 0,
403
+ typescriptCompilerFolder: libFolder,
420
404
  ...rollupOptions
421
405
  });
422
406
  }
@@ -451,7 +435,7 @@ function querySvelteVersion() {
451
435
  if (typeof lowerVersion === "boolean")
452
436
  return;
453
437
  try {
454
- const version = localPkg.getPackageInfoSync("svelte")?.version ?? localPkg.getPackageInfoSync("svelte", { paths: [localPkg.resolveModule("svelte") || process.cwd()] })?.version;
438
+ const version = tryGetPackageInfo("svelte")?.version;
455
439
  lowerVersion = version ? compareVersions.compare(version, "4.0.0", "<") : false;
456
440
  } catch (e) {
457
441
  lowerVersion = false;
@@ -1224,7 +1208,7 @@ ${content}`;
1224
1208
  outDir,
1225
1209
  entryPath: path,
1226
1210
  fileName: node_path.basename(path),
1227
- libFolder: getTsLibFolder({ root, entryRoot }),
1211
+ libFolder: getTsLibFolder(),
1228
1212
  rollupConfig,
1229
1213
  rollupOptions
1230
1214
  });
package/dist/index.mjs CHANGED
@@ -12,72 +12,15 @@ import { cpus } from 'node:os';
12
12
  import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePlugin2, createRootFileChecker } from '@vue/language-core';
13
13
  import { proxyCreateProgram } from '@volar/typescript';
14
14
  import ts from 'typescript';
15
- import { getPackageInfoSync, resolveModule } from 'local-pkg';
16
15
  import { removeEmitGlobalTypes } from 'vue-tsc';
16
+ import { getPackageInfoSync, resolveModule } from 'local-pkg';
17
17
  import { createFilter } from '@rollup/pluginutils';
18
18
  import debug from 'debug';
19
19
  import { cyan, yellow, green } from 'kolorist';
20
20
  import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
21
- import { createRequire } from 'node:module';
22
21
  import { compare } from 'compare-versions';
23
22
  import MagicString from 'magic-string';
24
23
 
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
24
  const windowsSlashRE = /\\+/g;
82
25
  function slash(p) {
83
26
  return p.replace(windowsSlashRE, "/");
@@ -201,25 +144,9 @@ function getTsConfig(tsConfigPath, readFileSync) {
201
144
  Object.assign(tsConfig.compilerOptions, baseConfig.compilerOptions);
202
145
  return tsConfig;
203
146
  }
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;
147
+ function getTsLibFolder() {
148
+ const libFolder = tryGetPackageInfo("typescript")?.rootPath;
149
+ return libFolder && normalizePath(libFolder);
223
150
  }
224
151
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
225
152
  function base64Encode(number) {
@@ -342,6 +269,64 @@ function parseTsAliases(basePath, paths) {
342
269
  }
343
270
  return result;
344
271
  }
272
+ function tryGetPackageInfo(name) {
273
+ try {
274
+ return getPackageInfoSync(name) ?? getPackageInfoSync(name, { paths: [resolveModule(name) || process.cwd()] });
275
+ } catch (e) {
276
+ }
277
+ }
278
+
279
+ const hasVue = !!tryGetPackageInfo("vue");
280
+ const _createProgram = !hasVue ? ts.createProgram : proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
281
+ const { configFilePath } = options.options;
282
+ const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
283
+ if (options.host) {
284
+ const writeFile = options.host.writeFile.bind(options.host);
285
+ options.host.writeFile = (fileName, contents, ...args) => {
286
+ return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
287
+ };
288
+ }
289
+ const vueLanguagePlugin = createVueLanguagePlugin2(
290
+ ts2,
291
+ (id) => id,
292
+ createRootFileChecker(
293
+ void 0,
294
+ () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
295
+ options.host?.useCaseSensitiveFileNames?.() ?? false
296
+ ),
297
+ options.options,
298
+ vueOptions
299
+ );
300
+ return [vueLanguagePlugin];
301
+ });
302
+ const createProgram = !hasVue ? ts.createProgram : (options) => {
303
+ const program = _createProgram(options);
304
+ const emit = program.emit;
305
+ program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
306
+ if (writeFile) {
307
+ return emit(
308
+ targetSourceFile,
309
+ (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
310
+ if (fileName.endsWith(".d.ts")) {
311
+ data = removeEmitGlobalTypes(data);
312
+ }
313
+ return writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
314
+ },
315
+ cancellationToken,
316
+ emitOnlyDtsFiles,
317
+ customTransformers
318
+ );
319
+ }
320
+ return emit(
321
+ targetSourceFile,
322
+ writeFile,
323
+ cancellationToken,
324
+ emitOnlyDtsFiles,
325
+ customTransformers
326
+ );
327
+ };
328
+ return program;
329
+ };
345
330
 
346
331
  const dtsRE$1 = /\.d\.(m|c)?tsx?$/;
347
332
  function rollupDeclarationFiles({
@@ -355,7 +340,7 @@ function rollupDeclarationFiles({
355
340
  rollupConfig = {},
356
341
  rollupOptions = {}
357
342
  }) {
358
- const configObjectFullPath = resolve$1(root, "api-extractor.json");
343
+ const configObjectFullPath = resolve(root, "api-extractor.json");
359
344
  if (!dtsRE$1.test(fileName)) {
360
345
  fileName += ".d.ts";
361
346
  }
@@ -385,7 +370,7 @@ function rollupDeclarationFiles({
385
370
  },
386
371
  dtsRollup: {
387
372
  enabled: true,
388
- publicTrimmedFilePath: resolve$1(outDir, fileName)
373
+ publicTrimmedFilePath: resolve(outDir, fileName)
389
374
  },
390
375
  tsdocMetadata: {
391
376
  enabled: false,
@@ -412,7 +397,7 @@ function rollupDeclarationFiles({
412
397
  localBuild: false,
413
398
  showVerboseMessages: false,
414
399
  showDiagnostics: false,
415
- typescriptCompilerFolder: libFolder ? resolve$1(libFolder) : void 0,
400
+ typescriptCompilerFolder: libFolder,
416
401
  ...rollupOptions
417
402
  });
418
403
  }
@@ -447,7 +432,7 @@ function querySvelteVersion() {
447
432
  if (typeof lowerVersion === "boolean")
448
433
  return;
449
434
  try {
450
- const version = getPackageInfoSync("svelte")?.version ?? getPackageInfoSync("svelte", { paths: [resolveModule("svelte") || process.cwd()] })?.version;
435
+ const version = tryGetPackageInfo("svelte")?.version;
451
436
  lowerVersion = version ? compare(version, "4.0.0", "<") : false;
452
437
  } catch (e) {
453
438
  lowerVersion = false;
@@ -1220,7 +1205,7 @@ ${content}`;
1220
1205
  outDir,
1221
1206
  entryPath: path,
1222
1207
  fileName: basename(path),
1223
- libFolder: getTsLibFolder({ root, entryRoot }),
1208
+ libFolder: getTsLibFolder(),
1224
1209
  rollupConfig,
1225
1210
  rollupOptions
1226
1211
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
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",