vite-plugin-dts 1.4.1 → 1.5.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 +5 -0
- package/README.zh-CN.md +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -2
- package/dist/index.mjs +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,6 +97,11 @@ export interface PluginOptions {
|
|
|
97
97
|
// Default: 'tsconfig.json'
|
|
98
98
|
tsConfigFilePath?: string
|
|
99
99
|
|
|
100
|
+
// Set which paths should exclude when transform aliases
|
|
101
|
+
// If it's regexp, it will test the original import path directly
|
|
102
|
+
// Default: []
|
|
103
|
+
aliasesExclude?: (string | RegExp)[]
|
|
104
|
+
|
|
100
105
|
// Whether transform file name '.vue.d.ts' to '.d.ts'
|
|
101
106
|
// Default: false
|
|
102
107
|
cleanVueFileName?: boolean
|
package/README.zh-CN.md
CHANGED
|
@@ -96,6 +96,11 @@ export interface PluginOptions {
|
|
|
96
96
|
// 默认值: 'tsconfig.json'
|
|
97
97
|
tsConfigFilePath?: string
|
|
98
98
|
|
|
99
|
+
// 设置在转换别名时哪些路径需要排除
|
|
100
|
+
// 如果为正则,会直接使用 test 和原始路径进行比较
|
|
101
|
+
// 默认值: []
|
|
102
|
+
aliasesExclude?: (string | RegExp)[]
|
|
103
|
+
|
|
99
104
|
// 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
|
|
100
105
|
// 默认值: false
|
|
101
106
|
cleanVueFileName?: boolean
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
2
|
import { ts, Diagnostic } from 'ts-morph';
|
|
3
3
|
|
|
4
4
|
interface TransformWriteFile {
|
|
@@ -13,7 +13,7 @@ interface PluginOptions {
|
|
|
13
13
|
entryRoot?: string;
|
|
14
14
|
compilerOptions?: ts.CompilerOptions | null;
|
|
15
15
|
tsConfigFilePath?: string;
|
|
16
|
-
aliasesExclude?:
|
|
16
|
+
aliasesExclude?: (string | RegExp)[];
|
|
17
17
|
cleanVueFileName?: boolean;
|
|
18
18
|
staticImport?: boolean;
|
|
19
19
|
clearPureImport?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -219,7 +219,7 @@ var staticImportRE = /(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)
|
|
|
219
219
|
var dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
|
|
220
220
|
var simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
|
|
221
221
|
var simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
|
|
222
|
-
function transformAliasImport(filePath, content, aliases) {
|
|
222
|
+
function transformAliasImport(filePath, content, aliases, exclude = []) {
|
|
223
223
|
if (!aliases.length)
|
|
224
224
|
return content;
|
|
225
225
|
return content.replace(globalImportRE, (str) => {
|
|
@@ -232,6 +232,9 @@ function transformAliasImport(filePath, content, aliases) {
|
|
|
232
232
|
if (matchResult == null ? void 0 : matchResult[1]) {
|
|
233
233
|
const matchedAlias = aliases.find((alias) => isAliasMatch(alias, matchResult[1]));
|
|
234
234
|
if (matchedAlias) {
|
|
235
|
+
if (exclude.some((e) => isRegExp(e) ? e.test(matchResult[1]) : String(e) === matchResult[1])) {
|
|
236
|
+
return str;
|
|
237
|
+
}
|
|
235
238
|
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
239
|
return str.replace(isDynamic ? simpleDynamicImportRE : simpleStaticImportRE, `$1'${matchResult[1].replace(matchedAlias.find, (truthPath.startsWith(".") ? truthPath : `./${truthPath}`) + (typeof matchedAlias.find === "string" && matchedAlias.find.endsWith("/") ? "/" : ""))}'${isDynamic ? ")" : ""}`);
|
|
237
240
|
}
|
|
@@ -662,7 +665,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
662
665
|
}
|
|
663
666
|
if (!isMapFile && content && content !== noneExport) {
|
|
664
667
|
content = clearPureImport ? removePureImport(content) : content;
|
|
665
|
-
content = transformAliasImport(filePath, content, aliases);
|
|
668
|
+
content = transformAliasImport(filePath, content, aliases, aliasesExclude);
|
|
666
669
|
content = staticImport || rollupTypes ? transformDynamicImport(content) : content;
|
|
667
670
|
}
|
|
668
671
|
filePath = (0, import_path4.resolve)(outputDir, (0, import_path4.relative)(entryRoot, cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath));
|
package/dist/index.mjs
CHANGED
|
@@ -198,7 +198,7 @@ var staticImportRE = /(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)
|
|
|
198
198
|
var dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
|
|
199
199
|
var simpleStaticImportRE = /((?:import|export).+from\s?)['"](.+)['"]/;
|
|
200
200
|
var simpleDynamicImportRE = /(import\()['"](.+)['"]\)/;
|
|
201
|
-
function transformAliasImport(filePath, content, aliases) {
|
|
201
|
+
function transformAliasImport(filePath, content, aliases, exclude = []) {
|
|
202
202
|
if (!aliases.length)
|
|
203
203
|
return content;
|
|
204
204
|
return content.replace(globalImportRE, (str) => {
|
|
@@ -211,6 +211,9 @@ function transformAliasImport(filePath, content, aliases) {
|
|
|
211
211
|
if (matchResult == null ? void 0 : matchResult[1]) {
|
|
212
212
|
const matchedAlias = aliases.find((alias) => isAliasMatch(alias, matchResult[1]));
|
|
213
213
|
if (matchedAlias) {
|
|
214
|
+
if (exclude.some((e) => isRegExp(e) ? e.test(matchResult[1]) : String(e) === matchResult[1])) {
|
|
215
|
+
return str;
|
|
216
|
+
}
|
|
214
217
|
const truthPath = isAbsolute2(matchedAlias.replacement) ? normalizePath(relative(dirname2(filePath), matchedAlias.replacement)) : normalizePath(matchedAlias.replacement);
|
|
215
218
|
return str.replace(isDynamic ? simpleDynamicImportRE : simpleStaticImportRE, `$1'${matchResult[1].replace(matchedAlias.find, (truthPath.startsWith(".") ? truthPath : `./${truthPath}`) + (typeof matchedAlias.find === "string" && matchedAlias.find.endsWith("/") ? "/" : ""))}'${isDynamic ? ")" : ""}`);
|
|
216
219
|
}
|
|
@@ -644,7 +647,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
644
647
|
}
|
|
645
648
|
if (!isMapFile && content && content !== noneExport) {
|
|
646
649
|
content = clearPureImport ? removePureImport(content) : content;
|
|
647
|
-
content = transformAliasImport(filePath, content, aliases);
|
|
650
|
+
content = transformAliasImport(filePath, content, aliases, aliasesExclude);
|
|
648
651
|
content = staticImport || rollupTypes ? transformDynamicImport(content) : content;
|
|
649
652
|
}
|
|
650
653
|
filePath = resolve3(outputDir, relative2(entryRoot, cleanVueFileName ? filePath.replace(".vue.d.ts", ".d.ts") : filePath));
|
package/package.json
CHANGED