vite-intlayer 7.1.9 → 7.2.2

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 CHANGED
@@ -188,6 +188,7 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
188
188
  <li><a href="https://intlayer.org/doc/environment/react-native-and-expo" rel=''>React Native</a></li>
189
189
  <li><a href="https://intlayer.org/doc/environment/lynx-and-react" rel=''>Lynx + React</a></li>
190
190
  <li><a href="https://intlayer.org/doc/environment/vite-and-svelte" rel=''>Vite + Svelte</a></li>
191
+ <li><a href="https://intlayer.org/doc/environment/sveltekit" rel=''>SvelteKit</a></li>
191
192
  <li><a href="https://intlayer.org/doc/environment/vite-and-preact" rel=''>Vite + Preact</a></li>
192
193
  <li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
193
194
  <li><a href="https://intlayer.org/doc/environment/vite-and-nuxt" rel=''>Vite + Nuxt</a></li>
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
15
19
  }
16
20
  return to;
17
21
  };
@@ -19,7 +19,6 @@ let __intlayer_config = require("@intlayer/config");
19
19
  * */
20
20
  const intlayerPlugin = (configOptions) => {
21
21
  const intlayerConfig = (0, __intlayer_config.getConfiguration)(configOptions);
22
- const { optimize } = intlayerConfig.build;
23
22
  const alias = (0, __intlayer_config.getAlias)({
24
23
  configuration: intlayerConfig,
25
24
  formatter: (value) => (0, node_path.resolve)(value)
@@ -30,7 +29,7 @@ const intlayerPlugin = (configOptions) => {
30
29
  config: async (config, env) => {
31
30
  const isDevCommand = env.command === "serve" && env.mode === "development";
32
31
  const isBuildCommand = env.command === "build";
33
- if (isDevCommand || isBuildCommand) await (0, __intlayer_chokidar.prepareIntlayer)((0, __intlayer_config.getConfiguration)(configOptions), {
32
+ if (isDevCommand || isBuildCommand) await (0, __intlayer_chokidar.prepareIntlayer)(intlayerConfig, {
34
33
  clean: isBuildCommand,
35
34
  cacheTimeoutMs: isBuildCommand ? 1e3 * 30 : 1e3 * 60 * 60
36
35
  });
@@ -51,7 +50,7 @@ const intlayerPlugin = (configOptions) => {
51
50
  if (intlayerConfig.content.watch) (0, __intlayer_chokidar.watch)({ configuration: intlayerConfig });
52
51
  }
53
52
  }];
54
- if (optimize) plugins.push(require_intlayerPrunePlugin.intlayerPrune(intlayerConfig));
53
+ plugins.push(require_intlayerPrunePlugin.intlayerPrune(intlayerConfig));
55
54
  return plugins;
56
55
  };
57
56
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerPlugin.cjs","names":["plugins: PluginOption[]","intlayerPrune"],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getAlias,\n getConfiguration,\n} from '@intlayer/config';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport type { PluginOption } from 'vite';\nimport { intlayerPrune } from './intlayerPrunePlugin';\n\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n configOptions?: GetConfigurationOptions\n): PluginOption => {\n const intlayerConfig = getConfiguration(configOptions);\n const { optimize } = intlayerConfig.build;\n\n const alias = getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value),\n });\n\n const aliasPackages = Object.keys(alias);\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: async (config, env) => {\n const isDevCommand =\n env.command === 'serve' && env.mode === 'development';\n const isBuildCommand = env.command === 'build';\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n ...alias,\n },\n };\n\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [...(config.optimizeDeps?.exclude ?? []), ...aliasPackages],\n };\n\n return config;\n },\n\n configureServer: async (_server) => {\n if (intlayerConfig.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ configuration: intlayerConfig });\n }\n },\n },\n ];\n\n // Add Babel transform plugin if enabled\n if (optimize) {\n plugins.push(intlayerPrune(intlayerConfig));\n }\n\n return plugins;\n};\n\n/**\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intlayer = intlayerPlugin;\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intLayerPlugin = intlayerPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,MAAa,kBACX,kBACiB;CACjB,MAAM,yDAAkC,cAAc;CACtD,MAAM,EAAE,aAAa,eAAe;CAEpC,MAAM,wCAAiB;EACrB,eAAe;EACf,YAAY,iCAA0B,MAAM;EAC7C,CAAC;CAEF,MAAM,gBAAgB,OAAO,KAAK,MAAM;CAExC,MAAMA,UAA0B,CAC9B;EACE,MAAM;EAEN,QAAQ,OAAO,QAAQ,QAAQ;GAC7B,MAAM,eACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAC1C,MAAM,iBAAiB,IAAI,YAAY;AAKvC,OAAI,gBAAgB,eAIlB,wFAHwC,cAAc,EAGhB;IACpC,OAAO;IACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;IACjB,CAAC;AAIJ,UAAO,UAAU;IACf,GAAG,OAAO;IACV,OAAO;KACL,GAAG,OAAO,SAAS;KACnB,GAAG;KACJ;IACF;AAED,UAAO,eAAe;IACpB,GAAG,OAAO;IACV,SAAS,CAAC,GAAI,OAAO,cAAc,WAAW,EAAE,EAAG,GAAG,cAAc;IACrE;AAED,UAAO;;EAGT,iBAAiB,OAAO,YAAY;AAClC,OAAI,eAAe,QAAQ,MAEzB,gCAAM,EAAE,eAAe,gBAAgB,CAAC;;EAG7C,CACF;AAGD,KAAI,SACF,SAAQ,KAAKC,0CAAc,eAAe,CAAC;AAG7C,QAAO;;;;;;;;;;;;AAaT,MAAa,WAAW;;;;;;;;;;;;;AAaxB,MAAa,iBAAiB"}
1
+ {"version":3,"file":"intlayerPlugin.cjs","names":["plugins: PluginOption[]","intlayerPrune"],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getAlias,\n getConfiguration,\n} from '@intlayer/config';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport type { PluginOption } from 'vite';\nimport { intlayerPrune } from './intlayerPrunePlugin';\n\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n configOptions?: GetConfigurationOptions\n): PluginOption => {\n const intlayerConfig = getConfiguration(configOptions);\n\n const alias = getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value),\n });\n\n const aliasPackages = Object.keys(alias);\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: async (config, env) => {\n const isDevCommand =\n env.command === 'serve' && env.mode === 'development';\n const isBuildCommand = env.command === 'build';\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n ...alias,\n },\n };\n\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [...(config.optimizeDeps?.exclude ?? []), ...aliasPackages],\n };\n\n return config;\n },\n\n configureServer: async (_server) => {\n if (intlayerConfig.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ configuration: intlayerConfig });\n }\n },\n },\n ];\n\n // Add Babel transform plugin if enabled\n plugins.push(intlayerPrune(intlayerConfig));\n\n return plugins;\n};\n\n/**\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intlayer = intlayerPlugin;\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intLayerPlugin = intlayerPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,MAAa,kBACX,kBACiB;CACjB,MAAM,yDAAkC,cAAc;CAEtD,MAAM,wCAAiB;EACrB,eAAe;EACf,YAAY,iCAA0B,MAAM;EAC7C,CAAC;CAEF,MAAM,gBAAgB,OAAO,KAAK,MAAM;CAExC,MAAMA,UAA0B,CAC9B;EACE,MAAM;EAEN,QAAQ,OAAO,QAAQ,QAAQ;GAC7B,MAAM,eACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAC1C,MAAM,iBAAiB,IAAI,YAAY;AAKvC,OAAI,gBAAgB,eAElB,gDAAsB,gBAAgB;IACpC,OAAO;IACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;IACjB,CAAC;AAIJ,UAAO,UAAU;IACf,GAAG,OAAO;IACV,OAAO;KACL,GAAG,OAAO,SAAS;KACnB,GAAG;KACJ;IACF;AAED,UAAO,eAAe;IACpB,GAAG,OAAO;IACV,SAAS,CAAC,GAAI,OAAO,cAAc,WAAW,EAAE,EAAG,GAAG,cAAc;IACrE;AAED,UAAO;;EAGT,iBAAiB,OAAO,YAAY;AAClC,OAAI,eAAe,QAAQ,MAEzB,gCAAM,EAAE,eAAe,gBAAgB,CAAC;;EAG7C,CACF;AAGD,SAAQ,KAAKC,0CAAc,eAAe,CAAC;AAE3C,QAAO;;;;;;;;;;;;AAaT,MAAa,WAAW;;;;;;;;;;;;;AAaxB,MAAa,iBAAiB"}
@@ -1,5 +1,7 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  let node_path = require("node:path");
3
+ let __intlayer_chokidar = require("@intlayer/chokidar");
4
+ let __intlayer_config = require("@intlayer/config");
3
5
  let node_module = require("node:module");
