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 +31 -19
- package/dist/index.mjs +31 -19
- package/package.json +1 -1
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
|
-
|
|
377
|
-
|
|
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
|
-
|
|
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 = `${
|
|
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 =
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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(`${
|
|
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
|
-
|
|
382
|
-
|
|
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
|
-
|
|
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 = `${
|
|
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 =
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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(`${
|
|
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,
|