vite-plugin-dts 1.6.0 → 1.6.2

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.js CHANGED
@@ -1,54 +1,29 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
-
26
- // src/index.ts
27
- var src_exports = {};
28
- __export(src_exports, {
29
- default: () => src_default
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
30
7
  });
31
- module.exports = dtsPlugin;
32
- dtsPlugin['default'] = dtsPlugin;
33
8
 
34
9
  // src/plugin.ts
35
- var import_path4 = require("path");
36
- var import_fs_extra = __toESM(require("fs-extra"));
37
- var import_os = __toESM(require("os"));
38
- var import_chalk = __toESM(require("chalk"));
39
- var import_fast_glob = __toESM(require("fast-glob"));
40
- var import_debug = require("debug");
41
- var import_ts_morph = require("ts-morph");
42
- var import_vite2 = require("vite");
43
- var import_typescript = require("typescript");
10
+ import { resolve as resolve3, dirname as dirname3, relative as relative2, basename } from "node:path";
11
+ import fs from "fs-extra";
12
+ import os from "os";
13
+ import chalk from "chalk";
14
+ import glob from "fast-glob";
15
+ import { debug } from "debug";
16
+ import { Project } from "ts-morph";
17
+ import { normalizePath as normalizePath2 } from "vite";
18
+ import { readConfigFile } from "typescript";
44
19
 
45
20
  // src/transform.ts
46
- var import_path2 = require("path");
47
- var import_vite = require("vite");
21
+ import { dirname as dirname2, relative, isAbsolute as isAbsolute2 } from "node:path";
22
+ import { normalizePath } from "vite";
48
23
 
49
24
  // src/utils.ts
50
- var import_path = require("path");
51
- var import_fs = require("fs");
25
+ import { resolve, isAbsolute, dirname, normalize, sep } from "node:path";
26
+ import { existsSync, readdirSync, lstatSync, rmdirSync } from "node:fs";
52
27
  function isNativeObj(value) {
53
28
  return Object.prototype.toString.call(value) === "[object Object]";
54
29
  }
@@ -92,7 +67,7 @@ function mergeObjects(sourceObj, targetObj) {
92
67
  return sourceObj;
93
68
  }
94
69
  function ensureAbsolute(path, root) {
95
- return path ? (0, import_path.isAbsolute)(path) ? path : (0, import_path.resolve)(root, path) : root;
70
+ return path ? isAbsolute(path) ? path : resolve(root, path) : root;
96
71
  }
