vite-plugin-dts 1.7.2 → 1.7.3

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
@@ -356,7 +356,6 @@ const _sfc_main = ${classMatch[1]}`;
356
356
  const dtsRE$1 = /\.d\.tsx?$/;
357
357
  function rollupDeclarationFiles({
358
358
  root,
359
- tsConfigPath,
360
359
  outputDir,
361
360
  entryPath,
362
361
  fileName,
@@ -373,8 +372,10 @@ function rollupDeclarationFiles({
373
372
  projectFolder: root,
374
373
  mainEntryPointFilePath: entryPath,
375
374
  compiler: {
376
- tsconfigFilePath: tsConfigPath,
377
- overrideTsconfig: compilerOptions
375
+ overrideTsconfig: {
376
+ $schema: "http://json.schemastore.org/tsconfig",
377
+ compilerOptions
378
+ }
378
379
  },
379
380
  apiReport: {
380
381
  enabled: false,
@@ -439,13 +440,16 @@ const noneExport = "export {};\n";
439
440
  const vueRE = /\.vue$/;
440
441
  const tsRE = /\.(m|c)?tsx?$/;
441
442
  const jsRE = /\.(m|c)?jsx?$/;
442
- const dtsRE = /\.d\.tsx?$/;
443
+ const dtsRE = /\.d\.(m|c)?tsx?$/;
443
444
  const tjsRE = /\.(m|c)?(t|j)sx?$/;
445
+ const mtjsRE = /\.m(t|j)sx?$/;
446
+ const ctjsRE = /\.c(t|j)sx?$/;
444
447
  const watchExtensionRE = /\.(vue|(m|c)?(t|j)sx?)$/;
445
448
  const fullRelativeRE = /^\.\.?\//;
446
449
  const defaultIndex = "index.d.ts";
447
450
  const noop = () => {
448
451
  };
452
+ const extPrefix = (file) => mtjsRE.test(file) ? "m" : ctjsRE.test(file) ? "c" : "";
449
453
  const logPrefix = kolorist.cyan("[vite:dts]");
450
454
  const bundleDebug = debug("vite-plugin-dts:bundle");
451
455
  function dtsPlugin(options = {}) {
@@ -466,7 +470,7 @@ function dtsPlugin(options = {}) {
466
470
  beforeWriteFile = noop,
467
471
  afterBuild = noop
468
472
  } = options;
469
- const compilerOptions = options.compilerOptions ?? {};
473
+ let compilerOptions = options.compilerOptions ?? {};
470
474
  let root;
471
475
  let entryRoot = options.entryRoot ?? "";
472
476
  let libName;
@@ -540,7 +544,7 @@ ${kolorist.cyan(
540
544
  libName = config.build.lib.name || "_default";
541
545
  indexName = typeof filename === "string" ? filename : filename("es", entry);
542
546
  if (!dtsRE.test(indexName)) {
543
- indexName = `${tjsRE.test(indexName) ? indexName.replace(tjsRE, "") : indexName}.d.ts`;
547
+ indexName = `${indexName.replace(tjsRE, "")}.d.${extPrefix(indexName)}ts`;
544
548
  }
545
549
  }
546
550
  root = ensureAbsolute(options.root ?? "", config.root);
@@ -559,9 +563,9 @@ ${kolorist.cyan(
559
563
  return;
560
564
  }
561
565
  setCompileRoot(root);
562
- compilerOptions.rootDir || (compilerOptions.rootDir = root);
563
566
  project = new tsMorph.Project({
564
567
  compilerOptions: mergeObjects(compilerOptions, {
568
+ rootDir: compilerOptions.rootDir || root,
565
569
  noEmitOnError,
566
570
  outDir: ".",
567
571
  declarationDir: null,
@@ -575,16 +579,26 @@ ${kolorist.cyan(
575
579
  libFolderPath: libFolderPath ? ensureAbsolute(libFolderPath, root) : void 0
576
580
  });
577
581
  allowJs = project.getCompilerOptions().allowJs ?? false;
578
- const tsConfig = typescript.readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
579
- const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
580
- const parentTsConfig = parentTsConfigPath ? typescript.readConfigFile(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
581
- include = ensureArray(
582
- options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*"
583
- ).map(normalizeGlob);
584
- exclude = ensureArray(
585
- options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**"
586
- ).map(normalizeGlob);
582
+ const tsConfig = { compilerOptions: {} };
583
+ const readFile = project.getFileSystem().readFileSync;
584
+ let currentConfigPath = tsConfigPath;
585
+ while (currentConfigPath) {
586
+ const currentConfig = typescript.readConfigFile(currentConfigPath, readFile).config ?? {};
587
+ Object.assign(tsConfig.compilerOptions, currentConfig.compilerOptions || {});
588
+ if (!tsConfig.include) {
589
+ tsConfig.include = currentConfig.include;
590
+ }
591
+ if (!tsConfig.exclude) {
592
+ tsConfig.exclude = currentConfig.exclude;
593
+ }
594
+ currentConfigPath = currentConfig.extends;
595
+ }
596
+ include = ensureArray(options.include ?? tsConfig.include ?? "**/*").map(normalizeGlob);
597
+ exclude = ensureArray(options.exclude ?? tsConfig.exclude ?? "node_modules/**").map(
598
+ normalizeGlob
599
+ );
587
600
  filter = pluginutils.createFilter(include, exclude, { resolve: root });
601
+ compilerOptions = tsConfig.compilerOptions;
588
602
  },
589
603
  buildStart(inputOptions) {
590
604
  if (Array.isArray(inputOptions.input)) {
@@ -646,7 +660,7 @@ ${logPrefix} Start generate declaration files...`));
646
660
  includedFileSet.add(file);
