vite-plugin-dts 1.2.1 → 1.3.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.d.ts +1 -1
- package/dist/index.js +27 -9
- package/dist/index.mjs +27 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface PluginOptions {
|
|
|
9
9
|
include?: string | string[];
|
|
10
10
|
exclude?: string | string[];
|
|
11
11
|
root?: string;
|
|
12
|
-
outputDir?: string;
|
|
12
|
+
outputDir?: string | string[];
|
|
13
13
|
entryRoot?: string;
|
|
14
14
|
compilerOptions?: ts.CompilerOptions | null;
|
|
15
15
|
tsConfigFilePath?: string;
|
package/dist/index.js
CHANGED
|
@@ -444,7 +444,7 @@ function dtsPlugin(options = {}) {
|
|
|
444
444
|
let logger;
|
|
445
445
|
let project;
|
|
446
446
|
let tsConfigPath;
|
|
447
|
-
let
|
|
447
|
+
let outputDirs;
|
|
448
448
|
let isBundle = false;
|
|
449
449
|
const sourceDtsFiles = /* @__PURE__ */ new Set();
|
|
450
450
|
let hasJsVue = false;
|
|
@@ -468,7 +468,7 @@ function dtsPlugin(options = {}) {
|
|
|
468
468
|
if (aliasesExclude.length > 0) {
|
|
469
469
|
aliases = aliases.filter(({ find }) => !aliasesExclude.some((alias) => {
|
|
470
470
|
var _a3;
|
|
471
|
-
return
|
|
471
|
+
return alias && (isRegExp(find) ? find.toString() === alias.toString() : isRegExp(alias) ? (_a3 = find.match(alias)) == null ? void 0 : _a3[0] : find === alias);
|
|
472
472
|
}));
|
|
473
473
|
}
|
|
474
474
|
},
|
|
@@ -491,8 +491,8 @@ ${import_chalk.default.cyan("[vite:dts]")} You building not a library that may n
|
|
|
491
491
|
}
|
|
492
492
|
root = ensureAbsolute((_b2 = options.root) != null ? _b2 : "", config.root);
|
|
493
493
|
tsConfigPath = ensureAbsolute(tsConfigFilePath, root);
|
|
494
|
-
|
|
495
|
-
if (!
|
|
494
|
+
outputDirs = options.outputDir ? ensureArray(options.outputDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(config.build.outDir, root)];
|
|
495
|
+
if (!outputDirs) {
|
|
496
496
|
logger.error(import_chalk.default.red(`
|
|
497
497
|
${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory, please check your vite config and plugin options.
|
|
498
498
|
`));
|
|
@@ -547,7 +547,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
547
547
|
},
|
|
548
548
|
async closeBundle() {
|
|
549
549
|
var _a2, _b2, _c, _d, _e, _f;
|
|
550
|
-
if (!
|
|
550
|
+
if (!outputDirs || !project || isBundle)
|
|
551
551
|
return;
|
|
552
552
|
logger.info(import_chalk.default.green(`
|
|
553
553
|
${logPrefix} Start generate declaration files...`));
|
|
@@ -604,7 +604,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
604
604
|
}));
|
|
605
605
|
const service = project.getLanguageService();
|
|
606
606
|
const outputFiles = project.getSourceFiles().map((sourceFile) => service.getEmitOutput(sourceFile, true).getOutputFiles().map((outputFile) => ({
|
|
607
|
-
path:
|
|
607
|
+
path: (0, import_vite2.normalizePath)((0, import_path4.resolve)(root, outputFile.compilerObject.name)),
|
|
608
608
|
content: outputFile.getText()
|
|
609
609
|
}))).flat().concat(dtsOutputFiles);
|
|
610
610
|
bundleDebug("emit");
|
|
@@ -613,6 +613,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
613
613
|
}
|
|
614
614
|
entryRoot = ensureAbsolute(entryRoot, root);
|
|
615
615
|
const wroteFiles = /* @__PURE__ */ new Set();
|
|
616
|
+
const outputDir = outputDirs[0];
|
|
616
617
|
await runParallel(import_os.default.cpus().length, outputFiles, async (outputFile) => {
|
|
617
618
|
var _a3, _b3;
|
|
618
619
|
let filePath = outputFile.path;
|
|
@@ -635,7 +636,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
635
636
|
}
|
|
636
637
|
}
|
|
637
638
|
await import_fs_extra.default.mkdir((0, import_path4.dirname)(filePath), { recursive: true });
|
|
638
|
-
await import_fs_extra.default.writeFile(filePath, cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content, "
|
|
639
|
+
await import_fs_extra.default.writeFile(filePath, cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content, "utf-8");
|
|
639
640
|
wroteFiles.add((0, import_vite2.normalizePath)(filePath));
|
|
640
641
|
});
|
|
641
642
|
bundleDebug("output");
|
|
@@ -671,17 +672,34 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
671
672
|
entryPath: typesPath,
|
|
672
673
|
fileName: (0, import_path4.basename)(typesPath)
|
|
673
674
|
});
|
|
674
|
-
|
|
675
|
+
const wroteFile = (0, import_vite2.normalizePath)(typesPath);
|
|
676
|
+
wroteFiles.delete(wroteFile);
|
|
675
677
|
await runParallel(import_os.default.cpus().length, Array.from(wroteFiles), (f) => import_fs_extra.default.unlink(f));
|
|
676
678
|
removeDirIfEmpty(outputDir);
|
|
679
|
+
wroteFiles.clear();
|
|
680
|
+
wroteFiles.add(wroteFile);
|
|
677
681
|
if (copyDtsFiles) {
|
|
678
682
|
await runParallel(import_os.default.cpus().length, dtsOutputFiles, async ({ path, content }) => {
|
|
679
|
-
|
|
683
|
+
const filePath = (0, import_path4.resolve)(outputDir, (0, import_path4.basename)(path));
|
|
684
|
+
await import_fs_extra.default.writeFile(filePath, content, "utf-8");
|
|
685
|
+
wroteFiles.add((0, import_vite2.normalizePath)(filePath));
|
|
680
686
|
});
|
|
681
687
|
}
|
|
682
688
|
bundleDebug("rollup");
|
|
683
689
|
}
|
|
684
690
|
}
|
|
691
|
+
if (outputDirs.length > 1) {
|
|
692
|
+
const dirs = outputDirs.slice(1);
|
|
693
|
+
await runParallel(import_os.default.cpus().length, Array.from(wroteFiles), async (wroteFile) => {
|
|
694
|
+
const relativePath = (0, import_path4.relative)(outputDir, wroteFile);
|
|
695
|
+
const content = await import_fs_extra.default.readFile(wroteFile, "utf-8");
|
|
696
|
+
await Promise.all(dirs.map(async (dir) => {
|
|
697
|
+
const filePath = (0, import_path4.resolve)(dir, relativePath);
|
|
698
|
+
await import_fs_extra.default.mkdir((0, import_path4.dirname)(filePath), { recursive: true });
|
|
699
|
+
await import_fs_extra.default.writeFile(filePath, content, "utf-8");
|
|
700
|
+
}));
|
|
701
|
+
});
|
|
702
|
+
}
|
|
685
703
|
if (typeof afterBuild === "function") {
|
|
686
704
|
const result = afterBuild();
|
|
687
705
|
isPromise(result) && await result;
|
package/dist/index.mjs
CHANGED
|
@@ -426,7 +426,7 @@ function dtsPlugin(options = {}) {
|
|
|
426
426
|
let logger;
|
|
427
427
|
let project;
|
|
428
428
|
let tsConfigPath;
|
|
429
|
-
let
|
|
429
|
+
let outputDirs;
|
|
430
430
|
let isBundle = false;
|
|
431
431
|
const sourceDtsFiles = /* @__PURE__ */ new Set();
|
|
432
432
|
let hasJsVue = false;
|
|
@@ -450,7 +450,7 @@ function dtsPlugin(options = {}) {
|
|
|
450
450
|
if (aliasesExclude.length > 0) {
|
|
451
451
|
aliases = aliases.filter(({ find }) => !aliasesExclude.some((alias) => {
|
|
452
452
|
var _a3;
|
|
453
|
-
return
|
|
453
|
+
return alias && (isRegExp(find) ? find.toString() === alias.toString() : isRegExp(alias) ? (_a3 = find.match(alias)) == null ? void 0 : _a3[0] : find === alias);
|
|
454
454
|
}));
|
|
455
455
|
}
|
|
456
456
|
},
|
|
@@ -473,8 +473,8 @@ ${chalk.cyan("[vite:dts]")} You building not a library that may not need to gene
|
|
|
473
473
|
}
|
|
474
474
|
root = ensureAbsolute((_b2 = options.root) != null ? _b2 : "", config.root);
|
|
475
475
|
tsConfigPath = ensureAbsolute(tsConfigFilePath, root);
|
|
476
|
-
|
|
477
|
-
if (!
|
|
476
|
+
outputDirs = options.outputDir ? ensureArray(options.outputDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(config.build.outDir, root)];
|
|
477
|
+
if (!outputDirs) {
|
|
478
478
|
logger.error(chalk.red(`
|
|
479
479
|
${chalk.cyan("[vite:dts]")} Can not resolve declaration directory, please check your vite config and plugin options.
|
|
480
480
|
`));
|
|
@@ -529,7 +529,7 @@ ${chalk.cyan("[vite:dts]")} Can not resolve declaration directory, please check
|
|
|
529
529
|
},
|
|
530
530
|
async closeBundle() {
|
|
531
531
|
var _a2, _b2, _c, _d, _e, _f;
|
|
532
|
-
if (!
|
|
532
|
+
if (!outputDirs || !project || isBundle)
|
|
533
533
|
return;
|
|
534
534
|
logger.info(chalk.green(`
|
|
535
535
|
${logPrefix} Start generate declaration files...`));
|
|
@@ -586,7 +586,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
586
586
|
}));
|
|
587
587
|
const service = project.getLanguageService();
|
|
588
588
|
const outputFiles = project.getSourceFiles().map((sourceFile) => service.getEmitOutput(sourceFile, true).getOutputFiles().map((outputFile) => ({
|
|
589
|
-
path: outputFile.
|
|
589
|
+
path: normalizePath2(resolve3(root, outputFile.compilerObject.name)),
|
|
590
590
|
content: outputFile.getText()
|
|
591
591
|
}))).flat().concat(dtsOutputFiles);
|
|
592
592
|
bundleDebug("emit");
|
|
@@ -595,6 +595,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
595
595
|
}
|
|
596
596
|
entryRoot = ensureAbsolute(entryRoot, root);
|
|
597
597
|
const wroteFiles = /* @__PURE__ */ new Set();
|
|
598
|
+
const outputDir = outputDirs[0];
|
|
598
599
|
await runParallel(os.cpus().length, outputFiles, async (outputFile) => {
|
|
599
600
|
var _a3, _b3;
|
|
600
601
|
let filePath = outputFile.path;
|
|
@@ -617,7 +618,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
617
618
|
}
|
|
618
619
|
}
|
|
619
620
|
await fs.mkdir(dirname3(filePath), { recursive: true });
|
|
620
|
-
await fs.writeFile(filePath, cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content, "
|
|
621
|
+
await fs.writeFile(filePath, cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content, "utf-8");
|
|
621
622
|
wroteFiles.add(normalizePath2(filePath));
|
|
622
623
|
});
|
|
623
624
|
bundleDebug("output");
|
|
@@ -653,17 +654,34 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
653
654
|
entryPath: typesPath,
|
|
654
655
|
fileName: basename(typesPath)
|
|
655
656
|
});
|
|
656
|
-
|
|
657
|
+
const wroteFile = normalizePath2(typesPath);
|
|
658
|
+
wroteFiles.delete(wroteFile);
|
|
657
659
|
await runParallel(os.cpus().length, Array.from(wroteFiles), (f) => fs.unlink(f));
|
|
658
660
|
removeDirIfEmpty(outputDir);
|
|
661
|
+
wroteFiles.clear();
|
|
662
|
+
wroteFiles.add(wroteFile);
|
|
659
663
|
if (copyDtsFiles) {
|
|
660
664
|
await runParallel(os.cpus().length, dtsOutputFiles, async ({ path, content }) => {
|
|
661
|
-
|
|
665
|
+
const filePath = resolve3(outputDir, basename(path));
|
|
666
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
667
|
+
wroteFiles.add(normalizePath2(filePath));
|
|
662
668
|
});
|
|
663
669
|
}
|
|
664
670
|
bundleDebug("rollup");
|
|
665
671
|
}
|
|
666
672
|
}
|
|
673
|
+
if (outputDirs.length > 1) {
|
|
674
|
+
const dirs = outputDirs.slice(1);
|
|
675
|
+
await runParallel(os.cpus().length, Array.from(wroteFiles), async (wroteFile) => {
|
|
676
|
+
const relativePath = relative2(outputDir, wroteFile);
|
|
677
|
+
const content = await fs.readFile(wroteFile, "utf-8");
|
|
678
|
+
await Promise.all(dirs.map(async (dir) => {
|
|
679
|
+
const filePath = resolve3(dir, relativePath);
|
|
680
|
+
await fs.mkdir(dirname3(filePath), { recursive: true });
|
|
681
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
682
|
+
}));
|
|
683
|
+
});
|
|
684
|
+
}
|
|
667
685
|
if (typeof afterBuild === "function") {
|
|
668
686
|
const result = afterBuild();
|
|
669
687
|
isPromise(result) && await result;
|
package/package.json
CHANGED