vue-i18n-extract-plugin 1.0.58 → 1.0.60
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/lib/index.js +2 -0
- package/lib/utils.js +32 -0
- package/lib/vite-plugin-i18n.js +1 -38
- package/lib/vite-plugin-import-i18n.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/utils.d.ts +1 -0
- package/types/vite-plugin-i18n.d.ts +0 -2
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
registerLangMatch,
|
|
20
20
|
trimEmptyLine,
|
|
21
21
|
padEmptyLine,
|
|
22
|
+
createFilterFn,
|
|
22
23
|
excludeDirectives,
|
|
23
24
|
EXCLUDED_CALL
|
|
24
25
|
} = require("./utils");
|
|
@@ -62,6 +63,7 @@ module.exports = {
|
|
|
62
63
|
registerLangMatch,
|
|
63
64
|
trimEmptyLine,
|
|
64
65
|
padEmptyLine,
|
|
66
|
+
createFilterFn,
|
|
65
67
|
excludeDirectives,
|
|
66
68
|
EXCLUDED_CALL,
|
|
67
69
|
shouldTransform,
|
package/lib/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ const path = require("path");
|
|
|
2
2
|
const fs = require("fs-extra");
|
|
3
3
|
const crypto = require("crypto");
|
|
4
4
|
const types = require("@babel/types");
|
|
5
|
+
const { createFilter } = require("@rollup/pluginutils");
|
|
5
6
|
|
|
6
7
|
function hashKey(str) {
|
|
7
8
|
return crypto.createHash("sha512").update(str).digest("base64").slice(0, 6);
|
|
@@ -179,6 +180,36 @@ function padEmptyLine(str) {
|
|
|
179
180
|
return "\n" + str + "\n";
|
|
180
181
|
}
|
|
181
182
|
|
|
183
|
+
function createFilterFn(option) {
|
|
184
|
+
const {
|
|
185
|
+
i18nPkgImportPath: importPath,
|
|
186
|
+
allowedExtensions: extensions,
|
|
187
|
+
includePath,
|
|
188
|
+
excludedPath
|
|
189
|
+
} = option;
|
|
190
|
+
|
|
191
|
+
return createFilter(
|
|
192
|
+
extensions
|
|
193
|
+
.map(ext => includePath.map(p => `${fixFolderPath(p)}**/*${ext}`))
|
|
194
|
+
.flat(),
|
|
195
|
+
[
|
|
196
|
+
"node_modules/**",
|
|
197
|
+
importPath.endsWith("/")
|
|
198
|
+
? [
|
|
199
|
+
resolveFilterPath(importPath + "index.ts"),
|
|
200
|
+
resolveFilterPath(importPath + "index.js")
|
|
201
|
+
]
|
|
202
|
+
: [
|
|
203
|
+
resolveFilterPath(importPath + "/index.ts"),
|
|
204
|
+
resolveFilterPath(importPath + "/index.js"),
|
|
205
|
+
resolveFilterPath(importPath + ".ts"),
|
|
206
|
+
resolveFilterPath(importPath + ".js")
|
|
207
|
+
],
|
|
208
|
+
excludedPath.map(resolveFilterPath)
|
|
209
|
+
].flat()
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
182
213
|
const translateLangKeyEnum = {
|
|
183
214
|
ZH: "zh-cn",
|
|
184
215
|
EN: "en",
|
|
@@ -241,6 +272,7 @@ module.exports = {
|
|
|
241
272
|
registerLangMatch,
|
|
242
273
|
trimEmptyLine,
|
|
243
274
|
padEmptyLine,
|
|
275
|
+
createFilterFn,
|
|
244
276
|
excludeDirectives,
|
|
245
277
|
EXCLUDED_CALL
|
|
246
278
|
};
|
package/lib/vite-plugin-i18n.js
CHANGED
|
@@ -1,44 +1,9 @@
|
|
|
1
|
-
const { createFilter } = require("@rollup/pluginutils");
|
|
2
1
|
const { transformAsync } = require("@babel/core");
|
|
3
2
|
const { createI18nPlugin } = require("./visitors");
|
|
4
|
-
const {
|
|
5
|
-
relativeCWDPath,
|
|
6
|
-
resolveFilterPath,
|
|
7
|
-
fixFolderPath
|
|
8
|
-
} = require("./utils");
|
|
3
|
+
const { relativeCWDPath, createFilterFn } = require("./utils");
|
|
9
4
|
const { defaultOptions } = require("./options");
|
|
10
5
|
const { globalI18nMap, handleFinalI18nMap } = require("./extract");
|
|
11
6
|
|
|
12
|
-
function createFilterFn(option) {
|
|
13
|
-
const {
|
|
14
|
-
i18nPkgImportPath: importPath,
|
|
15
|
-
allowedExtensions: extensions,
|
|
16
|
-
includePath,
|
|
17
|
-
excludedPath
|
|
18
|
-
} = option;
|
|
19
|
-
|
|
20
|
-
return createFilter(
|
|
21
|
-
extensions
|
|
22
|
-
.map(ext => includePath.map(p => `${fixFolderPath(p)}**/*${ext}`))
|
|
23
|
-
.flat(),
|
|
24
|
-
[
|
|
25
|
-
"node_modules/**",
|
|
26
|
-
importPath.endsWith("/")
|
|
27
|
-
? [
|
|
28
|
-
resolveFilterPath(importPath + "index.ts"),
|
|
29
|
-
resolveFilterPath(importPath + "index.js")
|
|
30
|
-
]
|
|
31
|
-
: [
|
|
32
|
-
resolveFilterPath(importPath + "/index.ts"),
|
|
33
|
-
resolveFilterPath(importPath + "/index.js"),
|
|
34
|
-
resolveFilterPath(importPath + ".ts"),
|
|
35
|
-
resolveFilterPath(importPath + ".js")
|
|
36
|
-
],
|
|
37
|
-
excludedPath.map(resolveFilterPath)
|
|
38
|
-
].flat()
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
7
|
function vitePluginI18n(option) {
|
|
43
8
|
option = { ...defaultOptions, ...option };
|
|
44
9
|
|
|
@@ -105,8 +70,6 @@ function vitePluginI18n(option) {
|
|
|
105
70
|
};
|
|
106
71
|
}
|
|
107
72
|
|
|
108
|
-
exports.createFilterFn = createFilterFn;
|
|
109
|
-
|
|
110
73
|
module.exports = vitePluginI18n;
|
|
111
74
|
|
|
112
75
|
/* import { defineConfig } from 'vite'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { i18nImportTransform } = require("./import-i18n-transform");
|
|
2
|
-
const { createFilterFn } = require("./
|
|
2
|
+
const { createFilterFn } = require("./utils");
|
|
3
3
|
const { defaultOptions } = require("./options");
|
|
4
4
|
|
|
5
5
|
function vitePluginImportI18n(option) {
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
package/types/utils.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ export function shouldExtract(str: string, langKey: LangKey): boolean;
|
|
|
18
18
|
export function registerLangMatch(langKey: LangKey, regex: RegExp | ((str: string) => boolean)): void;
|
|
19
19
|
export function trimEmptyLine(str: string): string;
|
|
20
20
|
export function padEmptyLine(str: string): string;
|
|
21
|
+
export function createFilterFn(option: Partial<I18nOptions>): (id: string) => boolean;
|
|
21
22
|
export const excludeDirectives: string[];
|
|
22
23
|
export const EXCLUDED_CALL: string[];
|