4
6
  let __intlayer_babel = require("@intlayer/babel");
5
7
  let __intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
@@ -10,17 +12,29 @@ fast_glob = require_rolldown_runtime.__toESM(fast_glob);
10
12
  const intlayerPrune = (intlayerConfig) => {
11
13
  try {
12
14
  const babel = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@babel/core");
13
- const { optimize, importMode, traversePattern } = intlayerConfig.build;
14
- const { dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
15
+ const logger = (0, __intlayer_config.getAppLogger)(intlayerConfig);
16
+ const { importMode, traversePattern, optimize } = intlayerConfig.build;
17
+ const { dictionariesDir, dynamicDictionariesDir, unmergedDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
15
18
  const filesListPattern = fast_glob.default.sync(traversePattern, { cwd: baseDir }).map((file) => (0, node_path.join)(baseDir, file));
16
19
  const dictionariesEntryPath = (0, node_path.join)(mainDir, "dictionaries.mjs");
20
+ const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
17
21
  const dynamicDictionariesEntryPath = (0, node_path.join)(mainDir, "dynamic_dictionaries.mjs");
18
- const filesList = [...filesListPattern, dictionariesEntryPath];
22
+ const filesList = [
23
+ ...filesListPattern,
24
+ dictionariesEntryPath,
25
+ unmergedDictionariesEntryPath
26
+ ];
19
27
  const dictionaries = (0, __intlayer_dictionaries_entry.getDictionaries)();
20
28
  const liveSyncKeys = Object.values(dictionaries).filter((dictionary) => dictionary.live).map((dictionary) => dictionary.key);
21
29
  return {
22
30
  name: "vite-intlayer-babel-transform",
23
31
  enforce: "post",
32
+ apply: (_config, env) => {
33
+ const isBuild = env.command === "build";
34
+ const isEnabled = optimize ?? isBuild;
35
+ if (isEnabled) (0, __intlayer_chokidar.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Build optimization enabled"), { cacheTimeoutMs: 1e3 * 10 });
36
+ return isEnabled;
37
+ },
24
38
  transform(code, id) {
25
39
  /**
26
40
  * Transform file as
@@ -32,18 +46,19 @@ const intlayerPrune = (intlayerConfig) => {
32
46
  */
33
47
  const filename = id.split("?", 1)[0];
34
48
  if (!filesList.includes(filename)) return null;
35
- if (!optimize) return null;
36
49
  const result = babel.transformSync(code, {
37
50
  filename,
38
51
  plugins: [[__intlayer_babel.intlayerBabelPlugin, {
39
52
  dictionariesDir,
40
53
  dictionariesEntryPath,
54
+ unmergedDictionariesEntryPath,
55
+ unmergedDictionariesDir,
41
56
  dynamicDictionariesDir,
42
57
  dynamicDictionariesEntryPath,
43
58
  fetchDictionariesDir,
44
59
  importMode,
45
60
  filesList,
46
- replaceDictionaryEntry: false,
61
+ replaceDictionaryEntry: true,
47
62
  liveSyncKeys
48
63
  }]],
49
64
  parserOpts: {
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerPrunePlugin.cjs","names":["fg","intlayerBabelPlugin"],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport type { PluginOption } from 'vite';\n\nexport const intlayerPrune = (intlayerConfig: IntlayerConfig): PluginOption => {\n try {\n const localeRequire = createRequire(import.meta.url);\n const babel = localeRequire('@babel/core');\n\n const { optimize, importMode, traversePattern } = intlayerConfig.build;\n\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\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 ];\n\n const dictionaries = getDictionaries();\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after other transformations as vue\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 if (!filesList.includes(filename)) return null;\n if (!optimize) return null;\n\n const result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerBabelPlugin,\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n importMode,\n filesList,\n replaceDictionaryEntry: false,\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 } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n\n return null;\n }\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,iBAAiB,mBAAiD;AAC7E,KAAI;EAEF,MAAM,qFAD8C,CACxB,cAAc;EAE1C,MAAM,EAAE,UAAU,YAAY,oBAAoB,eAAe;EAEjE,MAAM,EACJ,iBACA,wBACA,sBACA,SACA,YACE,eAAe;EAEnB,MAAM,mBAAmBA,kBACtB,KAAK,iBAAiB,EACrB,KAAK,SACN,CAAC,CACD,KAAK,6BAAc,SAAS,KAAK,CAAC;EAErC,MAAM,4CAA6B,SAAS,mBAAmB;EAC/D,MAAM,mDACJ,SACA,2BACD;EAED,MAAM,YAAY,CAChB,GAAG,kBACH,sBACD;EAED,MAAM,mEAAgC;EACtC,MAAM,eAAe,OAAO,OAAO,aAAa,CAC7C,QAAQ,eAAe,WAAW,KAAK,CACvC,KAAK,eAAe,WAAW,IAAI;AAEtC,SAAO;GACL,MAAM;GACN,SAAS;GACT,UAAU,MAAM,IAAI;;;;;;;;;IASlB,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,QAAI,CAAC,UAAU,SAAS,SAAS,CAAE,QAAO;AAC1C,QAAI,CAAC,SAAU,QAAO;IAEtB,MAAM,SAAS,MAAM,cAAc,MAAM;KACvC;KACA,SAAS,CACP,CACEC,sCACA;MACE;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;UACM,OAAO;AACd,UAAQ,KAAK,0CAA0C,MAAM;AAE7D,SAAO"}
1
+ {"version":3,"file":"intlayerPrunePlugin.cjs","names":["fg","intlayerBabelPlugin"],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { runOnce } from '@intlayer/chokidar';\nimport { getAppLogger } from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport type { PluginOption } from 'vite';\n\nexport const intlayerPrune = (intlayerConfig: IntlayerConfig): 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 = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\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();\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\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 = optimize ?? isBuild;\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 result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerBabelPlugin,\n {\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 } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,iBAAiB,mBAAiD;AAC7E,KAAI;EAEF,MAAM,qFAD8C,CACxB,cAAc;EAC1C,MAAM,6CAAsB,eAAe;EAE3C,MAAM,EAAE,YAAY,iBAAiB,aAAa,eAAe;EAEjE,MAAM,EACJ,iBACA,wBACA,yBACA,sBACA,SACA,YACE,eAAe;EAEnB,MAAM,mBAAmBA,kBACtB,KAAK,iBAAiB,EACrB,KAAK,SACN,CAAC,CACD,KAAK,6BAAc,SAAS,KAAK,CAAC;EAErC,MAAM,4CAA6B,SAAS,mBAAmB;EAC/D,MAAM,oDACJ,SACA,4BACD;EACD,MAAM,mDACJ,SACA,2BACD;EAED,MAAM,YAAY;GAChB,GAAG;GACH;GACA;GACD;EAED,MAAM,mEAAgC;EACtC,MAAM,eAAe,OAAO,OAAO,aAAa,CAC7C,QAAQ,eAAe,WAAW,KAAK,CACvC,KAAK,eAAe,WAAW,IAAI;AAEtC,SAAO;GACL,MAAM;GACN,SAAS;GACT,QAAQ,SAAS,QAAQ;IAGvB,MAAM,UAAU,IAAI,YAAY;IAChC,MAAM,YAAY,YAAY;AAE9B,QAAI,UACF,sDAEI,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,SAAS,MAAM,cAAc,MAAM;KACvC;KACA,SAAS,CACP,CACEC,sCACA;MACE;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;UACM,OAAO;AACd,UAAQ,KAAK,0CAA0C,MAAM;AAE7D,SAAO"}
@@ -18,7 +18,6 @@ import { getAlias, getConfiguration } from "@intlayer/config";
18
18
  * */
19
19
  const intlayerPlugin = (configOptions) => {
20
20
  const intlayerConfig = getConfiguration(configOptions);
21
- const { optimize } = intlayerConfig.build;
22
21
  const alias = getAlias({
23
22
  configuration: intlayerConfig,
24
23
  formatter: (value) => resolve(value)
@@ -29,7 +28,7 @@ const intlayerPlugin = (configOptions) => {
29
28
  config: async (config, env) => {
30
29
  const isDevCommand = env.command === "serve" && env.mode === "development";
31
30
  const isBuildCommand = env.command === "build";
32
- if (isDevCommand || isBuildCommand) await prepareIntlayer(getConfiguration(configOptions), {
31
+ if (isDevCommand || isBuildCommand) await prepareIntlayer(intlayerConfig, {
33
32
  clean: isBuildCommand,
34
33
  cacheTimeoutMs: isBuildCommand ? 1e3 * 30 : 1e3 * 60 * 60
35
34
  });
@@ -50,7 +49,7 @@ const intlayerPlugin = (configOptions) => {
50
49
  if (intlayerConfig.content.watch) watch({ configuration: intlayerConfig });
51
50
  }
52
51
  }];
53
- if (optimize) plugins.push(intlayerPrune(intlayerConfig));
52
+ plugins.push(intlayerPrune(intlayerConfig));
54
53
  return plugins;
55
54
  };
56
55
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerPlugin.mjs","names":["plugins: PluginOption[]"],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getAlias,\n getConfiguration,\n} from '@intlayer/config';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport type { PluginOption } from 'vite';\nimport { intlayerPrune } from './intlayerPrunePlugin';\n\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n configOptions?: GetConfigurationOptions\n): PluginOption => {\n const intlayerConfig = getConfiguration(configOptions);\n const { optimize } = intlayerConfig.build;\n\n const alias = getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value),\n });\n\n const aliasPackages = Object.keys(alias);\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: async (config, env) => {\n const isDevCommand =\n env.command === 'serve' && env.mode === 'development';\n const isBuildCommand = env.command === 'build';\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n ...alias,\n },\n };\n\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [...(config.optimizeDeps?.exclude ?? []), ...aliasPackages],\n };\n\n return config;\n },\n\n configureServer: async (_server) => {\n if (intlayerConfig.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ configuration: intlayerConfig });\n }\n },\n },\n ];\n\n // Add Babel transform plugin if enabled\n if (optimize) {\n plugins.push(intlayerPrune(intlayerConfig));\n }\n\n return plugins;\n};\n\n/**\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intlayer = intlayerPlugin;\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intLayerPlugin = intlayerPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAa,kBACX,kBACiB;CACjB,MAAM,iBAAiB,iBAAiB,cAAc;CACtD,MAAM,EAAE,aAAa,eAAe;CAEpC,MAAM,QAAQ,SAAS;EACrB,eAAe;EACf,YAAY,UAAkB,QAAQ,MAAM;EAC7C,CAAC;CAEF,MAAM,gBAAgB,OAAO,KAAK,MAAM;CAExC,MAAMA,UAA0B,CAC9B;EACE,MAAM;EAEN,QAAQ,OAAO,QAAQ,QAAQ;GAC7B,MAAM,eACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAC1C,MAAM,iBAAiB,IAAI,YAAY;AAKvC,OAAI,gBAAgB,eAIlB,OAAM,gBAHiB,iBAAiB,cAAc,EAGhB;IACpC,OAAO;IACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;IACjB,CAAC;AAIJ,UAAO,UAAU;IACf,GAAG,OAAO;IACV,OAAO;KACL,GAAG,OAAO,SAAS;KACnB,GAAG;KACJ;IACF;AAED,UAAO,eAAe;IACpB,GAAG,OAAO;IACV,SAAS,CAAC,GAAI,OAAO,cAAc,WAAW,EAAE,EAAG,GAAG,cAAc;IACrE;AAED,UAAO;;EAGT,iBAAiB,OAAO,YAAY;AAClC,OAAI,eAAe,QAAQ,MAEzB,OAAM,EAAE,eAAe,gBAAgB,CAAC;;EAG7C,CACF;AAGD,KAAI,SACF,SAAQ,KAAK,cAAc,eAAe,CAAC;AAG7C,QAAO;;;;;;;;;;;;AAaT,MAAa,WAAW;;;;;;;;;;;;;AAaxB,MAAa,iBAAiB"}
1
+ {"version":3,"file":"intlayerPlugin.mjs","names":["plugins: PluginOption[]"],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getAlias,\n getConfiguration,\n} from '@intlayer/config';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport type { PluginOption } from 'vite';\nimport { intlayerPrune } from './intlayerPrunePlugin';\n\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n configOptions?: GetConfigurationOptions\n): PluginOption => {\n const intlayerConfig = getConfiguration(configOptions);\n\n const alias = getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value),\n });\n\n const aliasPackages = Object.keys(alias);\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: async (config, env) => {\n const isDevCommand =\n env.command === 'serve' && env.mode === 'development';\n const isBuildCommand = env.command === 'build';\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n ...alias,\n },\n };\n\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [...(config.optimizeDeps?.exclude ?? []), ...aliasPackages],\n };\n\n return config;\n },\n\n configureServer: async (_server) => {\n if (intlayerConfig.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ configuration: intlayerConfig });\n }\n },\n },\n ];\n\n // Add Babel transform plugin if enabled\n plugins.push(intlayerPrune(intlayerConfig));\n\n return plugins;\n};\n\n/**\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intlayer = intlayerPlugin;\n/**\n * @deprecated Rename to intlayer instead\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayer() ],\n * });\n * ```\n */\nexport const intLayerPlugin = intlayerPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAa,kBACX,kBACiB;CACjB,MAAM,iBAAiB,iBAAiB,cAAc;CAEtD,MAAM,QAAQ,SAAS;EACrB,eAAe;EACf,YAAY,UAAkB,QAAQ,MAAM;EAC7C,CAAC;CAEF,MAAM,gBAAgB,OAAO,KAAK,MAAM;CAExC,MAAMA,UAA0B,CAC9B;EACE,MAAM;EAEN,QAAQ,OAAO,QAAQ,QAAQ;GAC7B,MAAM,eACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAC1C,MAAM,iBAAiB,IAAI,YAAY;AAKvC,OAAI,gBAAgB,eAElB,OAAM,gBAAgB,gBAAgB;IACpC,OAAO;IACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;IACjB,CAAC;AAIJ,UAAO,UAAU;IACf,GAAG,OAAO;IACV,OAAO;KACL,GAAG,OAAO,SAAS;KACnB,GAAG;KACJ;IACF;AAED,UAAO,eAAe;IACpB,GAAG,OAAO;IACV,SAAS,CAAC,GAAI,OAAO,cAAc,WAAW,EAAE,EAAG,GAAG,cAAc;IACrE;AAED,UAAO;;EAGT,iBAAiB,OAAO,YAAY;AAClC,OAAI,eAAe,QAAQ,MAEzB,OAAM,EAAE,eAAe,gBAAgB,CAAC;;EAG7C,CACF;AAGD,SAAQ,KAAK,cAAc,eAAe,CAAC;AAE3C,QAAO;;;;;;;;;;;;AAaT,MAAa,WAAW;;;;;;;;;;;;;AAaxB,MAAa,iBAAiB"}
@@ -1,4 +1,6 @@
1
1
  import { join } from "node:path";
2
+ import { runOnce } from "@intlayer/chokidar";
3
+ import { getAppLogger } from "@intlayer/config";
2
4
  import { createRequire } from "node:module";
3
5
  import { intlayerBabelPlugin } from "@intlayer/babel";
4
6
  import { getDictionaries } from "@intlayer/dictionaries-entry";
@@ -8,17 +10,29 @@ import fg from "fast-glob";
8
10
  const intlayerPrune = (intlayerConfig) => {
9
11
  try {
10
12
  const babel = createRequire(import.meta.url)("@babel/core");
11
- const { optimize, importMode, traversePattern } = intlayerConfig.build;
12
- const { dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
13
+ const logger = getAppLogger(intlayerConfig);
14
+ const { importMode, traversePattern, optimize } = intlayerConfig.build;
15
+ const { dictionariesDir, dynamicDictionariesDir, unmergedDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
13
16
  const filesListPattern = fg.sync(traversePattern, { cwd: baseDir }).map((file) => join(baseDir, file));
14
17
  const dictionariesEntryPath = join(mainDir, "dictionaries.mjs");
18
+ const unmergedDictionariesEntryPath = join(mainDir, "unmerged_dictionaries.mjs");
15
19
  const dynamicDictionariesEntryPath = join(mainDir, "dynamic_dictionaries.mjs");
16
- const filesList = [...filesListPattern, dictionariesEntryPath];
20
+ const filesList = [
21
+ ...filesListPattern,
22
+ dictionariesEntryPath,
23
+ unmergedDictionariesEntryPath
24
+ ];
17
25
  const dictionaries = getDictionaries();
18
26
  const liveSyncKeys = Object.values(dictionaries).filter((dictionary) => dictionary.live).map((dictionary) => dictionary.key);
19
27
  return {
20
28
  name: "vite-intlayer-babel-transform",
21
29
  enforce: "post",
30
+ apply: (_config, env) => {
31
+ const isBuild = env.command === "build";
32
+ const isEnabled = optimize ?? isBuild;
33
+ if (isEnabled) runOnce(join(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Build optimization enabled"), { cacheTimeoutMs: 1e3 * 10 });
34
+ return isEnabled;
35
+ },
22
36
  transform(code, id) {
23
37
  /**
24
38
  * Transform file as
@@ -30,18 +44,19 @@ const intlayerPrune = (intlayerConfig) => {
30
44
  */
31
45
  const filename = id.split("?", 1)[0];
32
46
  if (!filesList.includes(filename)) return null;
33
- if (!optimize) return null;
34
47
  const result = babel.transformSync(code, {
35
48
  filename,
36
49
  plugins: [[intlayerBabelPlugin, {
37
50
  dictionariesDir,
38
51
  dictionariesEntryPath,
52
+ unmergedDictionariesEntryPath,
53
+ unmergedDictionariesDir,
39
54
  dynamicDictionariesDir,
40
55
  dynamicDictionariesEntryPath,
41
56
  fetchDictionariesDir,
42
57
  importMode,
43
58
  filesList,
44
- replaceDictionaryEntry: false,
59
+ replaceDictionaryEntry: true,
45
60
  liveSyncKeys
46
61
  }]],
47
62
  parserOpts: {
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerPrunePlugin.mjs","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport type { PluginOption } from 'vite';\n\nexport const intlayerPrune = (intlayerConfig: IntlayerConfig): PluginOption => {\n try {\n const localeRequire = createRequire(import.meta.url);\n const babel = localeRequire('@babel/core');\n\n const { optimize, importMode, traversePattern } = intlayerConfig.build;\n\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\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 ];\n\n const dictionaries = getDictionaries();\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after other transformations as vue\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 if (!filesList.includes(filename)) return null;\n if (!optimize) return null;\n\n const result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerBabelPlugin,\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n importMode,\n filesList,\n replaceDictionaryEntry: false,\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 } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n\n return null;\n }\n};\n"],"mappings":";;;;;;;AAQA,MAAa,iBAAiB,mBAAiD;AAC7E,KAAI;EAEF,MAAM,QADgB,cAAc,OAAO,KAAK,IAAI,CACxB,cAAc;EAE1C,MAAM,EAAE,UAAU,YAAY,oBAAoB,eAAe;EAEjE,MAAM,EACJ,iBACA,wBACA,sBACA,SACA,YACE,eAAe;EAEnB,MAAM,mBAAmB,GACtB,KAAK,iBAAiB,EACrB,KAAK,SACN,CAAC,CACD,KAAK,SAAS,KAAK,SAAS,KAAK,CAAC;EAErC,MAAM,wBAAwB,KAAK,SAAS,mBAAmB;EAC/D,MAAM,+BAA+B,KACnC,SACA,2BACD;EAED,MAAM,YAAY,CAChB,GAAG,kBACH,sBACD;EAED,MAAM,eAAe,iBAAiB;EACtC,MAAM,eAAe,OAAO,OAAO,aAAa,CAC7C,QAAQ,eAAe,WAAW,KAAK,CACvC,KAAK,eAAe,WAAW,IAAI;AAEtC,SAAO;GACL,MAAM;GACN,SAAS;GACT,UAAU,MAAM,IAAI;;;;;;;;;IASlB,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,QAAI,CAAC,UAAU,SAAS,SAAS,CAAE,QAAO;AAC1C,QAAI,CAAC,SAAU,QAAO;IAEtB,MAAM,SAAS,MAAM,cAAc,MAAM;KACvC;KACA,SAAS,CACP,CACE,qBACA;MACE;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;UACM,OAAO;AACd,UAAQ,KAAK,0CAA0C,MAAM;AAE7D,SAAO"}
1
+ {"version":3,"file":"intlayerPrunePlugin.mjs","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { runOnce } from '@intlayer/chokidar';\nimport { getAppLogger } from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport type { PluginOption } from 'vite';\n\nexport const intlayerPrune = (intlayerConfig: IntlayerConfig): 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 = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\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();\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\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 = optimize ?? isBuild;\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 result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerBabelPlugin,\n {\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 } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n\n return null;\n }\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,iBAAiB,mBAAiD;AAC7E,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,GACtB,KAAK,iBAAiB,EACrB,KAAK,SACN,CAAC,CACD,KAAK,SAAS,KAAK,SAAS,KAAK,CAAC;EAErC,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,iBAAiB;EACtC,MAAM,eAAe,OAAO,OAAO,aAAa,CAC7C,QAAQ,eAAe,WAAW,KAAK,CACvC,KAAK,eAAe,WAAW,IAAI;AAEtC,SAAO;GACL,MAAM;GACN,SAAS;GACT,QAAQ,SAAS,QAAQ;IAGvB,MAAM,UAAU,IAAI,YAAY;IAChC,MAAM,YAAY,YAAY;AAE9B,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,SAAS,MAAM,cAAc,MAAM;KACvC;KACA,SAAS,CACP,CACE,qBACA;MACE;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;UACM,OAAO;AACd,UAAQ,KAAK,0CAA0C,MAAM;AAE7D,SAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerPlugin.d.ts","names":[],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":[],"mappings":";;;;;;;AAuBA;AAiFA;AAaA;;;;;;;;cA9Fa,iCACK,4BACf;;;;;;;;;;;cA+EU,2BAhFK,4BACf;;;;;;;;;;;;;cA4FU,iCA7FK,4BACf"}
1
+ {"version":3,"file":"intlayerPlugin.d.ts","names":[],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":[],"mappings":";;;;;;;AAuBA;AA4EA;AAaA;;;;;;;;cAzFa,iCACK,4BACf;;;;;;;;;;;cA0EU,2BA3EK,4BACf;;;;;;;;;;;;;cAuFU,iCAxFK,4BACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerPrunePlugin.d.ts","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":[],"mappings":";;;;cAQa,gCAAiC,mBAAiB"}
1
+ {"version":3,"file":"intlayerPrunePlugin.d.ts","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":[],"mappings":";;;;cAUa,gCAAiC,mBAAiB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-intlayer",
3
- "version": "7.1.9",
3
+ "version": "7.2.2",
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": [
@@ -76,24 +76,24 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@babel/core": "7.28.4",
79
- "@intlayer/babel": "7.1.9",
80
- "@intlayer/chokidar": "7.1.9",
81
- "@intlayer/config": "7.1.9",
82
- "@intlayer/core": "7.1.9",
83
- "@intlayer/dictionaries-entry": "7.1.9",
84
- "@intlayer/types": "7.1.9",
79
+ "@intlayer/babel": "7.2.2",
80
+ "@intlayer/chokidar": "7.2.2",
81
+ "@intlayer/config": "7.2.2",
82
+ "@intlayer/core": "7.2.1",
83
+ "@intlayer/dictionaries-entry": "7.2.2",
84
+ "@intlayer/types": "7.2.2",
85
85
  "fast-glob": "3.3.3",
86
- "intlayer": "7.1.9"
86
+ "intlayer": "7.2.2"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@types/node": "24.10.1",
90
90
  "@utils/ts-config": "1.0.4",
91
91
  "@utils/ts-config-types": "1.0.4",
92
92
  "@utils/tsdown-config": "1.0.4",
93
- "rimraf": "6.1.0",
94
- "tsdown": "0.16.5",
93
+ "rimraf": "6.1.2",
94
+ "tsdown": "0.16.6",
95
95
  "typescript": "5.9.3",
96
- "vitest": "4.0.10"
96
+ "vitest": "4.0.12"
97
97
  },
98
98
  "peerDependencies": {
99
99
  "@babel/core": ">=6.0.0",