vite-plugin-dts 1.6.1 → 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.cjs +831 -0
- package/dist/index.js +103 -123
- package/package.json +18 -14
package/dist/index.js
CHANGED
|
@@ -1,54 +1,29 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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 ?
|
|
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
|
|
96
|
+
return dirname(paths[0]);
|
|
122
97
|
}
|
|
123
|
-
let publicPath =
|
|
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 =
|
|
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(
|
|
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 (!
|
|
130
|
+
if (!existsSync(dir)) {
|
|
156
131
|
return;
|
|
157
132
|
}
|
|
158
133
|
let onlyHasDir = true;
|
|
159
|
-
for (const file of
|
|
160
|
-
const abs =
|
|
161
|
-
if (
|
|
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
|
-
|
|
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 = (
|
|
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(
|
|
@@ -283,16 +258,16 @@ function requireCompiler() {
|
|
|
283
258
|
if (!compiler) {
|
|
284
259
|
if (compileRoot) {
|
|
285
260
|
try {
|
|
286
|
-
compiler =
|
|
261
|
+
compiler = __require(__require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
|
|
287
262
|
} catch (e) {
|
|
288
263
|
}
|
|
289
264
|
}
|
|
290
265
|
if (!compiler) {
|
|
291
266
|
try {
|
|
292
|
-
compiler =
|
|
267
|
+
compiler = __require("vue/compiler-sfc");
|
|
293
268
|
} catch (e) {
|
|
294
269
|
try {
|
|
295
|
-
compiler =
|
|
270
|
+
compiler = __require("@vue/compiler-sfc");
|
|
296
271
|
} catch (e2) {
|
|
297
272
|
throw new Error("@vue/compiler-sfc is not present in the dependency tree.\n");
|
|
298
273
|
}
|
|
@@ -305,13 +280,13 @@ function isVue3() {
|
|
|
305
280
|
if (!vue) {
|
|
306
281
|
if (compileRoot) {
|
|
307
282
|
try {
|
|
308
|
-
vue =
|
|
283
|
+
vue = __require(__require.resolve("vue", { paths: [compileRoot] }));
|
|
309
284
|
} catch (e) {
|
|
310
285
|
}
|
|
311
286
|
}
|
|
312
287
|
if (!vue) {
|
|
313
288
|
try {
|
|
314
|
-
vue =
|
|
289
|
+
vue = __require("vue");
|
|
315
290
|
} catch (e) {
|
|
316
291
|
throw new Error("vue is not present in the dependency tree.\n");
|
|
317
292
|
}
|
|
@@ -381,12 +356,15 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
381
356
|
}
|
|
382
357
|
|
|
383
358
|
// src/rollup.ts
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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";
|
|
390
368
|
var dtsRE = /\.d\.tsx?$/;
|
|
391
369
|
function rollupDeclarationFiles({
|
|
392
370
|
root,
|
|
@@ -396,13 +374,13 @@ function rollupDeclarationFiles({
|
|
|
396
374
|
fileName,
|
|
397
375
|
compilerOptions
|
|
398
376
|
}) {
|
|
399
|
-
const configObjectFullPath = (
|
|
400
|
-
const packageJsonLookup = new
|
|
377
|
+
const configObjectFullPath = resolve2(root, "api-extractor.json");
|
|
378
|
+
const packageJsonLookup = new PackageJsonLookup();
|
|
401
379
|
const packageJsonFullPath = packageJsonLookup.tryGetPackageJsonFilePathFor(configObjectFullPath);
|
|
402
380
|
if (!dtsRE.test(fileName)) {
|
|
403
381
|
fileName += ".d.ts";
|
|
404
382
|
}
|
|
405
|
-
const extractorConfig =
|
|
383
|
+
const extractorConfig = ExtractorConfig.prepare({
|
|
406
384
|
configObject: {
|
|
407
385
|
projectFolder: root,
|
|
408
386
|
mainEntryPointFilePath: entryPath,
|
|
@@ -419,7 +397,7 @@ function rollupDeclarationFiles({
|
|
|
419
397
|
},
|
|
420
398
|
dtsRollup: {
|
|
421
399
|
enabled: true,
|
|
422
|
-
publicTrimmedFilePath: (
|
|
400
|
+
publicTrimmedFilePath: resolve2(outputDir, fileName)
|
|
423
401
|
},
|
|
424
402
|
tsdocMetadata: {
|
|
425
403
|
enabled: false
|
|
@@ -440,11 +418,11 @@ function rollupDeclarationFiles({
|
|
|
440
418
|
configObjectFullPath,
|
|
441
419
|
packageJsonFullPath
|
|
442
420
|
});
|
|
443
|
-
const compilerState =
|
|
421
|
+
const compilerState = CompilerState.create(extractorConfig, {
|
|
444
422
|
localBuild: true,
|
|
445
423
|
showVerboseMessages: false
|
|
446
424
|
});
|
|
447
|
-
const messageRouter = new
|
|
425
|
+
const messageRouter = new MessageRouter({
|
|
448
426
|
workingPackageFolder: root,
|
|
449
427
|
messageCallback: void 0,
|
|
450
428
|
messagesConfig: extractorConfig.messages,
|
|
@@ -452,16 +430,16 @@ function rollupDeclarationFiles({
|
|
|
452
430
|
showDiagnostics: false,
|
|
453
431
|
tsdocConfiguration: extractorConfig.tsdocConfiguration
|
|
454
432
|
});
|
|
455
|
-
const collector = new
|
|
433
|
+
const collector = new Collector({
|
|
456
434
|
program: compilerState.program,
|
|
457
435
|
messageRouter,
|
|
458
436
|
extractorConfig
|
|
459
437
|
});
|
|
460
438
|
collector.analyze();
|
|
461
|
-
|
|
439
|
+
DtsRollupGenerator.writeTypingsFile(
|
|
462
440
|
collector,
|
|
463
441
|
extractorConfig.publicTrimmedFilePath,
|
|
464
|
-
|
|
442
|
+
DtsRollupKind.PublicRelease,
|
|
465
443
|
extractorConfig.newlineKind
|
|
466
444
|
);
|
|
467
445
|
}
|
|
@@ -479,8 +457,8 @@ var fullRelativeRE = /^\.\.?\//;
|
|
|
479
457
|
var defaultIndex = "index.d.ts";
|
|
480
458
|
var noop = () => {
|
|
481
459
|
};
|
|
482
|
-
var logPrefix =
|
|
483
|
-
var bundleDebug =
|
|
460
|
+
var logPrefix = chalk.cyan("[vite:dts]");
|
|
461
|
+
var bundleDebug = debug("vite-plugin-dts:bundle");
|
|
484
462
|
function dtsPlugin(options = {}) {
|
|
485
463
|
const {
|
|
486
464
|
tsConfigFilePath = "tsconfig.json",
|
|
@@ -546,9 +524,9 @@ function dtsPlugin(options = {}) {
|
|
|
546
524
|
logger = config.logger;
|
|
547
525
|
if (!config.build.lib) {
|
|
548
526
|
logger.warn(
|
|
549
|
-
|
|
527
|
+
chalk.yellow(
|
|
550
528
|
`
|
|
551
|
-
${
|
|
529
|
+
${chalk.cyan(
|
|
552
530
|
"[vite:dts]"
|
|
553
531
|
)} You building not a library that may not need to generate declaration files.
|
|
554
532
|
`
|
|
@@ -569,9 +547,9 @@ ${import_chalk.default.cyan(
|
|
|
569
547
|
outputDirs = options.outputDir ? ensureArray(options.outputDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(config.build.outDir, root)];
|
|
570
548
|
if (!outputDirs[0]) {
|
|
571
549
|
logger.error(
|
|
572
|
-
|
|
550
|
+
chalk.red(
|
|
573
551
|
`
|
|
574
|
-
${
|
|
552
|
+
${chalk.cyan(
|
|
575
553
|
"[vite:dts]"
|
|
576
554
|
)} Can not resolve declaration directory, please check your vite config and plugin options.
|
|
577
555
|
`
|
|
@@ -581,7 +559,7 @@ ${import_chalk.default.cyan(
|
|
|
581
559
|
}
|
|
582
560
|
setCompileRoot(root);
|
|
583
561
|
compilerOptions.rootDir || (compilerOptions.rootDir = root);
|
|
584
|
-
project = new
|
|
562
|
+
project = new Project({
|
|
585
563
|
compilerOptions: mergeObjects(compilerOptions, {
|
|
586
564
|
noEmitOnError,
|
|
587
565
|
outDir: ".",
|
|
@@ -621,7 +599,7 @@ ${import_chalk.default.cyan(
|
|
|
621
599
|
if (watchExtensionRE.test(id)) {
|
|
622
600
|
isBundle = false;
|
|
623
601
|
if (project) {
|
|
624
|
-
const sourceFile = project.getSourceFile((
|
|
602
|
+
const sourceFile = project.getSourceFile(normalizePath2(id));
|
|
625
603
|
sourceFile && project.removeSourceFile(sourceFile);
|
|
626
604
|
}
|
|
627
605
|
}
|
|
@@ -629,21 +607,21 @@ ${import_chalk.default.cyan(
|
|
|
629
607
|
async closeBundle() {
|
|
630
608
|
if (!outputDirs || !project || isBundle)
|
|
631
609
|
return;
|
|
632
|
-
logger.info(
|
|
610
|
+
logger.info(chalk.green(`
|
|
633
611
|
${logPrefix} Start generate declaration files...`));
|
|
634
612
|
bundleDebug("start");
|
|
635
613
|
isBundle = true;
|
|
636
614
|
sourceDtsFiles.clear();
|
|
637
615
|
const startTime = Date.now();
|
|
638
|
-
const tsConfig =
|
|
616
|
+
const tsConfig = readConfigFile(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
|
|
639
617
|
const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
|
|
640
|
-
const parentTsConfig = parentTsConfigPath ?
|
|
618
|
+
const parentTsConfig = parentTsConfigPath ? readConfigFile(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
|
|
641
619
|
const include = options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*";
|
|
642
620
|
const exclude = options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**";
|
|
643
621
|
bundleDebug("read config");
|
|
644
622
|
const includedFileSet = /* @__PURE__ */ new Set();
|
|
645
623
|
if (include && include.length) {
|
|
646
|
-
const files = await (
|
|
624
|
+
const files = await glob(ensureArray(include).map(normalizeGlob), {
|
|
647
625
|
cwd: root,
|
|
648
626
|
absolute: true,
|
|
649
627
|
ignore: ensureArray(exclude).map(normalizeGlob)
|
|
@@ -662,8 +640,8 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
662
640
|
if (hasJsVue) {
|
|
663
641
|
if (!allowJs) {
|
|
664
642
|
logger.warn(
|
|
665
|
-
|
|
666
|
-
`${
|
|
643
|
+
chalk.yellow(
|
|
644
|
+
`${chalk.cyan(
|
|
667
645
|
"[vite:dts]"
|
|
668
646
|
)} Some js files are referenced, but you may not enable the 'allowJs' option.`
|
|
669
647
|
)
|
|
@@ -673,6 +651,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
673
651
|
}
|
|
674
652
|
bundleDebug("collect files");
|
|
675
653
|
}
|
|
654
|
+
project.resolveSourceFileDependencies();
|
|
676
655
|
bundleDebug("resolve");
|
|
677
656
|
if (!skipDiagnostics) {
|
|
678
657
|
const diagnostics = project.getPreEmitDiagnostics();
|
|
@@ -692,7 +671,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
692
671
|
const service = project.getLanguageService();
|
|
693
672
|
const outputFiles = project.getSourceFiles().map(
|
|
694
673
|
(sourceFile) => service.getEmitOutput(sourceFile, true).getOutputFiles().map((outputFile) => ({
|
|
695
|
-
path: (
|
|
674
|
+
path: normalizePath2(resolve3(root, outputFile.compilerObject.name)),
|
|
696
675
|
content: outputFile.getText()
|
|
697
676
|
}))
|
|
698
677
|
).flat().concat(dtsOutputFiles);
|
|
@@ -703,7 +682,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
703
682
|
entryRoot = ensureAbsolute(entryRoot, root);
|
|
704
683
|
const wroteFiles = /* @__PURE__ */ new Set();
|
|
705
684
|
const outputDir = outputDirs[0];
|
|
706
|
-
await runParallel(
|
|
685
|
+
await runParallel(os.cpus().length, outputFiles, async (outputFile) => {
|
|
707
686
|
let filePath = outputFile.path;
|
|
708
687
|
let content = outputFile.content;
|
|
709
688
|
const isMapFile = filePath.endsWith(".map");
|
|
@@ -715,9 +694,9 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
715
694
|
content = transformAliasImport(filePath, content, aliases, aliasesExclude);
|
|
716
695
|
content = staticImport || rollupTypes ? transformDynamicImport(content) : content;
|
|
717
696
|
}
|
|
718
|
-
filePath = (
|
|
697
|
+
filePath = resolve3(
|
|
719
698
|
outputDir,
|
|
720
|
-
(
|
|
699
|
+
relative2(entryRoot, cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath)
|
|
721
700
|
);
|
|
722
701
|
if (typeof beforeWriteFile === "function") {
|
|
723
702
|
const result = beforeWriteFile(filePath, content);
|
|
@@ -728,30 +707,30 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
728
707
|
content = result.content ?? content;
|
|
729
708
|
}
|
|
730
709
|
}
|
|
731
|
-
await
|
|
732
|
-
await
|
|
710
|
+
await fs.mkdir(dirname3(filePath), { recursive: true });
|
|
711
|
+
await fs.writeFile(
|
|
733
712
|
filePath,
|
|
734
713
|
cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content,
|
|
735
714
|
"utf-8"
|
|
736
715
|
);
|
|
737
|
-
wroteFiles.add((
|
|
716
|
+
wroteFiles.add(normalizePath2(filePath));
|
|
738
717
|
});
|
|
739
718
|
bundleDebug("output");
|
|
740
719
|
if (insertTypesEntry || rollupTypes) {
|
|
741
|
-
const pkgPath = (
|
|
742
|
-
const pkg =
|
|
720
|
+
const pkgPath = resolve3(root, "package.json");
|
|
721
|
+
const pkg = fs.existsSync(pkgPath) ? JSON.parse(await fs.readFile(pkgPath, "utf-8")) : {};
|
|
743
722
|
const types = pkg.types || pkg.typings;
|
|
744
|
-
let typesPath = types ? (
|
|
745
|
-
if (!
|
|
723
|
+
let typesPath = types ? resolve3(root, types) : resolve3(outputDir, indexName);
|
|
724
|
+
if (!fs.existsSync(typesPath)) {
|
|
746
725
|
const entry = entries[0];
|
|
747
|
-
const outputIndex = (
|
|
748
|
-
let filePath = (
|
|
726
|
+
const outputIndex = resolve3(outputDir, relative2(entryRoot, entry.replace(tsRE, ".d.ts")));
|
|
727
|
+
let filePath = normalizePath2(relative2(dirname3(typesPath), outputIndex));
|
|
749
728
|
filePath = filePath.replace(dtsRE2, "");
|
|
750
729
|
filePath = fullRelativeRE.test(filePath) ? filePath : `./${filePath}`;
|
|
751
730
|
let content = `export * from '${filePath}'
|
|
752
731
|
`;
|
|
753
|
-
if (
|
|
754
|
-
const entryCodes = await
|
|
732
|
+
if (fs.existsSync(outputIndex)) {
|
|
733
|
+
const entryCodes = await fs.readFile(outputIndex, "utf-8");
|
|
755
734
|
if (entryCodes.includes("export default")) {
|
|
756
735
|
content += `import ${libName} from '${filePath}'
|
|
757
736
|
export default ${libName}
|
|
@@ -767,32 +746,32 @@ export default ${libName}
|
|
|
767
746
|
}
|
|
768
747
|
}
|
|
769
748
|
if (result !== false) {
|
|
770
|
-
await
|
|
771
|
-
wroteFiles.add((
|
|
749
|
+
await fs.writeFile(typesPath, content, "utf-8");
|
|
750
|
+
wroteFiles.add(normalizePath2(typesPath));
|
|
772
751
|
}
|
|
773
752
|
}
|
|
774
753
|
bundleDebug("insert index");
|
|
775
754
|
if (rollupTypes) {
|
|
776
|
-
logger.info(
|
|
755
|
+
logger.info(chalk.green(`${logPrefix} Start rollup declaration files...`));
|
|
777
756
|
rollupDeclarationFiles({
|
|
778
757
|
root,
|
|
779
758
|
tsConfigPath,
|
|
780
759
|
compilerOptions,
|
|
781
760
|
outputDir,
|
|
782
761
|
entryPath: typesPath,
|
|
783
|
-
fileName:
|
|
762
|
+
fileName: basename(typesPath)
|
|
784
763
|
});
|
|
785
|
-
const wroteFile = (
|
|
764
|
+
const wroteFile = normalizePath2(typesPath);
|
|
786
765
|
wroteFiles.delete(wroteFile);
|
|
787
|
-
await runParallel(
|
|
766
|
+
await runParallel(os.cpus().length, Array.from(wroteFiles), (f) => fs.unlink(f));
|
|
788
767
|
removeDirIfEmpty(outputDir);
|
|
789
768
|
wroteFiles.clear();
|
|
790
769
|
wroteFiles.add(wroteFile);
|
|
791
770
|
if (copyDtsFiles) {
|
|
792
|
-
await runParallel(
|
|
793
|
-
const filePath = (
|
|
794
|
-
await
|
|
795
|
-
wroteFiles.add((
|
|
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));
|
|
796
775
|
});
|
|
797
776
|
}
|
|
798
777
|
bundleDebug("rollup");
|
|
@@ -800,14 +779,14 @@ export default ${libName}
|
|
|
800
779
|
}
|
|
801
780
|
if (outputDirs.length > 1) {
|
|
802
781
|
const dirs = outputDirs.slice(1);
|
|
803
|
-
await runParallel(
|
|
804
|
-
const relativePath = (
|
|
805
|
-
const content = await
|
|
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");
|
|
806
785
|
await Promise.all(
|
|
807
786
|
dirs.map(async (dir) => {
|
|
808
|
-
const filePath = (
|
|
809
|
-
await
|
|
810
|
-
await
|
|
787
|
+
const filePath = resolve3(dir, relativePath);
|
|
788
|
+
await fs.mkdir(dirname3(filePath), { recursive: true });
|
|
789
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
811
790
|
})
|
|
812
791
|
);
|
|
813
792
|
});
|
|
@@ -818,7 +797,7 @@ export default ${libName}
|
|
|
818
797
|
}
|
|
819
798
|
bundleDebug("finish");
|
|
820
799
|
logger.info(
|
|
821
|
-
|
|
800
|
+
chalk.green(`${logPrefix} Declaration files built in ${Date.now() - startTime}ms.
|
|
822
801
|
`)
|
|
823
802
|
);
|
|
824
803
|
}
|
|
@@ -827,5 +806,6 @@ export default ${libName}
|
|
|
827
806
|
|
|
828
807
|
// src/index.ts
|
|
829
808
|
var src_default = dtsPlugin;
|
|
830
|
-
|
|
831
|
-
|
|
809
|
+
export {
|
|
810
|
+
src_default as default
|
|
811
|
+
};
|
package/package.json
CHANGED
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
"url": "https://github.com/qmhc/vite-plugin-dts/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@microsoft/api-extractor": "^7.
|
|
10
|
-
"@rushstack/node-core-library": "^3.
|
|
9
|
+
"@microsoft/api-extractor": "^7.32.0",
|
|
10
|
+
"@rushstack/node-core-library": "^3.53.0",
|
|
11
11
|
"chalk": "^4.1.2",
|
|
12
12
|
"debug": "^4.3.4",
|
|
13
13
|
"fast-glob": "^3.2.12",
|
|
14
14
|
"fs-extra": "^10.1.0",
|
|
15
|
+
"kolorist": "^1.6.0",
|
|
15
16
|
"ts-morph": "^16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
@@ -19,8 +20,10 @@
|
|
|
19
20
|
"@commitlint/config-conventional": "^17.1.0",
|
|
20
21
|
"@types/debug": "^4.1.7",
|
|
21
22
|
"@types/fs-extra": "^9.0.13",
|
|
22
|
-
"@types/
|
|
23
|
+
"@types/minimist": "^1.2.2",
|
|
23
24
|
"@types/node": "^18.7.23",
|
|
25
|
+
"@types/prompts": "^2.0.14",
|
|
26
|
+
"@types/semver": "^7.3.12",
|
|
24
27
|
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
|
25
28
|
"@typescript-eslint/parser": "^5.38.1",
|
|
26
29
|
"@vitejs/plugin-vue": "^3.1.0",
|
|
@@ -30,31 +33,31 @@
|
|
|
30
33
|
"conventional-changelog-cli": "^2.2.2",
|
|
31
34
|
"cross-env": "^7.0.3",
|
|
32
35
|
"cz-customizable": "^7.0.0",
|
|
33
|
-
"enquirer": "^2.3.6",
|
|
34
36
|
"eslint": "^8.24.0",
|
|
35
37
|
"eslint-plugin-import": "^2.26.0",
|
|
36
38
|
"eslint-plugin-node": "^11.1.0",
|
|
37
39
|
"eslint-plugin-promise": "^6.0.1",
|
|
38
40
|
"eslint-plugin-vue": "^9.5.1",
|
|
39
|
-
"execa": "^
|
|
41
|
+
"execa": "^6.1.0",
|
|
40
42
|
"husky": "^8.0.1",
|
|
41
43
|
"is-ci": "^3.0.1",
|
|
42
|
-
"jest": "^29.0.3",
|
|
43
44
|
"lint-staged": "^13.0.3",
|
|
44
45
|
"minimist": "^1.2.6",
|
|
45
46
|
"pinst": "^3.0.0",
|
|
46
47
|
"prettier": "^2.7.1",
|
|
47
48
|
"pretty-quick": "^3.1.3",
|
|
49
|
+
"prompts": "^2.4.2",
|
|
48
50
|
"rimraf": "^3.0.2",
|
|
49
51
|
"semver": "^7.3.7",
|
|
50
|
-
"ts-
|
|
52
|
+
"ts-node": "^10.9.1",
|
|
51
53
|
"tsup": "^6.2.3",
|
|
52
54
|
"typescript": "4.7.4",
|
|
53
|
-
"vite": "^3.1.
|
|
55
|
+
"vite": "^3.1.4",
|
|
56
|
+
"vitest": "^0.23.4",
|
|
54
57
|
"vue": "3.2.40"
|
|
55
58
|
},
|
|
56
59
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
60
|
+
"node": "^14.18.0 || >=16.0.0"
|
|
58
61
|
},
|
|
59
62
|
"files": [
|
|
60
63
|
"dist"
|
|
@@ -71,14 +74,14 @@
|
|
|
71
74
|
"module": "dist/index.mjs",
|
|
72
75
|
"name": "vite-plugin-dts",
|
|
73
76
|
"peerDependencies": {
|
|
74
|
-
"vite": ">=
|
|
77
|
+
"vite": ">=2.9.0"
|
|
75
78
|
},
|
|
76
79
|
"repository": {
|
|
77
80
|
"type": "git",
|
|
78
81
|
"url": "git+https://github.com/qmhc/vite-plugin-dts.git"
|
|
79
82
|
},
|
|
80
83
|
"scripts": {
|
|
81
|
-
"build": "node scripts/build.
|
|
84
|
+
"build": "ts-node --esm scripts/build.ts",
|
|
82
85
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
|
|
83
86
|
"dev": "pnpm run build -- --watch",
|
|
84
87
|
"lint": "pnpm run lint:src && pnpm run lint:example",
|
|
@@ -89,10 +92,11 @@
|
|
|
89
92
|
"precommit": "lint-staged -c ./.husky/.lintstagedrc -q",
|
|
90
93
|
"prepublishOnly": "pinst --disable",
|
|
91
94
|
"prettier": "pretty-quick --staged",
|
|
92
|
-
"release": "node scripts/release.
|
|
93
|
-
"test": "
|
|
95
|
+
"release": "ts-node --esm scripts/release.ts",
|
|
96
|
+
"test": "vitest run",
|
|
94
97
|
"test:e2e": "pnpm -C example build"
|
|
95
98
|
},
|
|
99
|
+
"type": "module",
|
|
96
100
|
"types": "dist/index.d.ts",
|
|
97
|
-
"version": "1.6.
|
|
101
|
+
"version": "1.6.2"
|
|
98
102
|
}
|