97
72
  function ensureArray(value) {
98
73
  return Array.isArray(value) ? value : value ? [value] : [];
@@ -118,16 +93,16 @@ function queryPublicPath(paths) {
118
93
  if (paths.length === 0) {
119
94
  return "";
120
95
  } else if (paths.length === 1) {
121
- return (0, import_path.dirname)(paths[0]);
96
+ return dirname(paths[0]);
122
97
  }
123
- let publicPath = (0, import_path.normalize)((0, import_path.dirname)(paths[0])) + import_path.sep;
98
+ let publicPath = normalize(dirname(paths[0])) + sep;
124
99
  let publicUnits = publicPath.split(speRE);
125
100
  let index2 = publicUnits.length - 1;
126
101
  for (const path of paths.slice(1)) {
127
102
  if (!index2) {
128
103
  return publicPath;
129
104
  }
130
- const dirPath = (0, import_path.normalize)((0, import_path.dirname)(path)) + import_path.sep;
105
+ const dirPath = normalize(dirname(path)) + sep;
131
106
  if (dirPath.startsWith(publicPath)) {
132
107
  continue;
133
108
  }
@@ -144,7 +119,7 @@ function queryPublicPath(paths) {
144
119
  }
145
120
  index2 = i - 1;
146
121
  publicUnits = publicUnits.slice(0, index2 + 1);
147
- publicPath = publicUnits.join(import_path.sep) + import_path.sep;
122
+ publicPath = publicUnits.join(sep) + sep;
148
123
  break;
149
124
  }
150
125
  }
@@ -152,13 +127,13 @@ function queryPublicPath(paths) {
152
127
  return publicPath.slice(0, -1);
153
128
  }
154
129
  function removeDirIfEmpty(dir) {
155
- if (!(0, import_fs.existsSync)(dir)) {
130
+ if (!existsSync(dir)) {
156
131
  return;
157
132
  }
158
133
  let onlyHasDir = true;
159
- for (const file of (0, import_fs.readdirSync)(dir)) {
160
- const abs = (0, import_path.resolve)(dir, file);
161
- if ((0, import_fs.lstatSync)(abs).isDirectory()) {
134
+ for (const file of readdirSync(dir)) {
135
+ const abs = resolve(dir, file);
136
+ if (lstatSync(abs).isDirectory()) {
162
137
  if (!removeDirIfEmpty(abs)) {
163
138
  onlyHasDir = false;
164
139
  }
@@ -167,7 +142,7 @@ function removeDirIfEmpty(dir) {
167
142
  }
168
143
  }
169
144
  if (onlyHasDir) {
170
- (0, import_fs.rmdirSync)(dir);
145
+ rmdirSync(dir);
171
146
  }
172
147
  return onlyHasDir;
173
148
  }
@@ -244,7 +219,7 @@ function transformAliasImport(filePath, content, aliases, exclude = []) {
244
219
  if (exclude.some((e) => isRegExp(e) ? e.test(matchResult[1]) : String(e) === matchResult[1])) {
245
220
  return str;
246
221
  }
247
- const truthPath = (0, import_path2.isAbsolute)(matchedAlias.replacement) ? (0, import_vite.normalizePath)((0, import_path2.relative)((0, import_path2.dirname)(filePath), matchedAlias.replacement)) : (0, import_vite.normalizePath)(matchedAlias.replacement);
222
+ const truthPath = isAbsolute2(matchedAlias.replacement) ? normalizePath(relative(dirname2(filePath), matchedAlias.replacement)) : normalizePath(matchedAlias.replacement);
248
223
  return str.replace(
249
224
  isDynamic ? simpleDynamicImportRE : simpleStaticImportRE,
250
225
  `$1'${matchResult[1].replace(
@@ -272,8 +247,6 @@ function transferSetupPosition(content) {
272
247
  }
273
248
 
274
249
  // src/compile.ts
275
- var import_node_module = require("module");
276
- var import_meta = {};
277
250
  var exportDefaultRE = /export\s+default/;
278
251
  var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
279
252
  var noScriptContent = "import { defineComponent } from 'vue'\nexport default defineComponent({})";
@@ -281,21 +254,20 @@ var index = 1;
281
254
  var compileRoot = null;
282
255
  var compiler;
283
256
  var vue;
284
- var _require = (0, import_node_module.createRequire)(import_meta.url);
285
257
  function requireCompiler() {
286
258
  if (!compiler) {
287
259
  if (compileRoot) {
288
260
  try {
289
- compiler = _require(_require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
261
+ compiler = __require(__require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
290
262
  } catch (e) {
291
263
  }
292
264
  }
293
265
  if (!compiler) {
294
266
  try {
295
- compiler = _require("vue/compiler-sfc");
267
+ compiler = __require("vue/compiler-sfc");
296
268
  } catch (e) {
297
269
  try {
298
- compiler = _require("@vue/compiler-sfc");
270
+ compiler = __require("@vue/compiler-sfc");
299
271
  } catch (e2) {
300
272
  throw new Error("@vue/compiler-sfc is not present in the dependency tree.\n");
301
273
  }
@@ -308,13 +280,13 @@ function isVue3() {
308
280
  if (!vue) {
309
281
  if (compileRoot) {
310
282
  try {
311
- vue = _require(_require.resolve("vue", { paths: [compileRoot] }));
283
+ vue = __require(__require.resolve("vue", { paths: [compileRoot] }));
312
284
  } catch (e) {
313
285
  }
314
286
  }
315
287
  if (!vue) {
316
288
  try {
317
- vue = _require("vue");
289
+ vue = __require("vue");
318
290
  } catch (e) {
319
291
  throw new Error("vue is not present in the dependency tree.\n");
320
292
  }
@@ -384,12 +356,15 @@ const _sfc_main = ${classMatch[1]}`;
384
356
  }
385
357
 
386
358
  // src/rollup.ts
387
- var import_path3 = require("path");
388
- var import_api_extractor = require("@microsoft/api-extractor");
389
- var import_Collector = require("@microsoft/api-extractor/lib/collector/Collector");
390
- var import_MessageRouter = require("@microsoft/api-extractor/lib/collector/MessageRouter");
391
- var import_DtsRollupGenerator = require("@microsoft/api-extractor/lib/generators/DtsRollupGenerator");
392
- var import_node_core_library = require("@rushstack/node-core-library");
359
+ import { resolve as resolve2 } from "node:path";
360
+ import { ExtractorConfig, CompilerState } from "@microsoft/api-extractor";
361
+ import { Collector } from "@microsoft/api-extractor/lib/collector/Collector";
362
+ import { MessageRouter } from "@microsoft/api-extractor/lib/collector/MessageRouter";
363
+ import {
364
+ DtsRollupGenerator,
365
+ DtsRollupKind
366
+ } from "@microsoft/api-extractor/lib/generators/DtsRollupGenerator";
367
+ import { PackageJsonLookup } from "@rushstack/node-core-library";
393
368
  var dtsRE = /\.d\.tsx?$/;
394
369
  function rollupDeclarationFiles({
395
370
  root,
@@ -399,13 +374,13 @@ function rollupDeclarationFiles({
399
374
  fileName,
400
375
  compilerOptions
401
376
  }) {
402
- const configObjectFullPath = (0, import_path3.resolve)(root, "api-extractor.json");
403
- const packageJsonLookup = new import_node_core_library.PackageJsonLookup();
377
+ const configObjectFullPath = resolve2(root, "api-extractor.json");
378
+ const packageJsonLookup = new PackageJsonLookup();
404
379
  const packageJsonFullPath = packageJsonLookup.tryGetPackageJsonFilePathFor(configObjectFullPath);
405
380
  if (!dtsRE.test(fileName)) {
406
381
  fileName += ".d.ts";
407
382
  }
408
- const extractorConfig = import_api_extractor.ExtractorConfig.prepare({
383
+ const extractorConfig = ExtractorConfig.prepare({
409
384
  configObject: {
410
385
  projectFolder: root,
411
386
  mainEntryPointFilePath: entryPath,
@@ -422,7 +397,7 @@ function rollupDeclarationFiles({
422
397
  },
423
398
  dtsRollup: {
424
399
  enabled: true,
425
- publicTrimmedFilePath: (0, import_path3.resolve)(outputDir, fileName)
400
+ publicTrimmedFilePath: resolve2(outputDir, fileName)
426
401
  },
427
402
  tsdocMetadata: {
428
403
  enabled: false
@@ -443,11 +418,11 @@ function rollupDeclarationFiles({
443
418
  configObjectFullPath,
444
419
  packageJsonFullPath
445
420
  });
446
- const compilerState = import_api_extractor.CompilerState.create(extractorConfig, {
421
+ const compilerState = CompilerState.create(extractorConfig, {
447
422
  localBuild: true,
448
423
  showVerboseMessages: false
449
424
  });
450
- const messageRouter = new import_MessageRouter.MessageRouter({
425
+ const messageRouter = new MessageRouter({
451
426
  workingPackageFolder: root,
452
427
  messageCallback: void 0,
453
428
  messagesConfig: extractorConfig.messages,
@@ -455,16 +430,16 @@ function rollupDeclarationFiles({
455
430
  showDiagnostics: false,
456
431
  tsdocConfiguration: extractorConfig.tsdocConfiguration
457
432
  });
458
- const collector = new import_Collector.Collector({
433
+ const collector = new Collector({
459
434
  program: compilerState.program,
460
435
  messageRouter,
461
436
  extractorConfig
462
437
  });
463
438
  collector.analyze();
464
- import_DtsRollupGenerator.DtsRollupGenerator.writeTypingsFile(
439
+ DtsRollupGenerator.writeTypingsFile(
465
440
  collector,
466
441
  extractorConfig.publicTrimmedFilePath,
467
- import_DtsRollupGenerator.DtsRollupKind.PublicRelease,
442
+ DtsRollupKind.PublicRelease,
468
443
  extractorConfig.newlineKind
469
444
  );
470
445
  }
@@ -482,8 +457,8 @@ var fullRelativeRE = /^\.\.?\//;
482
457
  var defaultIndex = "index.d.ts";
483
458
  var noop = () => {
484
459
  };
485
- var logPrefix = import_chalk.default.cyan("[vite:dts]");
486
- var bundleDebug = (0, import_debug.debug)("vite-plugin-dts:bundle");
460
+ var logPrefix = chalk.cyan("[vite:dts]");
461
+ var bundleDebug = debug("vite-plugin-dts:bundle");
487
462
  function dtsPlugin(options = {}) {
488
463
  const {
489
464
  tsConfigFilePath = "tsconfig.json",
@@ -549,9 +524,9 @@ function dtsPlugin(options = {}) {
549
524
  logger = config.logger;
550
525
  if (!config.build.lib) {
551
526
  logger.warn(
552
- import_chalk.default.yellow(
527
+ chalk.yellow(
553
528
  `
554
- ${import_chalk.default.cyan(
529
+ ${chalk.cyan(
555
530
  "[vite:dts]"
556
531
  )} You building not a library that may not need to generate declaration files.
557
532
  `
@@ -572,9 +547,9 @@ ${import_chalk.default.cyan(
572
547
  outputDirs = options.outputDir ? ensureArray(options.outputDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(config.build.outDir, root)];
573
548
  if (!outputDirs[0]) {
574
549
  logger.error(
575
- import_chalk.default.red(
550
+ chalk.red(
576
551
  `
577
- ${import_chalk.default.cyan(
552
+ ${chalk.cyan(
578
553
  "[vite:dts]"
579
554
  )} Can not resolve declaration directory, please check your vite config and plugin options.
580
555
  `
@@ -584,7 +559,7 @@ ${import_chalk.default.cyan(
584
559
  }
585
560
  setCompileRoot(root);
586
561
  compilerOptions.rootDir || (compilerOptions.rootDir = root);
587
- project = new import_ts_morph.Project({
562
+ project = new Project({
588
563
  compilerOptions: mergeObjects(compilerOptions, {
589
564
  noEmitOnError,
590
565
  outDir: ".",
@@ -624,7 +599,7 @@ ${import_chalk.default.cyan(
624
599
  if (watchExtensionRE.test(id)) {
625
600
  isBundle = false;
626
601
  if (project) {
627
- const sourceFile = project.getSourceFile((0, import_vite2.normalizePath)(id));
602
+ const sourceFile = project.getSourceFile(normalizePath2(id));
628
603
  sourceFile && project.removeSourceFile(sourceFile);
629
604
  }
630
605
  }
@@ -632,21 +607,21 @@ ${import_chalk.default.cyan(
632
607
  async closeBundle() {
633
608
  if (!outputDirs || !project || isBundle)
634
609
  return;
635
- logger.info(import_chalk.default.green(`
610
+ logger.info(chalk.green(`
636
611
  ${logPrefix} Start generate declaration files...`));
637
612
  bundleDebug("start");
638
613
  isBundle = true;
639
614
  sourceDtsFiles.clear();
640
615
  const startTime = Date.now();
641
- const tsConfig = (0, import_typescript.readConfigFile)(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
616
+ const tsConfig = readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
642
617
  const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
643
- const parentTsConfig = parentTsConfigPath ? (0, import_typescript.readConfigFile)(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
618
+ const parentTsConfig = parentTsConfigPath ? readConfigFile(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
644
619
  const include = options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*";
645
620
  const exclude = options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**";
646
621
  bundleDebug("read config");
647
622
  const includedFileSet = /* @__PURE__ */ new Set();
648
623
  if (include && include.length) {
649
- const files = await (0, import_fast_glob.default)(ensureArray(include).map(normalizeGlob), {
624
+ const files = await glob(ensureArray(include).map(normalizeGlob), {
650
625
  cwd: root,
651
626
  absolute: true,
652
627
  ignore: ensureArray(exclude).map(normalizeGlob)
@@ -665,8 +640,8 @@ ${logPrefix} Start generate declaration files...`));
665
640
  if (hasJsVue) {
666
641
  if (!allowJs) {
667
642
  logger.warn(
668
- import_chalk.default.yellow(
669
- `${import_chalk.default.cyan(
643
+ chalk.yellow(
644
+ `${chalk.cyan(
670
645
  "[vite:dts]"
671
646
  )} Some js files are referenced, but you may not enable the 'allowJs' option.`
672
647
  )
@@ -676,6 +651,7 @@ ${logPrefix} Start generate declaration files...`));
676
651
  }
677
652
  bundleDebug("collect files");
678
653
  }
654
+ project.resolveSourceFileDependencies();
679
655
  bundleDebug("resolve");
680
656
  if (!skipDiagnostics) {
681
657
  const diagnostics = project.getPreEmitDiagnostics();
@@ -695,7 +671,7 @@ ${logPrefix} Start generate declaration files...`));
695
671
  const service = project.getLanguageService();
696
672
  const outputFiles = project.getSourceFiles().map(
697
673
  (sourceFile) => service.getEmitOutput(sourceFile, true).getOutputFiles().map((outputFile) => ({
698
- path: (0, import_vite2.normalizePath)((0, import_path4.resolve)(root, outputFile.compilerObject.name)),
674
+ path: normalizePath2(resolve3(root, outputFile.compilerObject.name)),
699
675
  content: outputFile.getText()
700
676
  }))
701
677
  ).flat().concat(dtsOutputFiles);
@@ -706,7 +682,7 @@ ${logPrefix} Start generate declaration files...`));
706
682
  entryRoot = ensureAbsolute(entryRoot, root);
707
683
  const wroteFiles = /* @__PURE__ */ new Set();
708
684
  const outputDir = outputDirs[0];
709
- await runParallel(import_os.default.cpus().length, outputFiles, async (outputFile) => {
685
+ await runParallel(os.cpus().length, outputFiles, async (outputFile) => {
710
686
  let filePath = outputFile.path;
711
687
  let content = outputFile.content;
712
688
  const isMapFile = filePath.endsWith(".map");
@@ -718,9 +694,9 @@ ${logPrefix} Start generate declaration files...`));
718
694
  content = transformAliasImport(filePath, content, aliases, aliasesExclude);
719
695
  content = staticImport || rollupTypes ? transformDynamicImport(content) : content;
720
696
  }
721
- filePath = (0, import_path4.resolve)(
697
+ filePath = resolve3(
722
698
  outputDir,
723
- (0, import_path4.relative)(entryRoot, cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath)
699
+ relative2(entryRoot, cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath)
724
700
  );
725
701
  if (typeof beforeWriteFile === "function") {
726
702
  const result = beforeWriteFile(filePath, content);
@@ -731,30 +707,30 @@ ${logPrefix} Start generate declaration files...`));
731
707
  content = result.content ?? content;
732
708
  }
733
709
  }
734
- await import_fs_extra.default.mkdir((0, import_path4.dirname)(filePath), { recursive: true });
735
- await import_fs_extra.default.writeFile(
710
+ await fs.mkdir(dirname3(filePath), { recursive: true });
711
+ await fs.writeFile(
736
712
  filePath,
737
713
  cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content,
738
714
  "utf-8"
739
715
  );
740
- wroteFiles.add((0, import_vite2.normalizePath)(filePath));
716
+ wroteFiles.add(normalizePath2(filePath));
741
717
  });
742
718
  bundleDebug("output");
743
719
  if (insertTypesEntry || rollupTypes) {
744
- const pkgPath = (0, import_path4.resolve)(root, "package.json");
745
- const pkg = import_fs_extra.default.existsSync(pkgPath) ? JSON.parse(await import_fs_extra.default.readFile(pkgPath, "utf-8")) : {};
720
+ const pkgPath = resolve3(root, "package.json");
721
+ const pkg = fs.existsSync(pkgPath) ? JSON.parse(await fs.readFile(pkgPath, "utf-8")) : {};
746
722
  const types = pkg.types || pkg.typings;
747
- let typesPath = types ? (0, import_path4.resolve)(root, types) : (0, import_path4.resolve)(outputDir, indexName);
748
- if (!import_fs_extra.default.existsSync(typesPath)) {
723
+ let typesPath = types ? resolve3(root, types) : resolve3(outputDir, indexName);
724
+ if (!fs.existsSync(typesPath)) {
749
725
  const entry = entries[0];
750
- const outputIndex = (0, import_path4.resolve)(outputDir, (0, import_path4.relative)(entryRoot, entry.replace(tsRE, ".d.ts")));
751
- let filePath = (0, import_vite2.normalizePath)((0, import_path4.relative)((0, import_path4.dirname)(typesPath), outputIndex));
726
+ const outputIndex = resolve3(outputDir, relative2(entryRoot, entry.replace(tsRE, ".d.ts")));
727
+ let filePath = normalizePath2(relative2(dirname3(typesPath), outputIndex));
752
728
  filePath = filePath.replace(dtsRE2, "");
753
729
  filePath = fullRelativeRE.test(filePath) ? filePath : `./${filePath}`;
754
730
  let content = `export * from '${filePath}'
755
731
  `;
756
- if (import_fs_extra.default.existsSync(outputIndex)) {
757
- const entryCodes = await import_fs_extra.default.readFile(outputIndex, "utf-8");
732
+ if (fs.existsSync(outputIndex)) {
733
+ const entryCodes = await fs.readFile(outputIndex, "utf-8");
758
734
  if (entryCodes.includes("export default")) {
759
735
  content += `import ${libName} from '${filePath}'
760
736
  export default ${libName}
@@ -770,32 +746,32 @@ export default ${libName}
770
746
  }
771
747
  }
772
748
  if (result !== false) {
773
- await import_fs_extra.default.writeFile(typesPath, content, "utf-8");
774
- wroteFiles.add((0, import_vite2.normalizePath)(typesPath));
749
+ await fs.writeFile(typesPath, content, "utf-8");
750
+ wroteFiles.add(normalizePath2(typesPath));
775
751
  }
776
752
  }
777
753
  bundleDebug("insert index");
778
754
  if (rollupTypes) {
779
- logger.info(import_chalk.default.green(`${logPrefix} Start rollup declaration files...`));
755
+ logger.info(chalk.green(`${logPrefix} Start rollup declaration files...`));
780
756
  rollupDeclarationFiles({
781
757
  root,
782
758
  tsConfigPath,
783
759
  compilerOptions,
784
760
  outputDir,
785
761
  entryPath: typesPath,
786
- fileName: (0, import_path4.basename)(typesPath)
762
+ fileName: basename(typesPath)
787
763
  });
788
- const wroteFile = (0, import_vite2.normalizePath)(typesPath);
764
+ const wroteFile = normalizePath2(typesPath);
789
765
  wroteFiles.delete(wroteFile);
790
- await runParallel(import_os.default.cpus().length, Array.from(wroteFiles), (f) => import_fs_extra.default.unlink(f));
766
+ await runParallel(os.cpus().length, Array.from(wroteFiles), (f) => fs.unlink(f));
791
767
  removeDirIfEmpty(outputDir);
792
768
  wroteFiles.clear();
793
769
  wroteFiles.add(wroteFile);
794
770
  if (copyDtsFiles) {
795
- await runParallel(import_os.default.cpus().length, dtsOutputFiles, async ({ path, content }) => {
796
- const filePath = (0, import_path4.resolve)(outputDir, (0, import_path4.basename)(path));
797
- await import_fs_extra.default.writeFile(filePath, content, "utf-8");
798
- wroteFiles.add((0, import_vite2.normalizePath)(filePath));
771
+ await runParallel(os.cpus().length, dtsOutputFiles, async ({ path, content }) => {
772
+ const filePath = resolve3(outputDir, basename(path));
773
+ await fs.writeFile(filePath, content, "utf-8");
774
+ wroteFiles.add(normalizePath2(filePath));
799
775
  });
800
776
  }
801
777
  bundleDebug("rollup");
@@ -803,14 +779,14 @@ export default ${libName}
803
779
  }
804
780
  if (outputDirs.length > 1) {
805
781
  const dirs = outputDirs.slice(1);
806
- await runParallel(import_os.default.cpus().length, Array.from(wroteFiles), async (wroteFile) => {
807
- const relativePath = (0, import_path4.relative)(outputDir, wroteFile);
808
- const content = await import_fs_extra.default.readFile(wroteFile, "utf-8");
782
+ await runParallel(os.cpus().length, Array.from(wroteFiles), async (wroteFile) => {
783
+ const relativePath = relative2(outputDir, wroteFile);
784
+ const content = await fs.readFile(wroteFile, "utf-8");
809
785
  await Promise.all(
810
786
  dirs.map(async (dir) => {
811
- const filePath = (0, import_path4.resolve)(dir, relativePath);
812
- await import_fs_extra.default.mkdir((0, import_path4.dirname)(filePath), { recursive: true });
813
- await import_fs_extra.default.writeFile(filePath, content, "utf-8");
787
+ const filePath = resolve3(dir, relativePath);
788
+ await fs.mkdir(dirname3(filePath), { recursive: true });
789
+ await fs.writeFile(filePath, content, "utf-8");
814
790
  })
815
791
  );
816
792
  });
@@ -821,7 +797,7 @@ export default ${libName}
821
797
  }
822
798
  bundleDebug("finish");
823
799
  logger.info(
824
- import_chalk.default.green(`${logPrefix} Declaration files built in ${Date.now() - startTime}ms.
800
+ chalk.green(`${logPrefix} Declaration files built in ${Date.now() - startTime}ms.
825
801
  `)
826
802
  );
827
803
  }
@@ -830,5 +806,6 @@ export default ${libName}
830
806
 
831
807
  // src/index.ts
832
808
  var src_default = dtsPlugin;
833
- // Annotate the CommonJS export names for ESM import in node:
834
- 0 && (module.exports = {});
809
+ export {
810
+ src_default as default
811
+ };
package/dist/index.mjs CHANGED
@@ -1,5 +1,13 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
1
9
  // src/plugin.ts
2
- import { resolve as resolve3, dirname as dirname3, relative as relative2, basename } from "path";
10
+ import { resolve as resolve3, dirname as dirname3, relative as relative2, basename } from "node:path";
3
11
  import fs from "fs-extra";
4
12
  import os from "os";
5
13
  import chalk from "chalk";
@@ -10,12 +18,12 @@ import { normalizePath as normalizePath2 } from "vite";
10
18
  import { readConfigFile } from "typescript";
11
19
 
12
20
  // src/transform.ts
13
- import { dirname as dirname2, relative, isAbsolute as isAbsolute2 } from "path";
21
+ import { dirname as dirname2, relative, isAbsolute as isAbsolute2 } from "node:path";
14
22
  import { normalizePath } from "vite";
15
23
 
16
24
  // src/utils.ts
17
- import { resolve, isAbsolute, dirname, normalize, sep } from "path";
18
- import { existsSync, readdirSync, lstatSync, rmdirSync } from "fs";
25
+ import { resolve, isAbsolute, dirname, normalize, sep } from "node:path";
26
+ import { existsSync, readdirSync, lstatSync, rmdirSync } from "node:fs";
19
27
  function isNativeObj(value) {
20
28
  return Object.prototype.toString.call(value) === "[object Object]";
21
29
  }
@@ -239,7 +247,6 @@ function transferSetupPosition(content) {
239
247
  }
240
248
 
241
249
  // src/compile.ts
242
- import { createRequire } from "node:module";
243
250
  var exportDefaultRE = /export\s+default/;
244
251
  var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
245
252
  var noScriptContent = "import { defineComponent } from 'vue'\nexport default defineComponent({})";
@@ -247,21 +254,20 @@ var index = 1;
247
254
  var compileRoot = null;
248
255
  var compiler;
249
256
  var vue;
250
- var _require = createRequire(import.meta.url);
251
257
  function requireCompiler() {
252
258
  if (!compiler) {
253
259
  if (compileRoot) {
254
260
  try {
255
- compiler = _require(_require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
261
+ compiler = __require(__require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
256
262
  } catch (e) {
257
263
  }
258
264
  }
259
265
  if (!compiler) {
260
266
  try {
261
- compiler = _require("vue/compiler-sfc");
267
+ compiler = __require("vue/compiler-sfc");
262
268
  } catch (e) {
263
269
  try {
264
- compiler = _require("@vue/compiler-sfc");
270
+ compiler = __require("@vue/compiler-sfc");
265
271
  } catch (e2) {
266
272
  throw new Error("@vue/compiler-sfc is not present in the dependency tree.\n");
267
273
  }
@@ -274,13 +280,13 @@ function isVue3() {
274
280
  if (!vue) {
275
281
  if (compileRoot) {
276
282
  try {
277
- vue = _require(_require.resolve("vue", { paths: [compileRoot] }));
283
+ vue = __require(__require.resolve("vue", { paths: [compileRoot] }));
278
284
  } catch (e) {
279
285
  }
280
286
  }
281
287
  if (!vue) {
282
288
  try {
283
- vue = _require("vue");
289
+ vue = __require("vue");
284
290
  } catch (e) {
285
291
  throw new Error("vue is not present in the dependency tree.\n");
286
292
  }
@@ -350,7 +356,7 @@ const _sfc_main = ${classMatch[1]}`;
350
356
  }
351
357
 
352
358
  // src/rollup.ts
353
- import { resolve as resolve2 } from "path";
359
+ import { resolve as resolve2 } from "node:path";
354
360
  import { ExtractorConfig, CompilerState } from "@microsoft/api-extractor";
355
361
  import { Collector } from "@microsoft/api-extractor/lib/collector/Collector";
356
362
  import { MessageRouter } from "@microsoft/api-extractor/lib/collector/MessageRouter";