647
661
  return;
648
662
  }
649
- includedFileSet.add(`${tjsRE.test(file) ? file.replace(tjsRE, "") : file}.d.ts`);
663
+ includedFileSet.add(`${file.replace(tjsRE, "")}.d.${extPrefix(file)}ts`);
650
664
  });
651
665
  if (hasJsVue) {
652
666
  if (!allowJs) {
@@ -777,7 +791,6 @@ export default ${libName}
777
791
  const path = node_path.resolve(outputDir, `${name.replace(tsRE, "")}.d.ts`);
778
792
  rollupDeclarationFiles({
779
793
  root,
780
- tsConfigPath,
781
794
  compilerOptions,
782
795
  outputDir,
783
796
  entryPath: path,
@@ -790,7 +803,6 @@ export default ${libName}
790
803
  } else {
791
804
  rollupDeclarationFiles({
792
805
  root,
793
- tsConfigPath,
794
806
  compilerOptions,
795
807
  outputDir,
796
808
  entryPath: typesPath,
package/dist/index.mjs CHANGED
@@ -361,7 +361,6 @@ const _sfc_main = ${classMatch[1]}`;
361
361
  const dtsRE$1 = /\.d\.tsx?$/;
362
362
  function rollupDeclarationFiles({
363
363
  root,
364
- tsConfigPath,
365
364
  outputDir,
366
365
  entryPath,
367
366
  fileName,
@@ -378,8 +377,10 @@ function rollupDeclarationFiles({
378
377
  projectFolder: root,
379
378
  mainEntryPointFilePath: entryPath,
380
379
  compiler: {
381
- tsconfigFilePath: tsConfigPath,
382
- overrideTsconfig: compilerOptions
380
+ overrideTsconfig: {
381
+ $schema: "http://json.schemastore.org/tsconfig",
382
+ compilerOptions
383
+ }
383
384
  },
384
385
  apiReport: {
385
386
  enabled: false,
@@ -444,13 +445,16 @@ const noneExport = "export {};\n";
444
445
  const vueRE = /\.vue$/;
445
446
  const tsRE = /\.(m|c)?tsx?$/;
446
447
  const jsRE = /\.(m|c)?jsx?$/;
447
- const dtsRE = /\.d\.tsx?$/;
448
+ const dtsRE = /\.d\.(m|c)?tsx?$/;
448
449
  const tjsRE = /\.(m|c)?(t|j)sx?$/;
450
+ const mtjsRE = /\.m(t|j)sx?$/;
451
+ const ctjsRE = /\.c(t|j)sx?$/;
449
452
  const watchExtensionRE = /\.(vue|(m|c)?(t|j)sx?)$/;
450
453
  const fullRelativeRE = /^\.\.?\//;
451
454
  const defaultIndex = "index.d.ts";
452
455
  const noop = () => {
453
456
  };
457
+ const extPrefix = (file) => mtjsRE.test(file) ? "m" : ctjsRE.test(file) ? "c" : "";
454
458
  const logPrefix = cyan("[vite:dts]");
455
459
  const bundleDebug = debug("vite-plugin-dts:bundle");
456
460
  function dtsPlugin(options = {}) {
@@ -471,7 +475,7 @@ function dtsPlugin(options = {}) {
471
475
  beforeWriteFile = noop,
472
476
  afterBuild = noop
473
477
  } = options;
474
- const compilerOptions = options.compilerOptions ?? {};
478
+ let compilerOptions = options.compilerOptions ?? {};
475
479
  let root;
476
480
  let entryRoot = options.entryRoot ?? "";
477
481
  let libName;
@@ -545,7 +549,7 @@ ${cyan(
545
549
  libName = config.build.lib.name || "_default";
546
550
  indexName = typeof filename === "string" ? filename : filename("es", entry);
547
551
  if (!dtsRE.test(indexName)) {
548
- indexName = `${tjsRE.test(indexName) ? indexName.replace(tjsRE, "") : indexName}.d.ts`;
552
+ indexName = `${indexName.replace(tjsRE, "")}.d.${extPrefix(indexName)}ts`;
549
553
  }
550
554
  }
551
555
  root = ensureAbsolute(options.root ?? "", config.root);
@@ -564,9 +568,9 @@ ${cyan(
564
568
  return;
565
569
  }
566
570
  setCompileRoot(root);
567
- compilerOptions.rootDir || (compilerOptions.rootDir = root);
568
571
  project = new Project({
569
572
  compilerOptions: mergeObjects(compilerOptions, {
573
+ rootDir: compilerOptions.rootDir || root,
570
574
  noEmitOnError,
571
575
  outDir: ".",
572
576
  declarationDir: null,
@@ -580,16 +584,26 @@ ${cyan(
580
584
  libFolderPath: libFolderPath ? ensureAbsolute(libFolderPath, root) : void 0
581
585
  });
582
586
  allowJs = project.getCompilerOptions().allowJs ?? false;
583
- const tsConfig = typescript.readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
584
- const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
585
- const parentTsConfig = parentTsConfigPath ? typescript.readConfigFile(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
586
- include = ensureArray(
587
- options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*"
588
- ).map(normalizeGlob);
589
- exclude = ensureArray(
590
- options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**"
591
- ).map(normalizeGlob);
587
+ const tsConfig = { compilerOptions: {} };
588
+ const readFile = project.getFileSystem().readFileSync;
589
+ let currentConfigPath = tsConfigPath;
590
+ while (currentConfigPath) {
591
+ const currentConfig = typescript.readConfigFile(currentConfigPath, readFile).config ?? {};
592
+ Object.assign(tsConfig.compilerOptions, currentConfig.compilerOptions || {});
593
+ if (!tsConfig.include) {
594
+ tsConfig.include = currentConfig.include;
595
+ }
596
+ if (!tsConfig.exclude) {
597
+ tsConfig.exclude = currentConfig.exclude;
598
+ }
599
+ currentConfigPath = currentConfig.extends;
600
+ }
601
+ include = ensureArray(options.include ?? tsConfig.include ?? "**/*").map(normalizeGlob);
602
+ exclude = ensureArray(options.exclude ?? tsConfig.exclude ?? "node_modules/**").map(
603
+ normalizeGlob
604
+ );
592
605
  filter = createFilter(include, exclude, { resolve: root });
606
+ compilerOptions = tsConfig.compilerOptions;
593
607
  },
594
608
  buildStart(inputOptions) {
595
609
  if (Array.isArray(inputOptions.input)) {
@@ -651,7 +665,7 @@ ${logPrefix} Start generate declaration files...`));
651
665
  includedFileSet.add(file);
652
666
  return;
653
667
  }
654
- includedFileSet.add(`${tjsRE.test(file) ? file.replace(tjsRE, "") : file}.d.ts`);
668
+ includedFileSet.add(`${file.replace(tjsRE, "")}.d.${extPrefix(file)}ts`);
655
669
  });
656
670
  if (hasJsVue) {
657
671
  if (!allowJs) {
@@ -782,7 +796,6 @@ export default ${libName}
782
796
  const path = resolve(outputDir, `${name.replace(tsRE, "")}.d.ts`);
783
797
  rollupDeclarationFiles({
784
798
  root,
785
- tsConfigPath,
786
799
  compilerOptions,
787
800
  outputDir,
788
801
  entryPath: path,
@@ -795,7 +808,6 @@ export default ${libName}
795
808
  } else {
796
809
  rollupDeclarationFiles({
797
810
  root,
798
- tsConfigPath,
799
811
  compilerOptions,
800
812
  outputDir,
801
813
  entryPath: typesPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "qmhc",