vite-plugin-dts 3.9.0 → 3.9.1
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 +20 -29
- package/dist/index.mjs +20 -29
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -456,18 +456,17 @@ function transformCode(options) {
|
|
|
456
456
|
const importMap = /* @__PURE__ */ new Map();
|
|
457
457
|
const usedDefault = /* @__PURE__ */ new Map();
|
|
458
458
|
const declareModules = [];
|
|
459
|
+
const toLibName = (origin) => {
|
|
460
|
+
const name = transformAlias(origin, dir, options.aliases, options.aliasesExclude);
|
|
461
|
+
return options.cleanVueFileName ? name.replace(/\.vue$/, "") : name;
|
|
462
|
+
};
|
|
459
463
|
let indexCount = 0;
|
|
460
464
|
walkSourceFile(ast, (node, parent) => {
|
|
461
465
|
if (ts__default.isImportDeclaration(node)) {
|
|
462
466
|
if (!node.importClause) {
|
|
463
467
|
options.clearPureImport && s.remove(node.pos, node.end);
|
|
464
468
|
} else if (ts__default.isStringLiteral(node.moduleSpecifier) && (node.importClause.name || node.importClause.namedBindings && ts__default.isNamedImports(node.importClause.namedBindings))) {
|
|
465
|
-
const libName =
|
|
466
|
-
node.moduleSpecifier.text,
|
|
467
|
-
dir,
|
|
468
|
-
options.aliases,
|
|
469
|
-
options.aliasesExclude
|
|
470
|
-
);
|
|
469
|
+
const libName = toLibName(node.moduleSpecifier.text);
|
|
471
470
|
const importSet = importMap.get(libName) ?? importMap.set(libName, /* @__PURE__ */ new Set()).get(libName);
|
|
472
471
|
if (node.importClause.name && !usedDefault.has(libName)) {
|
|
473
472
|
const usedType = node.importClause.name.escapedText;
|
|
@@ -488,12 +487,7 @@ function transformCode(options) {
|
|
|
488
487
|
return false;
|
|
489
488
|
}
|
|
490
489
|
if (ts__default.isImportTypeNode(node) && node.qualifier && ts__default.isLiteralTypeNode(node.argument) && ts__default.isIdentifier(node.qualifier) && ts__default.isStringLiteral(node.argument.literal)) {
|
|
491
|
-
const libName =
|
|
492
|
-
node.argument.literal.text,
|
|
493
|
-
dir,
|
|
494
|
-
options.aliases,
|
|
495
|
-
options.aliasesExclude
|
|
496
|
-
);
|
|
490
|
+
const libName = toLibName(node.argument.literal.text);
|
|
497
491
|
if (!options.staticImport) {
|
|
498
492
|
s.update(node.argument.literal.pos, node.argument.literal.end, `'${libName}'`);
|
|
499
493
|
return !!node.typeArguments;
|
|
@@ -515,23 +509,19 @@ function transformCode(options) {
|
|
|
515
509
|
return !!node.typeArguments;
|
|
516
510
|
}
|
|
517
511
|
if (ts__default.isCallExpression(node) && node.expression.kind === ts__default.SyntaxKind.ImportKeyword && ts__default.isStringLiteral(node.arguments[0])) {
|
|
518
|
-
|
|
519
|
-
node.arguments[0].
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
options.aliasesExclude
|
|
512
|
+
s.update(
|
|
513
|
+
node.arguments[0].pos,
|
|
514
|
+
node.arguments[0].end,
|
|
515
|
+
`'${toLibName(node.arguments[0].text)}'`
|
|
523
516
|
);
|
|
524
|
-
s.update(node.arguments[0].pos, node.arguments[0].end, `'${libName}'`);
|
|
525
517
|
return false;
|
|
526
518
|
}
|
|
527
519
|
if (ts__default.isExportDeclaration(node) && node.moduleSpecifier && ts__default.isStringLiteral(node.moduleSpecifier)) {
|
|
528
|
-
|
|
529
|
-
node.moduleSpecifier.
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
options.aliasesExclude
|
|
520
|
+
s.update(
|
|
521
|
+
node.moduleSpecifier.pos,
|
|
522
|
+
node.moduleSpecifier.end,
|
|
523
|
+
` '${toLibName(node.moduleSpecifier.text)}'`
|
|
533
524
|
);
|
|
534
|
-
s.update(node.moduleSpecifier.pos, node.moduleSpecifier.end, ` '${libName}'`);
|
|
535
525
|
return false;
|
|
536
526
|
}
|
|
537
527
|
if (ts__default.isModuleDeclaration(node)) {
|
|
@@ -543,10 +533,12 @@ function transformCode(options) {
|
|
|
543
533
|
return false;
|
|
544
534
|
}
|
|
545
535
|
});
|
|
536
|
+
let prependImports = "";
|
|
546
537
|
importMap.forEach((importSet, libName) => {
|
|
547
|
-
|
|
548
|
-
|
|
538
|
+
prependImports += `import { ${Array.from(importSet).join(", ")} } from '${libName}';
|
|
539
|
+
`;
|
|
549
540
|
});
|
|
541
|
+
s.prepend(prependImports);
|
|
550
542
|
return {
|
|
551
543
|
content: s.toString(),
|
|
552
544
|
declareModules
|
|
@@ -942,7 +934,6 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
942
934
|
}
|
|
943
935
|
bundleDebug("emit output patch");
|
|
944
936
|
const currentDir = host.getCurrentDirectory();
|
|
945
|
-
const vuePathRE = /['"](.+)\.vue['"]/g;
|
|
946
937
|
await runParallel(
|
|
947
938
|
node_os.cpus().length,
|
|
948
939
|
Array.from(outputFiles.entries()),
|
|
@@ -956,7 +947,8 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
956
947
|
aliases,
|
|
957
948
|
aliasesExclude,
|
|
958
949
|
staticImport,
|
|
959
|
-
clearPureImport
|
|
950
|
+
clearPureImport,
|
|
951
|
+
cleanVueFileName
|
|
960
952
|
});
|
|
961
953
|
content = result.content;
|
|
962
954
|
declareModules.push(...result.declareModules);
|
|
@@ -968,7 +960,6 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
968
960
|
cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath
|
|
969
961
|
)
|
|
970
962
|
);
|
|
971
|
-
content = cleanVueFileName ? content.replace(vuePathRE, '"$1"') : content;
|
|
972
963
|
if (isMapFile) {
|
|
973
964
|
try {
|
|
974
965
|
const sourceMap = JSON.parse(content);
|
package/dist/index.mjs
CHANGED
|
@@ -453,18 +453,17 @@ function transformCode(options) {
|
|
|
453
453
|
const importMap = /* @__PURE__ */ new Map();
|
|
454
454
|
const usedDefault = /* @__PURE__ */ new Map();
|
|
455
455
|
const declareModules = [];
|
|
456
|
+
const toLibName = (origin) => {
|
|
457
|
+
const name = transformAlias(origin, dir, options.aliases, options.aliasesExclude);
|
|
458
|
+
return options.cleanVueFileName ? name.replace(/\.vue$/, "") : name;
|
|
459
|
+
};
|
|
456
460
|
let indexCount = 0;
|
|
457
461
|
walkSourceFile(ast, (node, parent) => {
|
|
458
462
|
if (ts.isImportDeclaration(node)) {
|
|
459
463
|
if (!node.importClause) {
|
|
460
464
|
options.clearPureImport && s.remove(node.pos, node.end);
|
|
461
465
|
} else if (ts.isStringLiteral(node.moduleSpecifier) && (node.importClause.name || node.importClause.namedBindings && ts.isNamedImports(node.importClause.namedBindings))) {
|
|
462
|
-
const libName =
|
|
463
|
-
node.moduleSpecifier.text,
|
|
464
|
-
dir,
|
|
465
|
-
options.aliases,
|
|
466
|
-
options.aliasesExclude
|
|
467
|
-
);
|
|
466
|
+
const libName = toLibName(node.moduleSpecifier.text);
|
|
468
467
|
const importSet = importMap.get(libName) ?? importMap.set(libName, /* @__PURE__ */ new Set()).get(libName);
|
|
469
468
|
if (node.importClause.name && !usedDefault.has(libName)) {
|
|
470
469
|
const usedType = node.importClause.name.escapedText;
|
|
@@ -485,12 +484,7 @@ function transformCode(options) {
|
|
|
485
484
|
return false;
|
|
486
485
|
}
|
|
487
486
|
if (ts.isImportTypeNode(node) && node.qualifier && ts.isLiteralTypeNode(node.argument) && ts.isIdentifier(node.qualifier) && ts.isStringLiteral(node.argument.literal)) {
|
|
488
|
-
const libName =
|
|
489
|
-
node.argument.literal.text,
|
|
490
|
-
dir,
|
|
491
|
-
options.aliases,
|
|
492
|
-
options.aliasesExclude
|
|
493
|
-
);
|
|
487
|
+
const libName = toLibName(node.argument.literal.text);
|
|
494
488
|
if (!options.staticImport) {
|
|
495
489
|
s.update(node.argument.literal.pos, node.argument.literal.end, `'${libName}'`);
|
|
496
490
|
return !!node.typeArguments;
|
|
@@ -512,23 +506,19 @@ function transformCode(options) {
|
|
|
512
506
|
return !!node.typeArguments;
|
|
513
507
|
}
|
|
514
508
|
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && ts.isStringLiteral(node.arguments[0])) {
|
|
515
|
-
|
|
516
|
-
node.arguments[0].
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
options.aliasesExclude
|
|
509
|
+
s.update(
|
|
510
|
+
node.arguments[0].pos,
|
|
511
|
+
node.arguments[0].end,
|
|
512
|
+
`'${toLibName(node.arguments[0].text)}'`
|
|
520
513
|
);
|
|
521
|
-
s.update(node.arguments[0].pos, node.arguments[0].end, `'${libName}'`);
|
|
522
514
|
return false;
|
|
523
515
|
}
|
|
524
516
|
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
525
|
-
|
|
526
|
-
node.moduleSpecifier.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
options.aliasesExclude
|
|
517
|
+
s.update(
|
|
518
|
+
node.moduleSpecifier.pos,
|
|
519
|
+
node.moduleSpecifier.end,
|
|
520
|
+
` '${toLibName(node.moduleSpecifier.text)}'`
|
|
530
521
|
);
|
|
531
|
-
s.update(node.moduleSpecifier.pos, node.moduleSpecifier.end, ` '${libName}'`);
|
|
532
522
|
return false;
|
|
533
523
|
}
|
|
534
524
|
if (ts.isModuleDeclaration(node)) {
|
|
@@ -540,10 +530,12 @@ function transformCode(options) {
|
|
|
540
530
|
return false;
|
|
541
531
|
}
|
|
542
532
|
});
|
|
533
|
+
let prependImports = "";
|
|
543
534
|
importMap.forEach((importSet, libName) => {
|
|
544
|
-
|
|
545
|
-
|
|
535
|
+
prependImports += `import { ${Array.from(importSet).join(", ")} } from '${libName}';
|
|
536
|
+
`;
|
|
546
537
|
});
|
|
538
|
+
s.prepend(prependImports);
|
|
547
539
|
return {
|
|
548
540
|
content: s.toString(),
|
|
549
541
|
declareModules
|
|
@@ -939,7 +931,6 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
939
931
|
}
|
|
940
932
|
bundleDebug("emit output patch");
|
|
941
933
|
const currentDir = host.getCurrentDirectory();
|
|
942
|
-
const vuePathRE = /['"](.+)\.vue['"]/g;
|
|
943
934
|
await runParallel(
|
|
944
935
|
cpus().length,
|
|
945
936
|
Array.from(outputFiles.entries()),
|
|
@@ -953,7 +944,8 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
953
944
|
aliases,
|
|
954
945
|
aliasesExclude,
|
|
955
946
|
staticImport,
|
|
956
|
-
clearPureImport
|
|
947
|
+
clearPureImport,
|
|
948
|
+
cleanVueFileName
|
|
957
949
|
});
|
|
958
950
|
content = result.content;
|
|
959
951
|
declareModules.push(...result.declareModules);
|
|
@@ -965,7 +957,6 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
965
957
|
cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath
|
|
966
958
|
)
|
|
967
959
|
);
|
|
968
|
-
content = cleanVueFileName ? content.replace(vuePathRE, '"$1"') : content;
|
|
969
960
|
if (isMapFile) {
|
|
970
961
|
try {
|
|
971
962
|
const sourceMap = JSON.parse(content);
|