vite-plugin-dts 3.6.1 → 3.6.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 +40 -14
- package/dist/index.mjs +40 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -175,7 +175,7 @@ function toCapitalCase(value) {
|
|
|
175
175
|
""
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function findTypesPath(...pkgs) {
|
|
179
179
|
let path;
|
|
180
180
|
for (const pkg of pkgs) {
|
|
181
181
|
if (typeof pkg !== "object")
|
|
@@ -185,6 +185,27 @@ function fileTypesPath(...pkgs) {
|
|
|
185
185
|
return path;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
+
function setModuleResolution(options) {
|
|
189
|
+
if (options.moduleResolution)
|
|
190
|
+
return;
|
|
191
|
+
const module = typeof options.module === "number" ? options.module : options.target ?? ts__default.ScriptTarget.ES5 >= 2 ? ts__default.ModuleKind.ES2015 : ts__default.ModuleKind.CommonJS;
|
|
192
|
+
let moduleResolution;
|
|
193
|
+
switch (module) {
|
|
194
|
+
case ts__default.ModuleKind.CommonJS:
|
|
195
|
+
moduleResolution = ts__default.ModuleResolutionKind.Node10;
|
|
196
|
+
break;
|
|
197
|
+
case ts__default.ModuleKind.Node16:
|
|
198
|
+
moduleResolution = ts__default.ModuleResolutionKind.Node16;
|
|
199
|
+
break;
|
|
200
|
+
case ts__default.ModuleKind.NodeNext:
|
|
201
|
+
moduleResolution = ts__default.ModuleResolutionKind.NodeNext;
|
|
202
|
+
break;
|
|
203
|
+
default:
|
|
204
|
+
moduleResolution = ts__default.version.startsWith("5") ? ts__default.ModuleResolutionKind.Bundler : ts__default.ModuleResolutionKind.Classic;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
options.moduleResolution = moduleResolution;
|
|
208
|
+
}
|
|
188
209
|
|
|
189
210
|
const dtsRE$1 = /\.d\.tsx?$/;
|
|
190
211
|
function rollupDeclarationFiles({
|
|
@@ -546,10 +567,13 @@ function dtsPlugin(options = {}) {
|
|
|
546
567
|
if (config.build.lib) {
|
|
547
568
|
const input = typeof config.build.lib.entry === "string" ? [config.build.lib.entry] : config.build.lib.entry;
|
|
548
569
|
if (Array.isArray(input)) {
|
|
549
|
-
entries = input.reduce(
|
|
550
|
-
prev
|
|
551
|
-
|
|
552
|
-
|
|
570
|
+
entries = input.reduce(
|
|
571
|
+
(prev, current) => {
|
|
572
|
+
prev[node_path.basename(current)] = current;
|
|
573
|
+
return prev;
|
|
574
|
+
},
|
|
575
|
+
{}
|
|
576
|
+
);
|
|
553
577
|
} else {
|
|
554
578
|
entries = { ...input };
|
|
555
579
|
}
|
|
@@ -581,10 +605,13 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
581
605
|
return;
|
|
582
606
|
const input = typeof options2.input === "string" ? [options2.input] : options2.input;
|
|
583
607
|
if (Array.isArray(input)) {
|
|
584
|
-
entries = input.reduce(
|
|
585
|
-
prev
|
|
586
|
-
|
|
587
|
-
|
|
608
|
+
entries = input.reduce(
|
|
609
|
+
(prev, current) => {
|
|
610
|
+
prev[node_path.basename(current)] = current;
|
|
611
|
+
return prev;
|
|
612
|
+
},
|
|
613
|
+
{}
|
|
614
|
+
);
|
|
588
615
|
} else {
|
|
589
616
|
entries = { ...input };
|
|
590
617
|
}
|
|
@@ -603,9 +630,6 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
603
630
|
configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts__default.findConfigFile(root, ts__default.sys.fileExists);
|
|
604
631
|
const content = configPath ? languageCore.createParsedCommandLine(ts__default, ts__default.sys, configPath) : void 0;
|
|
605
632
|
compilerOptions = {
|
|
606
|
-
// (#277) If user don't specify `moduleResolution` in top config file,
|
|
607
|
-
// declaration of Vue files will be inferred to `any` type.
|
|
608
|
-
moduleResolution: ts__default.ModuleResolutionKind.Node10,
|
|
609
633
|
...content?.options || {},
|
|
610
634
|
...options.compilerOptions || {},
|
|
611
635
|
...fixedCompilerOptions,
|
|
@@ -613,6 +637,9 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
613
637
|
declarationDir: "."
|
|
614
638
|
};
|
|
615
639
|
rawCompilerOptions = content?.raw.compilerOptions || {};
|
|
640
|
+
if (content?.fileNames.find((name) => name.endsWith(".vue"))) {
|
|
641
|
+
setModuleResolution(compilerOptions);
|
|
642
|
+
}
|
|
616
643
|
if (!outDirs) {
|
|
617
644
|
outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
|
|
618
645
|
}
|
|
@@ -652,7 +679,6 @@ ${logPrefix} ${kolorist.yellow(
|
|
|
652
679
|
program = vueTsc.createProgram({
|
|
653
680
|
host,
|
|
654
681
|
rootNames,
|
|
655
|
-
projectReferences: content?.projectReferences,
|
|
656
682
|
options: compilerOptions
|
|
657
683
|
});
|
|
658
684
|
libName = toCapitalCase(libName || "_default");
|
|
@@ -834,7 +860,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
834
860
|
} catch (e) {
|
|
835
861
|
}
|
|
836
862
|
const entryNames = Object.keys(entries);
|
|
837
|
-
const types =
|
|
863
|
+
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
838
864
|
const multiple = entryNames.length > 1;
|
|
839
865
|
const cleanPath = (path) => {
|
|
840
866
|
return cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path;
|
package/dist/index.mjs
CHANGED
|
@@ -175,7 +175,7 @@ function toCapitalCase(value) {
|
|
|
175
175
|
""
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function findTypesPath(...pkgs) {
|
|
179
179
|
let path;
|
|
180
180
|
for (const pkg of pkgs) {
|
|
181
181
|
if (typeof pkg !== "object")
|
|
@@ -185,6 +185,27 @@ function fileTypesPath(...pkgs) {
|
|
|
185
185
|
return path;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
+
function setModuleResolution(options) {
|
|
189
|
+
if (options.moduleResolution)
|
|
190
|
+
return;
|
|
191
|
+
const module = typeof options.module === "number" ? options.module : options.target ?? ts.ScriptTarget.ES5 >= 2 ? ts.ModuleKind.ES2015 : ts.ModuleKind.CommonJS;
|
|
192
|
+
let moduleResolution;
|
|
193
|
+
switch (module) {
|
|
194
|
+
case ts.ModuleKind.CommonJS:
|
|
195
|
+
moduleResolution = ts.ModuleResolutionKind.Node10;
|
|
196
|
+
break;
|
|
197
|
+
case ts.ModuleKind.Node16:
|
|
198
|
+
moduleResolution = ts.ModuleResolutionKind.Node16;
|
|
199
|
+
break;
|
|
200
|
+
case ts.ModuleKind.NodeNext:
|
|
201
|
+
moduleResolution = ts.ModuleResolutionKind.NodeNext;
|
|
202
|
+
break;
|
|
203
|
+
default:
|
|
204
|
+
moduleResolution = ts.version.startsWith("5") ? ts.ModuleResolutionKind.Bundler : ts.ModuleResolutionKind.Classic;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
options.moduleResolution = moduleResolution;
|
|
208
|
+
}
|
|
188
209
|
|
|
189
210
|
const dtsRE$1 = /\.d\.tsx?$/;
|
|
190
211
|
function rollupDeclarationFiles({
|
|
@@ -546,10 +567,13 @@ function dtsPlugin(options = {}) {
|
|
|
546
567
|
if (config.build.lib) {
|
|
547
568
|
const input = typeof config.build.lib.entry === "string" ? [config.build.lib.entry] : config.build.lib.entry;
|
|
548
569
|
if (Array.isArray(input)) {
|
|
549
|
-
entries = input.reduce(
|
|
550
|
-
prev
|
|
551
|
-
|
|
552
|
-
|
|
570
|
+
entries = input.reduce(
|
|
571
|
+
(prev, current) => {
|
|
572
|
+
prev[basename(current)] = current;
|
|
573
|
+
return prev;
|
|
574
|
+
},
|
|
575
|
+
{}
|
|
576
|
+
);
|
|
553
577
|
} else {
|
|
554
578
|
entries = { ...input };
|
|
555
579
|
}
|
|
@@ -581,10 +605,13 @@ ${logPrefix} ${yellow(
|
|
|
581
605
|
return;
|
|
582
606
|
const input = typeof options2.input === "string" ? [options2.input] : options2.input;
|
|
583
607
|
if (Array.isArray(input)) {
|
|
584
|
-
entries = input.reduce(
|
|
585
|
-
prev
|
|
586
|
-
|
|
587
|
-
|
|
608
|
+
entries = input.reduce(
|
|
609
|
+
(prev, current) => {
|
|
610
|
+
prev[basename(current)] = current;
|
|
611
|
+
return prev;
|
|
612
|
+
},
|
|
613
|
+
{}
|
|
614
|
+
);
|
|
588
615
|
} else {
|
|
589
616
|
entries = { ...input };
|
|
590
617
|
}
|
|
@@ -603,9 +630,6 @@ ${logPrefix} ${yellow(
|
|
|
603
630
|
configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts.findConfigFile(root, ts.sys.fileExists);
|
|
604
631
|
const content = configPath ? createParsedCommandLine(ts, ts.sys, configPath) : void 0;
|
|
605
632
|
compilerOptions = {
|
|
606
|
-
// (#277) If user don't specify `moduleResolution` in top config file,
|
|
607
|
-
// declaration of Vue files will be inferred to `any` type.
|
|
608
|
-
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
609
633
|
...content?.options || {},
|
|
610
634
|
...options.compilerOptions || {},
|
|
611
635
|
...fixedCompilerOptions,
|
|
@@ -613,6 +637,9 @@ ${logPrefix} ${yellow(
|
|
|
613
637
|
declarationDir: "."
|
|
614
638
|
};
|
|
615
639
|
rawCompilerOptions = content?.raw.compilerOptions || {};
|
|
640
|
+
if (content?.fileNames.find((name) => name.endsWith(".vue"))) {
|
|
641
|
+
setModuleResolution(compilerOptions);
|
|
642
|
+
}
|
|
616
643
|
if (!outDirs) {
|
|
617
644
|
outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
|
|
618
645
|
}
|
|
@@ -652,7 +679,6 @@ ${logPrefix} ${yellow(
|
|
|
652
679
|
program = createProgram({
|
|
653
680
|
host,
|
|
654
681
|
rootNames,
|
|
655
|
-
projectReferences: content?.projectReferences,
|
|
656
682
|
options: compilerOptions
|
|
657
683
|
});
|
|
658
684
|
libName = toCapitalCase(libName || "_default");
|
|
@@ -834,7 +860,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
834
860
|
} catch (e) {
|
|
835
861
|
}
|
|
836
862
|
const entryNames = Object.keys(entries);
|
|
837
|
-
const types =
|
|
863
|
+
const types = findTypesPath(pkg.publishConfig, pkg);
|
|
838
864
|
const multiple = entryNames.length > 1;
|
|
839
865
|
const cleanPath = (path) => {
|
|
840
866
|
return cleanVueFileName ? path.replace(".vue.d.ts", ".d.ts") : path;
|