vue-i18n-extract-plugin 1.0.58 → 1.0.61

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 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");
@@ -40,6 +41,9 @@ const {
40
41
  } = require("./import-i18n-transform");
41
42
 
42
43
  function defineConfig(options) {
44
+ if (typeof options === "function") {
45
+ return options();
46
+ }
43
47
  return options;
44
48
  }
45
49
 
@@ -62,6 +66,7 @@ module.exports = {
62
66
  registerLangMatch,
63
67
  trimEmptyLine,
64
68
  padEmptyLine,
69
+ createFilterFn,
65
70
  excludeDirectives,
66
71
  EXCLUDED_CALL,
67
72
  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
  };
@@ -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("./vite-plugin-i18n");
2
+ const { createFilterFn } = require("./utils");
3
3
  const { defaultOptions } = require("./options");
4
4
 
5
5
  function vitePluginImportI18n(option) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-i18n-extract-plugin",
3
- "version": "1.0.58",
3
+ "version": "1.0.61",
4
4
  "main": "lib/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "bin": {
package/types/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export {
19
19
  registerLangMatch,
20
20
  trimEmptyLine,
21
21
  padEmptyLine,
22
+ createFilterFn,
22
23
  excludeDirectives,
23
24
  EXCLUDED_CALL
24
25
  } from "./utils";
@@ -43,4 +44,4 @@ declare const defaultOptions: I18nOptions;
43
44
 
44
45
  export { defaultOptions }
45
46
 
46
- export function defineConfig(options: Partial<I18nOptions>): I18nOptions;
47
+ export function defineConfig<T = Partial<I18nOptions>>(options: T | (() => T)): T;
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[];
@@ -1,6 +1,4 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { I18nOptions } from './options';
3
3
 
4
- export function createFilterFn(option: Partial<I18nOptions>): (id: string) => boolean;
5
-
6
4
  export default function vitePluginI18n(option?: Partial<I18nOptions>): Plugin