vite-intlayer 7.3.14 → 7.4.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/dist/esm/intlayerPrunePlugin.mjs +9 -24
- package/dist/esm/intlayerPrunePlugin.mjs.map +1 -1
- package/dist/esm/intlayerVueAsyncPlugin.mjs +34 -0
- package/dist/esm/intlayerVueAsyncPlugin.mjs.map +1 -0
- package/dist/types/intlayerPrunePlugin.d.ts +1 -1
- package/dist/types/intlayerPrunePlugin.d.ts.map +1 -1
- package/dist/types/intlayerVueAsyncPlugin.d.ts +8 -0
- package/dist/types/intlayerVueAsyncPlugin.d.ts.map +1 -0
- package/package.json +10 -11
|
@@ -1,22 +1,20 @@
|
|
|
1
|
+
import { intlayerVueAsyncPlugin } from "./intlayerVueAsyncPlugin.mjs";
|
|
1
2
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
3
|
+
import { join } from "node:path";
|
|
3
4
|
import { intlayerOptimizeBabelPlugin } from "@intlayer/babel";
|
|
4
|
-
import { runOnce } from "@intlayer/chokidar";
|
|
5
|
+
import { getComponentTransformPattern, runOnce } from "@intlayer/chokidar";
|
|
5
6
|
import { getAppLogger } from "@intlayer/config";
|
|
6
7
|
import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
7
|
-
import fg from "fast-glob";
|
|
8
8
|
|
|
9
9
|
//#region src/intlayerPrunePlugin.ts
|
|
10
|
-
const
|
|
10
|
+
const INTLAYER_USAGE_REGEX = /\b(use|get)Intlayer\b/;
|
|
11
|
+
const intlayerPrune = async (intlayerConfig) => {
|
|
11
12
|
try {
|
|
12
13
|
const babel = createRequire(import.meta.url)("@babel/core");
|
|
13
14
|
const logger = getAppLogger(intlayerConfig);
|
|
14
15
|
const { importMode, traversePattern, optimize } = intlayerConfig.build;
|
|
15
16
|
const { dictionariesDir, dynamicDictionariesDir, unmergedDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
|
|
16
|
-
const filesListPattern =
|
|
17
|
-
if (isAbsolute(file)) return file;
|
|
18
|
-
return join(baseDir, file);
|
|
19
|
-
});
|
|
17
|
+
const filesListPattern = await getComponentTransformPattern(intlayerConfig);
|
|
20
18
|
const dictionariesEntryPath = join(mainDir, "dictionaries.mjs");
|
|
21
19
|
const unmergedDictionariesEntryPath = join(mainDir, "unmerged_dictionaries.mjs");
|
|
22
20
|
const dynamicDictionariesEntryPath = join(mainDir, "dynamic_dictionaries.mjs");
|
|
@@ -27,22 +25,7 @@ const intlayerPrune = (intlayerConfig) => {
|
|
|
27
25
|
];
|
|
28
26
|
const dictionaries = getDictionaries(intlayerConfig);
|
|
29
27
|
const liveSyncKeys = Object.values(dictionaries).filter((dictionary) => dictionary.live).map((dictionary) => dictionary.key);
|
|
30
|
-
return [{
|
|
31
|
-
name: "vite-intlayer-simple-transform",
|
|
32
|
-
enforce: "pre",
|
|
33
|
-
apply: (_config, env) => {
|
|
34
|
-
const isBuild = env.command === "build";
|
|
35
|
-
return (optimize === void 0 && isBuild || optimize === true) && (importMode === "dynamic" || importMode === "live");
|
|
36
|
-
},
|
|
37
|
-
transform(code, id) {
|
|
38
|
-
if (!id.endsWith(".vue")) return null;
|
|
39
|
-
if (!code.includes("useIntlayer")) return null;
|
|
40
|
-
return {
|
|
41
|
-
code: code.replace(/(\s+|=\s*)useIntlayer\s*\(/g, "$1await useIntlayer("),
|
|
42
|
-
map: null
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
28
|
+
return [intlayerVueAsyncPlugin(intlayerConfig, filesList), {
|
|
46
29
|
name: "vite-intlayer-babel-transform",
|
|
47
30
|
enforce: "post",
|
|
48
31
|
apply: (_config, env) => {
|
|
@@ -62,6 +45,8 @@ const intlayerPrune = (intlayerConfig) => {
|
|
|
62
45
|
*/
|
|
63
46
|
const filename = id.split("?", 1)[0];
|
|
64
47
|
if (!filesList.includes(filename)) return null;
|
|
48
|
+
const isDictionaryEntry = [dictionariesEntryPath, unmergedDictionariesEntryPath].includes(filename);
|
|
49
|
+
if (!(INTLAYER_USAGE_REGEX.test(code) || isDictionaryEntry)) return null;
|
|
65
50
|
const result = babel.transformSync(code, {
|
|
66
51
|
filename,
|
|
67
52
|
plugins: [[intlayerOptimizeBabelPlugin, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPrunePlugin.mjs","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport {
|
|
1
|
+
{"version":3,"file":"intlayerPrunePlugin.mjs","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { intlayerOptimizeBabelPlugin } from '@intlayer/babel';\nimport { getComponentTransformPattern, runOnce } from '@intlayer/chokidar';\nimport { getAppLogger } from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { PluginOption } from 'vite';\nimport { intlayerVueAsyncPlugin } from './intlayerVueAsyncPlugin';\n\nconst INTLAYER_USAGE_REGEX = /\\b(use|get)Intlayer\\b/;\n\nexport const intlayerPrune = async (\n intlayerConfig: IntlayerConfig\n): Promise<PluginOption[]> => {\n try {\n const localeRequire = createRequire(import.meta.url);\n const babel = localeRequire('@babel/core');\n const logger = getAppLogger(intlayerConfig);\n\n const { importMode, traversePattern, optimize } = intlayerConfig.build;\n\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n unmergedDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n const filesListPattern = await getComponentTransformPattern(intlayerConfig);\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return [\n intlayerVueAsyncPlugin(intlayerConfig, filesList),\n {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after other transformations as vue\n apply: (_config, env) => {\n // Only apply babel plugin if optimize is enabled\n\n const isBuild = env.command === 'build';\n const isEnabled =\n (optimize === undefined && isBuild) || optimize === true;\n\n if (isEnabled) {\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-prune-plugin-enabled.lock'\n ),\n () => logger('Build optimization enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n }\n\n return isEnabled;\n },\n transform(code, id) {\n /**\n * Transform file as\n * .../HelloWorld.vue?vue&type=script&setup=true&lang.ts\n * Into\n * .../HelloWorld.vue\n *\n * Prevention for virtual file\n */\n const filename = id.split('?', 1)[0];\n\n if (!filesList.includes(filename)) return null;\n\n const isDictionaryEntry = [\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n ].includes(filename);\n\n const isUsingIntlayer = INTLAYER_USAGE_REGEX.test(code);\n\n const shouldTransform = isUsingIntlayer || isDictionaryEntry;\n\n if (!shouldTransform) return null;\n\n const result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerOptimizeBabelPlugin,\n {\n optimize,\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\n liveSyncKeys,\n },\n ],\n ],\n parserOpts: {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n },\n });\n\n if (result?.code) {\n return {\n code: result.code,\n map: result.map,\n };\n }\n },\n },\n ];\n } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n\n return [];\n }\n};\n"],"mappings":";;;;;;;;;AAUA,MAAM,uBAAuB;AAE7B,MAAa,gBAAgB,OAC3B,mBAC4B;AAC5B,KAAI;EAEF,MAAM,QADgB,cAAc,OAAO,KAAK,IAAI,CACxB,cAAc;EAC1C,MAAM,SAAS,aAAa,eAAe;EAE3C,MAAM,EAAE,YAAY,iBAAiB,aAAa,eAAe;EAEjE,MAAM,EACJ,iBACA,wBACA,yBACA,sBACA,SACA,YACE,eAAe;EAEnB,MAAM,mBAAmB,MAAM,6BAA6B,eAAe;EAE3E,MAAM,wBAAwB,KAAK,SAAS,mBAAmB;EAC/D,MAAM,gCAAgC,KACpC,SACA,4BACD;EACD,MAAM,+BAA+B,KACnC,SACA,2BACD;EAED,MAAM,YAAY;GAChB,GAAG;GACH;GACA;GACD;EAED,MAAM,eAAe,gBAAgB,eAAe;EACpD,MAAM,eAAe,OAAO,OAAO,aAAa,CAC7C,QAAQ,eAAe,WAAW,KAAK,CACvC,KAAK,eAAe,WAAW,IAAI;AAEtC,SAAO,CACL,uBAAuB,gBAAgB,UAAU,EACjD;GACE,MAAM;GACN,SAAS;GACT,QAAQ,SAAS,QAAQ;IAGvB,MAAM,UAAU,IAAI,YAAY;IAChC,MAAM,YACH,aAAa,UAAa,WAAY,aAAa;AAEtD,QAAI,UACF,SACE,KACE,SACA,aACA,SACA,qCACD,QACK,OAAO,6BAA6B,EAC1C,EACE,gBAAgB,MAAO,IACxB,CACF;AAGH,WAAO;;GAET,UAAU,MAAM,IAAI;;;;;;;;;IASlB,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAElC,QAAI,CAAC,UAAU,SAAS,SAAS,CAAE,QAAO;IAE1C,MAAM,oBAAoB,CACxB,uBACA,8BACD,CAAC,SAAS,SAAS;AAMpB,QAAI,EAJoB,qBAAqB,KAAK,KAAK,IAEZ,mBAErB,QAAO;IAE7B,MAAM,SAAS,MAAM,cAAc,MAAM;KACvC;KACA,SAAS,CACP,CACE,6BACA;MACE;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,wBAAwB;MACxB;MACD,CACF,CACF;KACD,YAAY;MACV,YAAY;MACZ,6BAA6B;MAC7B,SAAS;OACP;OACA;OACA;OACA;OACA;OACA;OACA;OACA;OACA;OACA;OACA;OACA;OACD;MACF;KACF,CAAC;AAEF,QAAI,QAAQ,KACV,QAAO;KACL,MAAM,OAAO;KACb,KAAK,OAAO;KACb;;GAGN,CACF;UACM,OAAO;AACd,UAAQ,KAAK,0CAA0C,MAAM;AAE7D,SAAO,EAAE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/intlayerVueAsyncPlugin.ts
|
|
2
|
+
const intlayerVueAsyncPlugin = (configuration, filesList) => {
|
|
3
|
+
const { importMode, optimize } = configuration.build;
|
|
4
|
+
return {
|
|
5
|
+
name: "vite-intlayer-simple-transform",
|
|
6
|
+
enforce: "pre",
|
|
7
|
+
apply: (_config, env) => {
|
|
8
|
+
const isBuild = env.command === "build";
|
|
9
|
+
return (optimize === void 0 && isBuild || optimize === true) && (importMode === "dynamic" || importMode === "live");
|
|
10
|
+
},
|
|
11
|
+
transform(code, id) {
|
|
12
|
+
if (!id.endsWith(".vue")) return null;
|
|
13
|
+
/**
|
|
14
|
+
* Transform file as
|
|
15
|
+
* .../HelloWorld.vue?vue&type=script&setup=true&lang.ts
|
|
16
|
+
* Into
|
|
17
|
+
* .../HelloWorld.vue
|
|
18
|
+
*
|
|
19
|
+
* Prevention for virtual file
|
|
20
|
+
*/
|
|
21
|
+
const filename = id.split("?", 1)[0];
|
|
22
|
+
if (!filesList.includes(filename)) return null;
|
|
23
|
+
if (!code.includes("useIntlayer")) return null;
|
|
24
|
+
return {
|
|
25
|
+
code: code.replace(/(\s+|=\s*)useIntlayer\s*\(/g, "$1await useIntlayer("),
|
|
26
|
+
map: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { intlayerVueAsyncPlugin };
|
|
34
|
+
//# sourceMappingURL=intlayerVueAsyncPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intlayerVueAsyncPlugin.mjs","names":[],"sources":["../../src/intlayerVueAsyncPlugin.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types';\nimport type { PluginOption } from 'vite';\n\nexport const intlayerVueAsyncPlugin = (\n configuration: IntlayerConfig,\n filesList: string[]\n): PluginOption => {\n const { importMode, optimize } = configuration.build;\n\n return {\n /**\n * On vue, we pre-insert the 'await' to the useIntlayer call\n * It will trigger the transformation of the async call by the vue compiler\n *\n * Then the second plugin will make the second transformation to replace the useIntlayer call by the useDictionaryDynamic call\n */\n name: 'vite-intlayer-simple-transform',\n enforce: 'pre', // Run before Vue so Vue sees the 'await'\n apply: (_config, env) => {\n // Only apply babel plugin if optimize is enabled\n\n const isBuild = env.command === 'build';\n const isEnabled =\n (optimize === undefined && isBuild) || optimize === true;\n const isAsync = importMode === 'dynamic' || importMode === 'live';\n\n return isEnabled && isAsync;\n },\n\n transform(code, id) {\n // Only process .vue files\n // The await injection is only needed for Vue to trigger async component compilation\n if (!id.endsWith('.vue')) return null;\n\n /**\n * Transform file as\n * .../HelloWorld.vue?vue&type=script&setup=true&lang.ts\n * Into\n * .../HelloWorld.vue\n *\n * Prevention for virtual file\n */\n const filename = id.split('?', 1)[0];\n\n if (!filesList.includes(filename)) return null;\n\n // Check if the file actually uses the composable to avoid unnecessary work\n if (!code.includes('useIntlayer')) return null;\n\n // B. Add 'await' to the function call\n // Matches: useIntlayer(args) -> await useIntlayer(args)\n // Note: Since we aliased the import above, 'useIntlayer' now refers to 'useDictionaryAsync'\n const transformedCode = code.replace(\n /(\\s+|=\\s*)useIntlayer\\s*\\(/g,\n '$1await useIntlayer('\n );\n\n return {\n code: transformedCode,\n map: null, // Simple string replace doesn't strictly need a sourcemap for this case\n };\n },\n };\n};\n"],"mappings":";AAGA,MAAa,0BACX,eACA,cACiB;CACjB,MAAM,EAAE,YAAY,aAAa,cAAc;AAE/C,QAAO;EAOL,MAAM;EACN,SAAS;EACT,QAAQ,SAAS,QAAQ;GAGvB,MAAM,UAAU,IAAI,YAAY;AAKhC,WAHG,aAAa,UAAa,WAAY,aAAa,UACtC,eAAe,aAAa,eAAe;;EAK7D,UAAU,MAAM,IAAI;AAGlB,OAAI,CAAC,GAAG,SAAS,OAAO,CAAE,QAAO;;;;;;;;;GAUjC,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAElC,OAAI,CAAC,UAAU,SAAS,SAAS,CAAE,QAAO;AAG1C,OAAI,CAAC,KAAK,SAAS,cAAc,CAAE,QAAO;AAU1C,UAAO;IACL,MANsB,KAAK,QAC3B,+BACA,uBACD;IAIC,KAAK;IACN;;EAEJ"}
|
|
@@ -2,7 +2,7 @@ import { IntlayerConfig } from "@intlayer/types";
|
|
|
2
2
|
import { PluginOption } from "vite";
|
|
3
3
|
|
|
4
4
|
//#region src/intlayerPrunePlugin.d.ts
|
|
5
|
-
declare const intlayerPrune: (intlayerConfig: IntlayerConfig) => PluginOption[]
|
|
5
|
+
declare const intlayerPrune: (intlayerConfig: IntlayerConfig) => Promise<PluginOption[]>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { intlayerPrune };
|
|
8
8
|
//# sourceMappingURL=intlayerPrunePlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPrunePlugin.d.ts","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"intlayerPrunePlugin.d.ts","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":[],"mappings":";;;;cAYa,gCACK,mBACf,QAAQ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IntlayerConfig } from "@intlayer/types";
|
|
2
|
+
import { PluginOption } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/intlayerVueAsyncPlugin.d.ts
|
|
5
|
+
declare const intlayerVueAsyncPlugin: (configuration: IntlayerConfig, filesList: string[]) => PluginOption;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { intlayerVueAsyncPlugin };
|
|
8
|
+
//# sourceMappingURL=intlayerVueAsyncPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intlayerVueAsyncPlugin.d.ts","names":[],"sources":["../../src/intlayerVueAsyncPlugin.ts"],"sourcesContent":[],"mappings":";;;;cAGa,wCACI,wCAEd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-intlayer",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Vite plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration",
|
|
6
6
|
"keywords": [
|
|
@@ -78,14 +78,13 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@babel/core": "7.28.4",
|
|
81
|
-
"@intlayer/babel": "7.
|
|
82
|
-
"@intlayer/chokidar": "7.
|
|
83
|
-
"@intlayer/config": "7.
|
|
84
|
-
"@intlayer/core": "7.
|
|
85
|
-
"@intlayer/dictionaries-entry": "7.
|
|
86
|
-
"@intlayer/types": "7.
|
|
87
|
-
"
|
|
88
|
-
"intlayer": "7.3.14"
|
|
81
|
+
"@intlayer/babel": "7.4.0",
|
|
82
|
+
"@intlayer/chokidar": "7.4.0",
|
|
83
|
+
"@intlayer/config": "7.4.0",
|
|
84
|
+
"@intlayer/core": "7.4.0",
|
|
85
|
+
"@intlayer/dictionaries-entry": "7.4.0",
|
|
86
|
+
"@intlayer/types": "7.4.0",
|
|
87
|
+
"intlayer": "7.4.0"
|
|
89
88
|
},
|
|
90
89
|
"devDependencies": {
|
|
91
90
|
"@types/node": "24.10.1",
|
|
@@ -99,8 +98,8 @@
|
|
|
99
98
|
},
|
|
100
99
|
"peerDependencies": {
|
|
101
100
|
"@babel/core": ">=6.0.0",
|
|
102
|
-
"@intlayer/svelte-compiler": "7.
|
|
103
|
-
"@intlayer/vue-compiler": "7.
|
|
101
|
+
"@intlayer/svelte-compiler": "7.4.0",
|
|
102
|
+
"@intlayer/vue-compiler": "7.4.0",
|
|
104
103
|
"vite": ">=4.0.0"
|
|
105
104
|
},
|
|
106
105
|
"peerDependenciesMeta": {
|