vite-plugin-dts 1.4.1 → 1.6.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/README.md +213 -208
- package/README.zh-CN.md +212 -207
- package/dist/index.d.ts +3 -3
- package/dist/index.js +132 -63
- package/dist/index.mjs +126 -70
- package/package.json +35 -34
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -16,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
}
|
|
17
18
|
return to;
|
|
18
19
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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
|
+
));
|
|
20
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
25
|
|
|
22
26
|
// src/index.ts
|
|
@@ -184,20 +188,25 @@ var importTypesRE = /import\s?(?:type)?\s?\{(.+)\}\s?from\s?['"].+['"]/;
|
|
|
184
188
|
function transformDynamicImport(content) {
|
|
185
189
|
const importMap = /* @__PURE__ */ new Map();
|
|
186
190
|
content = content.replace(globalDynamicTypeRE, (str) => {
|
|
187
|
-
var _a;
|
|
188
191
|
const matchResult = str.match(dynamicTypeRE);
|
|
189
192
|
const libName = matchResult[1];
|
|
190
|
-
const importSet =
|
|
193
|
+
const importSet = importMap.get(libName) ?? importMap.set(libName, /* @__PURE__ */ new Set()).get(libName);
|
|
191
194
|
const usedType = matchResult[2];
|
|
192
195
|
importSet.add(usedType);
|
|
193
196
|
return usedType + matchResult[3];
|
|
194
197
|
});
|
|
195
198
|
importMap.forEach((importSet, libName) => {
|
|
196
|
-
const importReg = new RegExp(
|
|
199
|
+
const importReg = new RegExp(
|
|
200
|
+
`import\\s?(?:type)?\\s?\\{[^;\\n]+\\}\\s?from\\s?['"]${libName}['"]`,
|
|
201
|
+
"g"
|
|
202
|
+
);
|
|
197
203
|
const matchResult = content.match(importReg);
|
|
198
204
|
if (matchResult == null ? void 0 : matchResult[0]) {
|
|
199
205
|
const importedTypes = matchResult[0].match(importTypesRE)[1].trim().split(",");
|
|
200
|
-
content = content.replace(
|
|
206
|
+
content = content.replace(
|
|
207
|
+
matchResult[0],
|
|
208
|
+
`import type { ${Array.from(importSet).concat(importedTypes).join(", ")} } from '${libName}'`
|
|
209
|
+
);
|
|
201
210
|
} else {
|
|
202
211
|
content = `import type { ${Array.from(importSet).join(", ")} } from '${libName}';
|
|
203
212
|
` + content;
|
|
@@ -219,7 +228,7 @@ var staticImportRE = /(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)
|
|
|
219
228
|
var dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
|
|
220
229
|
var simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
|
|
221
230
|
var simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
|
|
222
|
-
function transformAliasImport(filePath, content, aliases) {
|
|
231
|
+
function transformAliasImport(filePath, content, aliases, exclude = []) {
|
|
223
232
|
if (!aliases.length)
|
|
224
233
|
return content;
|
|
225
234
|
return content.replace(globalImportRE, (str) => {
|
|
@@ -232,8 +241,17 @@ function transformAliasImport(filePath, content, aliases) {
|
|
|
232
241
|
if (matchResult == null ? void 0 : matchResult[1]) {
|
|
233
242
|
const matchedAlias = aliases.find((alias) => isAliasMatch(alias, matchResult[1]));
|
|
234
243
|
if (matchedAlias) {
|
|
244
|
+
if (exclude.some((e) => isRegExp(e) ? e.test(matchResult[1]) : String(e) === matchResult[1])) {
|
|
245
|
+
return str;
|
|
246
|
+
}
|
|
235
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);
|
|
236
|
-
return str.replace(
|
|
248
|
+
return str.replace(
|
|
249
|
+
isDynamic ? simpleDynamicImportRE : simpleStaticImportRE,
|
|
250
|
+
`$1'${matchResult[1].replace(
|
|
251
|
+
matchedAlias.find,
|
|
252
|
+
(truthPath.startsWith(".") ? truthPath : `./${truthPath}`) + (typeof matchedAlias.find === "string" && matchedAlias.find.endsWith("/") ? "/" : "")
|
|
253
|
+
)}'${isDynamic ? ")" : ""}`
|
|
254
|
+
);
|
|
237
255
|
}
|
|
238
256
|
}
|
|
239
257
|
return str;
|
|
@@ -254,6 +272,8 @@ function transferSetupPosition(content) {
|
|
|
254
272
|
}
|
|
255
273
|
|
|
256
274
|
// src/compile.ts
|
|
275
|
+
var import_node_module = require("module");
|
|
276
|
+
var import_meta = {};
|
|
257
277
|
var exportDefaultRE = /export\s+default/;
|
|
258
278
|
var exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
259
279
|
var noScriptContent = "import { defineComponent } from 'vue'\nexport default defineComponent({})";
|
|
@@ -261,20 +281,21 @@ var index = 1;
|
|
|
261
281
|
var compileRoot = null;
|
|
262
282
|
var compiler;
|
|
263
283
|
var vue;
|
|
284
|
+
var _require = (0, import_node_module.createRequire)(import_meta.url);
|
|
264
285
|
function requireCompiler() {
|
|
265
286
|
if (!compiler) {
|
|
266
287
|
if (compileRoot) {
|
|
267
288
|
try {
|
|
268
|
-
compiler =
|
|
289
|
+
compiler = _require(_require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
|
|
269
290
|
} catch (e) {
|
|
270
291
|
}
|
|
271
292
|
}
|
|
272
293
|
if (!compiler) {
|
|
273
294
|
try {
|
|
274
|
-
compiler =
|
|
295
|
+
compiler = _require("vue/compiler-sfc");
|
|
275
296
|
} catch (e) {
|
|
276
297
|
try {
|
|
277
|
-
compiler =
|
|
298
|
+
compiler = _require("@vue/compiler-sfc");
|
|
278
299
|
} catch (e2) {
|
|
279
300
|
throw new Error("@vue/compiler-sfc is not present in the dependency tree.\n");
|
|
280
301
|
}
|
|
@@ -287,13 +308,13 @@ function isVue3() {
|
|
|
287
308
|
if (!vue) {
|
|
288
309
|
if (compileRoot) {
|
|
289
310
|
try {
|
|
290
|
-
vue =
|
|
311
|
+
vue = _require(_require.resolve("vue", { paths: [compileRoot] }));
|
|
291
312
|
} catch (e) {
|
|
292
313
|
}
|
|
293
314
|
}
|
|
294
315
|
if (!vue) {
|
|
295
316
|
try {
|
|
296
|
-
vue =
|
|
317
|
+
vue = _require("vue");
|
|
297
318
|
} catch (e) {
|
|
298
319
|
throw new Error("vue is not present in the dependency tree.\n");
|
|
299
320
|
}
|
|
@@ -329,7 +350,7 @@ function compileVueCode(code) {
|
|
|
329
350
|
id: `${index++}`
|
|
330
351
|
});
|
|
331
352
|
const classMatch = compiled.content.match(exportDefaultClassRE);
|
|
332
|
-
const plugins = scriptSetup.lang === "ts" ? ["typescript"] : void 0;
|
|
353
|
+
const plugins = scriptSetup.lang === "ts" ? ["typescript", "decorators-legacy"] : void 0;
|
|
333
354
|
if (classMatch) {
|
|
334
355
|
content = compiled.content.replace(exportDefaultClassRE, "\nclass $1") + `
|
|
335
356
|
const _sfc_main = ${classMatch[1]}`;
|
|
@@ -340,10 +361,18 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
340
361
|
content = rewriteDefault(compiled.content, "_sfc_main", plugins);
|
|
341
362
|
}
|
|
342
363
|
content = transferSetupPosition(content);
|
|
364
|
+
content = content.replace(/(const __returned__\s?=\s?\{[\s\S]+?)(props)(\s?\})/, "$1props: props as any$3").replace(
|
|
365
|
+
/(const __returned__\s?=\s?\{[\s\S]+?)(props,)([\s\S]+?)/,
|
|
366
|
+
"$1props: props as any,$3"
|
|
367
|
+
);
|
|
343
368
|
content += "\nexport default _sfc_main\n";
|
|
344
369
|
ext = scriptSetup.lang || "js";
|
|
345
370
|
} else if (script && script.content) {
|
|
346
|
-
content = rewriteDefault(
|
|
371
|
+
content = rewriteDefault(
|
|
372
|
+
script.content,
|
|
373
|
+
"_sfc_main",
|
|
374
|
+
script.lang === "ts" ? ["typescript"] : void 0
|
|
375
|
+
);
|
|
347
376
|
content += "\nexport default _sfc_main\n";
|
|
348
377
|
ext = script.lang || "js";
|
|
349
378
|
}
|
|
@@ -432,7 +461,12 @@ function rollupDeclarationFiles({
|
|
|
432
461
|
extractorConfig
|
|
433
462
|
});
|
|
434
463
|
collector.analyze();
|
|
435
|
-
import_DtsRollupGenerator.DtsRollupGenerator.writeTypingsFile(
|
|
464
|
+
import_DtsRollupGenerator.DtsRollupGenerator.writeTypingsFile(
|
|
465
|
+
collector,
|
|
466
|
+
extractorConfig.publicTrimmedFilePath,
|
|
467
|
+
import_DtsRollupGenerator.DtsRollupKind.PublicRelease,
|
|
468
|
+
extractorConfig.newlineKind
|
|
469
|
+
);
|
|
436
470
|
}
|
|
437
471
|
|
|
438
472
|
// src/plugin.ts
|
|
@@ -451,7 +485,6 @@ var noop = () => {
|
|
|
451
485
|
var logPrefix = import_chalk.default.cyan("[vite:dts]");
|
|
452
486
|
var bundleDebug = (0, import_debug.debug)("vite-plugin-dts:bundle");
|
|
453
487
|
function dtsPlugin(options = {}) {
|
|
454
|
-
var _a, _b;
|
|
455
488
|
const {
|
|
456
489
|
tsConfigFilePath = "tsconfig.json",
|
|
457
490
|
aliasesExclude = [],
|
|
@@ -468,9 +501,9 @@ function dtsPlugin(options = {}) {
|
|
|
468
501
|
beforeWriteFile = noop,
|
|
469
502
|
afterBuild = noop
|
|
470
503
|
} = options;
|
|
471
|
-
const compilerOptions =
|
|
504
|
+
const compilerOptions = options.compilerOptions ?? {};
|
|
472
505
|
let root;
|
|
473
|
-
let entryRoot =
|
|
506
|
+
let entryRoot = options.entryRoot ?? "";
|
|
474
507
|
let libName;
|
|
475
508
|
let indexName;
|
|
476
509
|
let aliases;
|
|
@@ -488,10 +521,10 @@ function dtsPlugin(options = {}) {
|
|
|
488
521
|
apply: "build",
|
|
489
522
|
enforce: "pre",
|
|
490
523
|
config(config) {
|
|
491
|
-
var
|
|
524
|
+
var _a;
|
|
492
525
|
if (isBundle)
|
|
493
526
|
return;
|
|
494
|
-
const aliasOptions = (
|
|
527
|
+
const aliasOptions = ((_a = config == null ? void 0 : config.resolve) == null ? void 0 : _a.alias) ?? [];
|
|
495
528
|
if (isNativeObj(aliasOptions)) {
|
|
496
529
|
aliases = Object.entries(aliasOptions).map(([key, value]) => {
|
|
497
530
|
return { find: key, replacement: value };
|
|
@@ -500,38 +533,53 @@ function dtsPlugin(options = {}) {
|
|
|
500
533
|
aliases = ensureArray(aliasOptions);
|
|
501
534
|
}
|
|
502
535
|
if (aliasesExclude.length > 0) {
|
|
503
|
-
aliases = aliases.filter(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
536
|
+
aliases = aliases.filter(
|
|
537
|
+
({ find }) => !aliasesExclude.some(
|
|
538
|
+
(alias) => {
|
|
539
|
+
var _a2;
|
|
540
|
+
return alias && (isRegExp(find) ? find.toString() === alias.toString() : isRegExp(alias) ? (_a2 = find.match(alias)) == null ? void 0 : _a2[0] : find === alias);
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
);
|
|
507
544
|
}
|
|
508
545
|
},
|
|
509
546
|
configResolved(config) {
|
|
510
|
-
var _a2, _b2, _c;
|
|
511
547
|
if (isBundle)
|
|
512
548
|
return;
|
|
513
549
|
logger = config.logger;
|
|
514
550
|
if (!config.build.lib) {
|
|
515
|
-
logger.warn(
|
|
516
|
-
|
|
517
|
-
`
|
|
551
|
+
logger.warn(
|
|
552
|
+
import_chalk.default.yellow(
|
|
553
|
+
`
|
|
554
|
+
${import_chalk.default.cyan(
|
|
555
|
+
"[vite:dts]"
|
|
556
|
+
)} You building not a library that may not need to generate declaration files.
|
|
557
|
+
`
|
|
558
|
+
)
|
|
559
|
+
);
|
|
518
560
|
libName = "_default";
|
|
519
561
|
indexName = defaultIndex;
|
|
520
562
|
} else {
|
|
521
|
-
const filename =
|
|
563
|
+
const filename = config.build.lib.fileName ?? defaultIndex;
|
|
522
564
|
libName = config.build.lib.name || "_default";
|
|
523
565
|
indexName = typeof filename === "string" ? filename : filename("es");
|
|
524
566
|
if (!dtsRE2.test(indexName)) {
|
|
525
567
|
indexName = `${tjsRE.test(indexName) ? indexName.replace(tjsRE, "") : indexName}.d.ts`;
|
|
526
568
|
}
|
|
527
569
|
}
|
|
528
|
-
root = ensureAbsolute(
|
|
570
|
+
root = ensureAbsolute(options.root ?? "", config.root);
|
|
529
571
|
tsConfigPath = ensureAbsolute(tsConfigFilePath, root);
|
|
530
572
|
outputDirs = options.outputDir ? ensureArray(options.outputDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(config.build.outDir, root)];
|
|
531
|
-
if (!outputDirs) {
|
|
532
|
-
logger.error(
|
|
533
|
-
|
|
534
|
-
`
|
|
573
|
+
if (!outputDirs[0]) {
|
|
574
|
+
logger.error(
|
|
575
|
+
import_chalk.default.red(
|
|
576
|
+
`
|
|
577
|
+
${import_chalk.default.cyan(
|
|
578
|
+
"[vite:dts]"
|
|
579
|
+
)} Can not resolve declaration directory, please check your vite config and plugin options.
|
|
580
|
+
`
|
|
581
|
+
)
|
|
582
|
+
);
|
|
535
583
|
return;
|
|
536
584
|
}
|
|
537
585
|
setCompileRoot(root);
|
|
@@ -549,7 +597,7 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
549
597
|
tsConfigFilePath: tsConfigPath,
|
|
550
598
|
skipAddingFilesFromTsConfig: true
|
|
551
599
|
});
|
|
552
|
-
allowJs =
|
|
600
|
+
allowJs = project.getCompilerOptions().allowJs ?? false;
|
|
553
601
|
},
|
|
554
602
|
buildStart(inputOptions) {
|
|
555
603
|
if (!isBundle && (insertTypesEntry || rollupTypes)) {
|
|
@@ -582,7 +630,6 @@ ${import_chalk.default.cyan("[vite:dts]")} Can not resolve declaration directory
|
|
|
582
630
|
}
|
|
583
631
|
},
|
|
584
632
|
async closeBundle() {
|
|
585
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
586
633
|
if (!outputDirs || !project || isBundle)
|
|
587
634
|
return;
|
|
588
635
|
logger.info(import_chalk.default.green(`
|
|
@@ -591,11 +638,11 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
591
638
|
isBundle = true;
|
|
592
639
|
sourceDtsFiles.clear();
|
|
593
640
|
const startTime = Date.now();
|
|
594
|
-
const tsConfig = (
|
|
641
|
+
const tsConfig = (0, import_typescript.readConfigFile)(tsConfigPath, project.getFileSystem().readFileSync).config ?? {};
|
|
595
642
|
const parentTsConfigPath = tsConfig.extends && ensureAbsolute(tsConfig.extends, root);
|
|
596
643
|
const parentTsConfig = parentTsConfigPath ? (0, import_typescript.readConfigFile)(parentTsConfigPath, project.getFileSystem().readFileSync).config : {};
|
|
597
|
-
const include =
|
|
598
|
-
const exclude =
|
|
644
|
+
const include = options.include ?? tsConfig.include ?? parentTsConfig.include ?? "**/*";
|
|
645
|
+
const exclude = options.exclude ?? tsConfig.exclude ?? parentTsConfig.exclude ?? "node_modules/**";
|
|
599
646
|
bundleDebug("read config");
|
|
600
647
|
const includedFileSet = /* @__PURE__ */ new Set();
|
|
601
648
|
if (include && include.length) {
|
|
@@ -617,13 +664,18 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
617
664
|
});
|
|
618
665
|
if (hasJsVue) {
|
|
619
666
|
if (!allowJs) {
|
|
620
|
-
logger.warn(
|
|
667
|
+
logger.warn(
|
|
668
|
+
import_chalk.default.yellow(
|
|
669
|
+
`${import_chalk.default.cyan(
|
|
670
|
+
"[vite:dts]"
|
|
671
|
+
)} Some js files are referenced, but you may not enable the 'allowJs' option.`
|
|
672
|
+
)
|
|
673
|
+
);
|
|
621
674
|
}
|
|
622
675
|
project.compilerOptions.set({ allowJs: true });
|
|
623
676
|
}
|
|
624
677
|
bundleDebug("collect files");
|
|
625
678
|
}
|
|
626
|
-
project.resolveSourceFileDependencies();
|
|
627
679
|
bundleDebug("resolve");
|
|
628
680
|
if (!skipDiagnostics) {
|
|
629
681
|
const diagnostics = project.getPreEmitDiagnostics();
|
|
@@ -641,10 +693,12 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
641
693
|
content: sourceFile.getFullText()
|
|
642
694
|
}));
|
|
643
695
|
const service = project.getLanguageService();
|
|
644
|
-
const outputFiles = project.getSourceFiles().map(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
696
|
+
const outputFiles = project.getSourceFiles().map(
|
|
697
|
+
(sourceFile) => service.getEmitOutput(sourceFile, true).getOutputFiles().map((outputFile) => ({
|
|
698
|
+
path: (0, import_vite2.normalizePath)((0, import_path4.resolve)(root, outputFile.compilerObject.name)),
|
|
699
|
+
content: outputFile.getText()
|
|
700
|
+
}))
|
|
701
|
+
).flat().concat(dtsOutputFiles);
|
|
648
702
|
bundleDebug("emit");
|
|
649
703
|
if (!entryRoot) {
|
|
650
704
|
entryRoot = queryPublicPath(outputFiles.map((file) => file.path));
|
|
@@ -653,7 +707,6 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
653
707
|
const wroteFiles = /* @__PURE__ */ new Set();
|
|
654
708
|
const outputDir = outputDirs[0];
|
|
655
709
|
await runParallel(import_os.default.cpus().length, outputFiles, async (outputFile) => {
|
|
656
|
-
var _a3, _b3;
|
|
657
710
|
let filePath = outputFile.path;
|
|
658
711
|
let content = outputFile.content;
|
|
659
712
|
const isMapFile = filePath.endsWith(".map");
|
|
@@ -662,19 +715,28 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
662
715
|
}
|
|
663
716
|
if (!isMapFile && content && content !== noneExport) {
|
|
664
717
|
content = clearPureImport ? removePureImport(content) : content;
|
|
665
|
-
content = transformAliasImport(filePath, content, aliases);
|
|
718
|
+
content = transformAliasImport(filePath, content, aliases, aliasesExclude);
|
|
666
719
|
content = staticImport || rollupTypes ? transformDynamicImport(content) : content;
|
|
667
720
|
}
|
|
668
|
-
filePath = (0, import_path4.resolve)(
|
|
721
|
+
filePath = (0, import_path4.resolve)(
|
|
722
|
+
outputDir,
|
|
723
|
+
(0, import_path4.relative)(entryRoot, cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath)
|
|
724
|
+
);
|
|
669
725
|
if (typeof beforeWriteFile === "function") {
|
|
670
726
|
const result = beforeWriteFile(filePath, content);
|
|
727
|
+
if (result === false)
|
|
728
|
+
return;
|
|
671
729
|
if (result && isNativeObj(result)) {
|
|
672
|
-
filePath =
|
|
673
|
-
content =
|
|
730
|
+
filePath = result.filePath ?? filePath;
|
|
731
|
+
content = result.content ?? content;
|
|
674
732
|
}
|
|
675
733
|
}
|
|
676
734
|
await import_fs_extra.default.mkdir((0, import_path4.dirname)(filePath), { recursive: true });
|
|
677
|
-
await import_fs_extra.default.writeFile(
|
|
735
|
+
await import_fs_extra.default.writeFile(
|
|
736
|
+
filePath,
|
|
737
|
+
cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content,
|
|
738
|
+
"utf-8"
|
|
739
|
+
);
|
|
678
740
|
wroteFiles.add((0, import_vite2.normalizePath)(filePath));
|
|
679
741
|
});
|
|
680
742
|
bundleDebug("output");
|
|
@@ -699,15 +761,18 @@ export default ${libName}
|
|
|
699
761
|
`;
|
|
700
762
|
}
|
|
701
763
|
}
|
|
764
|
+
let result;
|
|
702
765
|
if (typeof beforeWriteFile === "function") {
|
|
703
|
-
|
|
766
|
+
result = beforeWriteFile(typesPath, content);
|
|
704
767
|
if (result && isNativeObj(result)) {
|
|
705
|
-
typesPath =
|
|
706
|
-
content =
|
|
768
|
+
typesPath = result.filePath ?? typesPath;
|
|
769
|
+
content = result.content ?? content;
|
|
707
770
|
}
|
|
708
771
|
}
|
|
709
|
-
|
|
710
|
-
|
|
772
|
+
if (result !== false) {
|
|
773
|
+
await import_fs_extra.default.writeFile(typesPath, content, "utf-8");
|
|
774
|
+
wroteFiles.add((0, import_vite2.normalizePath)(typesPath));
|
|
775
|
+
}
|
|
711
776
|
}
|
|
712
777
|
bundleDebug("insert index");
|
|
713
778
|
if (rollupTypes) {
|
|
@@ -741,11 +806,13 @@ export default ${libName}
|
|
|
741
806
|
await runParallel(import_os.default.cpus().length, Array.from(wroteFiles), async (wroteFile) => {
|
|
742
807
|
const relativePath = (0, import_path4.relative)(outputDir, wroteFile);
|
|
743
808
|
const content = await import_fs_extra.default.readFile(wroteFile, "utf-8");
|
|
744
|
-
await Promise.all(
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
809
|
+
await Promise.all(
|
|
810
|
+
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");
|
|
814
|
+
})
|
|
815
|
+
);
|
|
749
816
|
});
|
|
750
817
|
}
|
|
751
818
|
if (typeof afterBuild === "function") {
|
|
@@ -753,8 +820,10 @@ export default ${libName}
|
|
|
753
820
|
isPromise(result) && await result;
|
|
754
821
|
}
|
|
755
822
|
bundleDebug("finish");
|
|
756
|
-
logger.info(
|
|
757
|
-
|
|
823
|
+
logger.info(
|
|
824
|
+
import_chalk.default.green(`${logPrefix} Declaration files built in ${Date.now() - startTime}ms.
|
|
825
|
+
`)
|
|
826
|
+
);
|
|
758
827
|
}
|
|
759
828
|
};
|
|
760
829
|
}
|