vite-intlayer 9.4.3 → 9.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 +0 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/intlayerOptimizePlugin.mjs +1 -1
- package/dist/esm/intlayerOptimizePlugin.mjs.map +1 -1
- package/dist/esm/intlayerPlugin.mjs +13 -2
- package/dist/esm/intlayerPlugin.mjs.map +1 -1
- package/dist/types/IntlayerCompilerPlugin.d.ts +2 -3
- package/dist/types/IntlayerCompilerPlugin.d.ts.map +1 -1
- package/dist/types/dedupePlugin.d.ts +2 -3
- package/dist/types/dedupePlugin.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/intlayerChunkPlugin.d.ts +7 -8
- package/dist/types/intlayerChunkPlugin.d.ts.map +1 -1
- package/dist/types/intlayerMinifyPlugin.d.ts +1 -2
- package/dist/types/intlayerMinifyPlugin.d.ts.map +1 -1
- package/dist/types/intlayerOptimizePlugin.d.ts +1 -2
- package/dist/types/intlayerOptimizePlugin.d.ts.map +1 -1
- package/dist/types/intlayerPlugin.d.ts +15 -5
- package/dist/types/intlayerPlugin.d.ts.map +1 -1
- package/dist/types/intlayerPreloadPlugin.d.ts +1 -2
- package/dist/types/intlayerPreloadPlugin.d.ts.map +1 -1
- package/dist/types/intlayerProxyHandler.d.ts +3 -4
- package/dist/types/intlayerProxyHandler.d.ts.map +1 -1
- package/dist/types/intlayerProxyPlugin.d.ts +5 -6
- package/dist/types/intlayerProxyPlugin.d.ts.map +1 -1
- package/dist/types/intlayerPrunePlugin.d.ts +1 -2
- package/dist/types/intlayerPrunePlugin.d.ts.map +1 -1
- package/dist/types/intlayerVueAsyncPlugin.d.ts +1 -2
- package/dist/types/intlayerVueAsyncPlugin.d.ts.map +1 -1
- package/package.json +12 -12
- package/dist/esm/pruneContext.mjs +0 -15
- package/dist/esm/pruneContext.mjs.map +0 -1
- package/dist/types/pruneContext.d.ts +0 -6
- package/dist/types/pruneContext.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -69,8 +69,6 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
69
69
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
|
|
70
70
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
|
|
71
71
|
|
|
72
|
-
---
|
|
73
|
-
|
|
74
72
|
## 📦 Installation
|
|
75
73
|
|
|
76
74
|
Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -5,6 +5,6 @@ import { createDictionaryModuleParser, intlayerChunk, resolveBoundaries, toBound
|
|
|
5
5
|
import { intlayerOptimize } from "./intlayerOptimizePlugin.mjs";
|
|
6
6
|
import { intlayerPreload } from "./intlayerPreloadPlugin.mjs";
|
|
7
7
|
import { createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy } from "./intlayerProxyPlugin.mjs";
|
|
8
|
-
import { intLayerPlugin, intlayer, intlayerPlugin } from "./intlayerPlugin.mjs";
|
|
8
|
+
import { INTLAYER_NO_EXTERNAL_PATTERN, intLayerPlugin, intlayer, intlayerPlugin } from "./intlayerPlugin.mjs";
|
|
9
9
|
|
|
10
|
-
export { createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, toBoundaryName };
|
|
10
|
+
export { INTLAYER_NO_EXTERNAL_PATTERN, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, toBoundaryName };
|
|
@@ -289,7 +289,7 @@ const intlayerOptimize = async (intlayerConfig, pruneContext, compatCallers) =>
|
|
|
289
289
|
fetchDictionariesEntryPath: join(mainDir, "fetch_dictionaries.mjs"),
|
|
290
290
|
importMode,
|
|
291
291
|
filesList: transformableFilesList,
|
|
292
|
-
replaceDictionaryEntry:
|
|
292
|
+
replaceDictionaryEntry: isBuildOptimizeEnabled(null, { command: "build" }),
|
|
293
293
|
nestingDictionaryKeys,
|
|
294
294
|
dictionaryModeMap: dictionaryKeyToImportModeMap,
|
|
295
295
|
isServer: options?.ssr === true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerOptimizePlugin.mjs","names":[],"sources":["../../src/intlayerOptimizePlugin.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport {\n analyzeFieldUsageInFile,\n buildNestedRenameMapFromContent,\n buildUsageCheckRegex,\n type CallerDescriptor,\n getNestedRenameEntryAtPath,\n INTLAYER_USAGE_REGEX,\n optimizeSourceFile,\n type PruneContext,\n preserveNestedDictionaryFields,\n renameFieldsInSourceFile,\n SOURCE_FILE_REGEX,\n} from '@intlayer/babel';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { IMPORT_MODE } from '@intlayer/config/defaultValues';\nimport {\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { normalizePath } from '@intlayer/config/utils';\nimport {\n getNestedDictionaryGraph,\n getNestedDictionaryReferences,\n} from '@intlayer/core/dictionaryManipulator';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport {\n buildComponentFilesList,\n formatPath,\n runOnce,\n} from '@intlayer/engine/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { PluginOption } from 'vite';\nimport { intlayerVueAsyncPlugin } from './intlayerVueAsyncPlugin';\n\n// Plugin\n\n/**\n * Returns the Vite plugins responsible for the build optimisation step.\n *\n * Contains three internal plugins:\n *\n * 1. Vue async plugin – handles Vue SFC async script blocks.\n * 2. Usage analyser (`vite-intlayer-usage-analyzer`) – pre-scans every\n * component source file during `buildStart` to build the field-usage map\n * in `pruneContext`. This runs before any `transform` calls so the\n * downstream prune plugin always has complete data.\n * 3. Babel transform (`vite-intlayer-babel-transform`) – rewrites\n * `useIntlayer('key')` / `getIntlayer('key')` calls into\n * `useDictionary(_hash)` / `getDictionary(_hash)` and injects the\n * corresponding JSON (or dynamic `.mjs`) imports. Also applies field-name\n * renaming when `build.minify` is enabled.\n *\n * @param intlayerConfig - Resolved intlayer configuration.\n * @param pruneContext - Shared mutable state written here and read by the\n * prune and minify plugins. Pass `null` to skip\n * analysis (e.g. when both `purge` and `minify` are\n * disabled).\n */\nexport const intlayerOptimize = async (\n intlayerConfig: IntlayerConfig,\n pruneContext: PruneContext | null,\n compatCallers?: CallerDescriptor[]\n): Promise<PluginOption[]> => {\n try {\n const logger = getAppLogger(intlayerConfig);\n\n const { optimize, purge, minify } = intlayerConfig.build;\n const editorEnabled = intlayerConfig.editor.enabled;\n\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n unmergedDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.system;\n\n const dictionariesEntryPath = normalizePath(\n join(mainDir, 'dictionaries.mjs')\n );\n const unmergedDictionariesEntryPath = normalizePath(\n join(mainDir, 'unmerged_dictionaries.mjs')\n );\n const dynamicDictionariesEntryPath = normalizePath(\n join(mainDir, 'dynamic_dictionaries.mjs')\n );\n\n const componentFilesList =\n buildComponentFilesList(intlayerConfig).map(normalizePath);\n\n const transformableFilesList = [\n ...componentFilesList,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const dictionaryKeyToImportModeMap: Record<\n string,\n 'static' | 'dynamic' | 'fetch'\n > = {};\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryKeyToImportModeMap[dictionary.key] =\n dictionary.importMode ?? importMode ?? IMPORT_MODE;\n });\n\n // Dictionaries pulled in by `nest()`: resolved at runtime by `getNesting`\n // through the dictionary registry, never by a `useIntlayer` call site.\n const nestedDictionaryReferences = getNestedDictionaryReferences(\n Object.values(dictionaries)\n );\n\n // Dictionaries holding `nest()` references: their static import is\n // re-pointed at the companion module carrying the nest targets.\n const nestingDictionaryKeys = [\n ...getNestedDictionaryGraph(Object.values(dictionaries)).keys(),\n ];\n\n const isBuildOptimizeEnabled = (\n _config: unknown,\n env: { command: string }\n ) => {\n const isBuildCommand = env.command === 'build';\n return (optimize === undefined && isBuildCommand) || optimize === true;\n };\n\n // Field renaming rewrites the content keys the interpreter walks, so the\n // `keyPath` reported by `ContentSelector` would no longer resolve against\n // the unmerged dictionaries the visual editor edits. Purging and the\n // keyPath-neutral part of minification stay active while the editor is on.\n const isFieldRenameEnabled = !editorEnabled && !!minify;\n\n const isAnalysisEnabled = (_config: unknown, env: { command: string }) =>\n (!!purge || !!minify) && isBuildOptimizeEnabled(_config, env);\n\n let partiallyMinifiedDictionariesCount = 0;\n\n return [\n intlayerVueAsyncPlugin(intlayerConfig, transformableFilesList),\n\n // Plugin 1: Usage analyser\n {\n name: 'vite-intlayer-usage-analyzer',\n enforce: 'pre',\n apply: isAnalysisEnabled,\n\n buildStart: async () => {\n if (!pruneContext) return;\n\n const extraCallerNames = (compatCallers ?? []).map(\n (caller) => caller.callerName\n );\n const usageCheckRegex = buildUsageCheckRegex(extraCallerNames);\n\n // Phase 1: Babel-based field-usage analysis for all component files\n await Promise.all(\n componentFilesList.map(async (sourceFilePath) => {\n if (!SOURCE_FILE_REGEX.test(sourceFilePath)) return;\n\n let sourceCode: string;\n try {\n sourceCode = await readFile(sourceFilePath, 'utf-8');\n } catch {\n return; // unreadable file – skip silently\n }\n\n if (!usageCheckRegex.test(sourceCode)) return;\n\n // For Vue/Svelte SFCs, the usage analyzer expects the raw script\n // content. `analyzeFieldUsageInFile` handles block extraction\n // internally via `extractScriptBlocks`.\n try {\n await analyzeFieldUsageInFile(\n sourceFilePath,\n sourceCode,\n pruneContext,\n compatCallers\n );\n } catch (parseError) {\n pruneContext.hasUnparsableSourceFiles = true;\n logger(\n [\n `Could not parse`,\n formatPath(sourceFilePath),\n `for field-usage analysis.`,\n 'Dictionaries whose usage cannot be confirmed will not be pruned.',\n parseError instanceof Error\n ? `(${parseError.message})`\n : String(parseError),\n ],\n { level: 'warn' }\n );\n }\n })\n );\n\n // Phase 2: Framework-specific analysis for Vue / Svelte / Astro SFC\n // bindings that Babel scope analysis cannot resolve:\n // Vue → `.value` ref-accessor indirection\n // Svelte → `$` reactive store prefix\n // Astro → frontmatter variables referenced in the HTML template\n if (pruneContext.pendingFrameworkAnalysis.size > 0) {\n const vuePending = new Map<\n string,\n { variableName: string; dictionaryKey: string }[]\n >();\n const sveltePending = new Map<\n string,\n { variableName: string; dictionaryKey: string }[]\n >();\n const astroPending = new Map<\n string,\n { variableName: string; dictionaryKey: string }[]\n >();\n\n for (const [\n filePath,\n entries,\n ] of pruneContext.pendingFrameworkAnalysis) {\n if (filePath.endsWith('.vue')) {\n vuePending.set(filePath, entries);\n } else if (filePath.endsWith('.svelte')) {\n sveltePending.set(filePath, entries);\n } else if (filePath.endsWith('.astro')) {\n astroPending.set(filePath, entries);\n }\n }\n\n /** Merge framework-extracted field usage into pruneContext. */\n const mergeFrameworkResult = (\n dictionaryKey: string,\n fields: Set<string> | undefined\n ): void => {\n if (fields && fields.size > 0) {\n // The Babel rename plugin cannot update source-code property\n // accesses for SFC indirect patterns → suppress field renaming.\n pruneContext.dictionariesSkippingFieldRename.add(dictionaryKey);\n\n const existing =\n pruneContext.dictionaryKeyToFieldUsageMap.get(dictionaryKey);\n if (existing === 'all') return;\n\n const merged =\n existing instanceof Set\n ? new Set([...existing, ...fields])\n : new Set(fields);\n pruneContext.dictionaryKeyToFieldUsageMap.set(\n dictionaryKey,\n merged\n );\n } else {\n pruneContext.dictionaryKeyToFieldUsageMap.set(\n dictionaryKey,\n 'all'\n );\n }\n };\n\n // Vue files\n if (vuePending.size > 0) {\n let extractVueIntlayerFieldUsage:\n | ((\n code: string,\n vars: { variableName: string; dictionaryKey: string }[]\n ) => Map<string, Set<string>>)\n | null = null;\n\n try {\n const vueCompiler = await import('@intlayer/vue-compiler');\n extractVueIntlayerFieldUsage =\n vueCompiler.extractVueIntlayerFieldUsage;\n } catch {\n // @intlayer/vue-compiler not installed – fall back to 'all'\n }\n\n for (const [filePath, entries] of vuePending) {\n if (!extractVueIntlayerFieldUsage) {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n let fileCode: string;\n try {\n fileCode = await readFile(filePath, 'utf-8');\n } catch {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n const result = extractVueIntlayerFieldUsage(fileCode, entries);\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(\n dictionaryKey,\n result.get(dictionaryKey)\n );\n }\n }\n }\n\n // Svelte files\n if (sveltePending.size > 0) {\n let extractSvelteIntlayerFieldUsage:\n | ((\n code: string,\n vars: { variableName: string; dictionaryKey: string }[]\n ) => Map<string, Set<string>>)\n | null = null;\n\n try {\n const svelteCompiler = await import(\n '@intlayer/svelte-compiler'\n );\n extractSvelteIntlayerFieldUsage =\n svelteCompiler.extractSvelteIntlayerFieldUsage;\n } catch {\n // @intlayer/svelte-compiler not installed – fall back to 'all'\n }\n\n for (const [filePath, entries] of sveltePending) {\n if (!extractSvelteIntlayerFieldUsage) {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n let fileCode: string;\n try {\n fileCode = await readFile(filePath, 'utf-8');\n } catch {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n const result = extractSvelteIntlayerFieldUsage(\n fileCode,\n entries\n );\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(\n dictionaryKey,\n result.get(dictionaryKey)\n );\n }\n }\n }\n\n // Astro files\n // Frontmatter variables are used in the HTML template, which is not\n // visible to Babel's scope analysis. Scan the template section for\n // `variableName.fieldName` accesses using a lightweight regex pass.\n if (astroPending.size > 0) {\n for (const [filePath, entries] of astroPending) {\n let fileCode: string;\n try {\n fileCode = await readFile(filePath, 'utf-8');\n } catch {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n // Extract only the template (everything after the closing ---).\n // The frontmatter was already handled by Babel in Phase 1.\n const fenceMatch = /^---\\r?\\n[\\s\\S]*?\\r?\\n---/.exec(fileCode);\n const template = fenceMatch\n ? fileCode.slice(fenceMatch.index + fenceMatch[0].length)\n : fileCode;\n\n for (const { variableName, dictionaryKey } of entries) {\n const escapedVar = variableName.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n '\\\\$&'\n );\n const fieldRe = new RegExp(\n `\\\\b${escapedVar}\\\\.([a-zA-Z_$][a-zA-Z0-9_$]*)`,\n 'g'\n );\n const foundFields = new Set<string>();\n let m = fieldRe.exec(template);\n while (m !== null) {\n foundFields.add(m[1]!);\n m = fieldRe.exec(template);\n }\n mergeFrameworkResult(\n dictionaryKey,\n foundFields.size > 0 ? foundFields : undefined\n );\n }\n }\n }\n }\n\n // Phase 2.5: Keep `nest()` targets resolvable — must run before the\n // rename maps of Phase 4 are built.\n preserveNestedDictionaryFields(\n pruneContext,\n nestedDictionaryReferences\n );\n\n // Phase 3: Warn about untracked bindings (plain variable assignments)\n for (const [\n dictionaryKey,\n sourceFilePaths,\n ] of pruneContext.dictionaryKeysWithUntrackedBindings) {\n logger(\n [\n `Dictionary`,\n colorizeKey(dictionaryKey),\n `cannot be purged or minified.`,\n `\\n Reason: the result of`,\n `${colorize(`useIntlayer(`, ANSIColors.GREY_LIGHT)}${colorizeKey(\n `'${dictionaryKey}'`\n )}${colorize(`)`, ANSIColors.GREY_LIGHT)}`,\n `is assigned to a plain variable in:`,\n ...sourceFilePaths.map(\n (filePath) => `\\n - ${formatPath(filePath)}`\n ),\n ],\n { level: 'warn' }\n );\n }\n\n // Phase 4: Build field-rename map for minification\n // Reads each compiled dictionary JSON to discover the full nested\n // user-defined field structure, then builds a NestedRenameMap that\n // assigns short alphabetic aliases at every level.\n if (isFieldRenameEnabled) {\n for (const [\n dictionaryKey,\n fieldUsage,\n ] of pruneContext.dictionaryKeyToFieldUsageMap) {\n if (fieldUsage === 'all') continue;\n\n // Fetch-mode dictionaries are served from a remote API using\n // original field names – renaming would break the client/server\n // contract.\n if (dictionaryKeyToImportModeMap[dictionaryKey] === 'fetch')\n continue;\n\n // SFC indirect access: skip field rename for these dictionaries\n // to avoid a JSON ↔ source mismatch at runtime.\n if (\n pruneContext.dictionariesSkippingFieldRename.has(dictionaryKey)\n )\n continue;\n\n // Read dictionary content (static JSON first, then dynamic per-locale)\n let dictionaryContent: unknown = null;\n\n const staticJsonPath = join(\n dictionariesDir,\n `${dictionaryKey}.json`\n );\n try {\n const raw = await readFile(staticJsonPath, 'utf-8');\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n dictionaryContent = parsed.content;\n } catch {\n try {\n const dynamicDir = join(\n dynamicDictionariesDir,\n dictionaryKey\n );\n const localeFiles = await readdir(dynamicDir);\n const firstJsonFile = localeFiles.find((f) =>\n f.endsWith('.json')\n );\n if (firstJsonFile) {\n const raw = await readFile(\n join(dynamicDir, firstJsonFile),\n 'utf-8'\n );\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n dictionaryContent = parsed.content;\n }\n } catch {\n // Dictionary file not readable – skip rename for this key\n }\n }\n\n if (!dictionaryContent) continue;\n\n // Build the rename map from ALL user-defined fields in the\n // dictionary — not just the ones statically consumed by source\n // files. Using the full set ensures that:\n // 1. Every field in the compiled JSON is renamed (even if\n // pruned-out fields still appear when purge is disabled).\n // 2. The short-name assignment is stable: the alphabetical\n // order of all fields determines each short name, so adding\n // or removing a consumer never changes names for others.\n // 3. There is no source ↔ JSON mismatch: both sides use the\n // identical map regardless of which subset is consumed.\n const nestedRenameMap =\n buildNestedRenameMapFromContent(dictionaryContent);\n\n // Skip renaming below opaque values that have nested\n // user-defined structure – renaming those sub-keys would\n // silently break child components that consume the value as-is.\n const opaqueFieldMap =\n pruneContext.dictionaryKeysWithOpaqueFields.get(dictionaryKey);\n\n if (opaqueFieldMap) {\n const dangerousOccurrences = [\n ...opaqueFieldMap.values(),\n ].filter(\n (occurrence) =>\n (getNestedRenameEntryAtPath(\n nestedRenameMap,\n occurrence.fieldPath\n )?.children.size ?? 0) > 0\n );\n if (dangerousOccurrences.length > 0) {\n partiallyMinifiedDictionariesCount += 1;\n\n logger(\n [\n `Dictionary`,\n colorizeKey(dictionaryKey),\n `partially minified.`,\n ...dangerousOccurrences.flatMap((occurrence) => [\n `\\n Opaque field:`,\n colorize(\n `'${occurrence.fieldPath.join('.')}'`,\n ANSIColors.BLUE\n ),\n `(nested keys preserved for stability).`,\n ...occurrence.locations.map(\n (loc) => `\\n at ${formatPath(loc)}`\n ),\n ]),\n ],\n { level: 'warn', isVerbose: true }\n );\n\n // Disable renaming for the children of opaque values to\n // prevent breaking components that receive the value as a\n // prop.\n for (const occurrence of dangerousOccurrences) {\n const entry = getNestedRenameEntryAtPath(\n nestedRenameMap,\n occurrence.fieldPath\n );\n if (entry) {\n entry.children = new Map();\n }\n }\n }\n }\n\n if (nestedRenameMap.size > 0) {\n pruneContext.dictionaryKeyToFieldRenameMap.set(\n dictionaryKey,\n nestedRenameMap\n );\n }\n }\n\n if (partiallyMinifiedDictionariesCount > 0) {\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-partial-minify-summary.lock'\n ),\n () => {\n logger([\n `Partially minified`,\n colorizeNumber(partiallyMinifiedDictionariesCount),\n `dictionar${partiallyMinifiedDictionariesCount === 1 ? 'y' : 'ies'}`,\n `(preserved nested keys for opaque fields).`,\n ]);\n },\n { cacheTimeoutMs: 1000 * 5 }\n );\n }\n }\n },\n },\n\n // Plugin 2: Babel transform\n {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after framework transformations (e.g. Vue SFC)\n apply: (_config, env) => {\n const isBuildCommand = env.command === 'build';\n const isEnabled =\n (optimize === undefined && isBuildCommand) || optimize === true;\n\n if (!isBuildCommand || !isEnabled) return false;\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-optimize-plugin-enabled.lock'\n ),\n () => {\n logger([\n `Build optimization ${colorize('enabled', ANSIColors.GREEN)}`,\n colorize('(import mode:', ANSIColors.GREY_DARK),\n colorize(importMode ?? IMPORT_MODE, ANSIColors.BLUE),\n colorize(')', ANSIColors.GREY_DARK),\n ]);\n\n // The minify plugin reports the field-rename step standing down\n // when the editor is enabled, so this line stays a plain one.\n if (minify) {\n logger(\n `Dictionary minification ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n\n if (purge) {\n logger(\n `Dictionary purge unused keys ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n },\n { cacheTimeoutMs: 1000 * 10 }\n );\n\n return true;\n },\n\n transform: async (sourceCode, moduleId, options) => {\n // Strip query parameters added by Vue/Svelte loaders\n // e.g. \"HelloWorld.vue?vue&type=script&setup=true&lang.ts\" → \"HelloWorld.vue\"\n const sourceFilePath = normalizePath(\n moduleId.split('?', 1)[0] ?? moduleId\n );\n\n if (!SOURCE_FILE_REGEX.test(sourceFilePath)) return null;\n if (!transformableFilesList.includes(sourceFilePath)) return null;\n\n const isDictionaryEntryFile = [\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n ].includes(sourceFilePath);\n\n // Match native intlayer calls plus any configured compat callers\n // (`useTranslation`, `useTranslations`, …) so compat-only files are\n // still optimized.\n const optimizeUsageRegex = compatCallers?.length\n ? buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n )\n : INTLAYER_USAGE_REGEX;\n\n const isUsingIntlayer = optimizeUsageRegex.test(sourceCode);\n if (!isUsingIntlayer && !isDictionaryEntryFile) return null;\n\n // Step 1: Field rename (must run before the optimize pass, which\n // replaces useIntlayer → useDictionary and erases the dictionary key)\n let codeToOptimize = sourceCode;\n\n if (isFieldRenameEnabled && pruneContext && isUsingIntlayer) {\n const renamedCode = await renameFieldsInSourceFile(\n sourceFilePath,\n sourceCode,\n pruneContext\n );\n if (renamedCode) {\n codeToOptimize = renamedCode;\n }\n }\n\n // Step 2: Optimize (useIntlayer('key') → useDictionary(_hash))\n const transformResult = await optimizeSourceFile(\n codeToOptimize,\n sourceFilePath,\n {\n optimize,\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath: join(\n mainDir,\n 'fetch_dictionaries.mjs'\n ),\n importMode,\n filesList: transformableFilesList,\n // When compat callers are configured, they call `getIntlayer` at\n // runtime which reads from `dictionaries.mjs`. Emptying that module\n // would break all compat runtime lookups, so we preserve it.\n replaceDictionaryEntry: !compatCallers?.length,\n nestingDictionaryKeys,\n dictionaryModeMap: dictionaryKeyToImportModeMap,\n isServer: options?.ssr === true,\n compatCallers,\n }\n );\n\n if (!transformResult) return null;\n\n return {\n code: transformResult.code,\n map: transformResult.map as any,\n };\n },\n },\n ];\n } catch (pluginInitError) {\n console.warn(\n '[vite-intlayer] Failed to initialise optimization plugin:',\n pluginInitError\n );\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,mBAAmB,OAC9B,gBACA,cACA,kBAC4B;CAC5B,IAAI;EACF,MAAM,SAAS,aAAa,cAAc;EAE1C,MAAM,EAAE,UAAU,OAAO,WAAW,eAAe;EACnD,MAAM,gBAAgB,eAAe,OAAO;EAE5C,MAAM,aACJ,eAAe,MAAM,cAAc,eAAe,YAAY;EAEhE,MAAM,EACJ,iBACA,wBACA,yBACA,sBACA,SACA,YACE,eAAe;EAEnB,MAAM,wBAAwB,cAC5B,KAAK,SAAS,kBAAkB,CAClC;EACA,MAAM,gCAAgC,cACpC,KAAK,SAAS,2BAA2B,CAC3C;EACA,MAAM,+BAA+B,cACnC,KAAK,SAAS,0BAA0B,CAC1C;EAEA,MAAM,qBACJ,wBAAwB,cAAc,CAAC,CAAC,IAAI,aAAa;EAE3D,MAAM,yBAAyB;GAC7B,GAAG;GACH;GACA;EACF;EAEA,MAAM,eAAe,gBAAgB,cAAc;EAEnD,MAAM,+BAGF,CAAC;EACL,AAAC,OAAO,OAAO,YAAY,CAAC,CAAkB,SAAS,eAAe;GACpE,6BAA6B,WAAW,OACtC,WAAW,cAAc,cAAc;EAC3C,CAAC;EAID,MAAM,6BAA6B,8BACjC,OAAO,OAAO,YAAY,CAC5B;EAIA,MAAM,wBAAwB,CAC5B,GAAG,yBAAyB,OAAO,OAAO,YAAY,CAAC,CAAC,CAAC,KAAK,CAChE;EAEA,MAAM,0BACJ,SACA,QACG;GACH,MAAM,iBAAiB,IAAI,YAAY;GACvC,OAAQ,aAAa,UAAa,kBAAmB,aAAa;EACpE;EAMA,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qBAEsC,CAAC,KAAK,UAAU;KAC1D,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,OAAO;KAIvD,IAAI,iBAAiB;KAErB,IAAI,wBAAwB,gBAAgB,iBAAiB;MAC3D,MAAM,cAAc,MAAM,yBACxB,gBACA,YACA,YACF;MACA,IAAI,aACF,iBAAiB;KAErB;KAGA,MAAM,kBAAkB,MAAM,mBAC5B,gBACA,gBACA;MACE;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,4BAA4B,KAC1B,SACA,wBACF;MACA;MACA,WAAW;MAIX,wBAAwB,CAAC,eAAe;MACxC;MACA,mBAAmB;MACnB,UAAU,SAAS,QAAQ;MAC3B;KACF,CACF;KAEA,IAAI,CAAC,iBAAiB,OAAO;KAE7B,OAAO;MACL,MAAM,gBAAgB;MACtB,KAAK,gBAAgB;KACvB;IACF;GACF;EACF;CACF,SAAS,iBAAiB;EACxB,QAAQ,KACN,6DACA,eACF;EACA,OAAO,CAAC;CACV;AACF"}
|
|
1
|
+
{"version":3,"file":"intlayerOptimizePlugin.mjs","names":[],"sources":["../../src/intlayerOptimizePlugin.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport {\n analyzeFieldUsageInFile,\n buildNestedRenameMapFromContent,\n buildUsageCheckRegex,\n type CallerDescriptor,\n getNestedRenameEntryAtPath,\n INTLAYER_USAGE_REGEX,\n optimizeSourceFile,\n type PruneContext,\n preserveNestedDictionaryFields,\n renameFieldsInSourceFile,\n SOURCE_FILE_REGEX,\n} from '@intlayer/babel';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { IMPORT_MODE } from '@intlayer/config/defaultValues';\nimport {\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { normalizePath } from '@intlayer/config/utils';\nimport {\n getNestedDictionaryGraph,\n getNestedDictionaryReferences,\n} from '@intlayer/core/dictionaryManipulator';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport {\n buildComponentFilesList,\n formatPath,\n runOnce,\n} from '@intlayer/engine/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { PluginOption } from 'vite';\nimport { intlayerVueAsyncPlugin } from './intlayerVueAsyncPlugin';\n\n// Plugin\n\n/**\n * Returns the Vite plugins responsible for the build optimisation step.\n *\n * Contains three internal plugins:\n *\n * 1. Vue async plugin – handles Vue SFC async script blocks.\n * 2. Usage analyser (`vite-intlayer-usage-analyzer`) – pre-scans every\n * component source file during `buildStart` to build the field-usage map\n * in `pruneContext`. This runs before any `transform` calls so the\n * downstream prune plugin always has complete data.\n * 3. Babel transform (`vite-intlayer-babel-transform`) – rewrites\n * `useIntlayer('key')` / `getIntlayer('key')` calls into\n * `useDictionary(_hash)` / `getDictionary(_hash)` and injects the\n * corresponding JSON (or dynamic `.mjs`) imports. Also applies field-name\n * renaming when `build.minify` is enabled.\n *\n * @param intlayerConfig - Resolved intlayer configuration.\n * @param pruneContext - Shared mutable state written here and read by the\n * prune and minify plugins. Pass `null` to skip\n * analysis (e.g. when both `purge` and `minify` are\n * disabled).\n */\nexport const intlayerOptimize = async (\n intlayerConfig: IntlayerConfig,\n pruneContext: PruneContext | null,\n compatCallers?: CallerDescriptor[]\n): Promise<PluginOption[]> => {\n try {\n const logger = getAppLogger(intlayerConfig);\n\n const { optimize, purge, minify } = intlayerConfig.build;\n const editorEnabled = intlayerConfig.editor.enabled;\n\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n unmergedDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.system;\n\n const dictionariesEntryPath = normalizePath(\n join(mainDir, 'dictionaries.mjs')\n );\n const unmergedDictionariesEntryPath = normalizePath(\n join(mainDir, 'unmerged_dictionaries.mjs')\n );\n const dynamicDictionariesEntryPath = normalizePath(\n join(mainDir, 'dynamic_dictionaries.mjs')\n );\n\n const componentFilesList =\n buildComponentFilesList(intlayerConfig).map(normalizePath);\n\n const transformableFilesList = [\n ...componentFilesList,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const dictionaryKeyToImportModeMap: Record<\n string,\n 'static' | 'dynamic' | 'fetch'\n > = {};\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryKeyToImportModeMap[dictionary.key] =\n dictionary.importMode ?? importMode ?? IMPORT_MODE;\n });\n\n // Dictionaries pulled in by `nest()`: resolved at runtime by `getNesting`\n // through the dictionary registry, never by a `useIntlayer` call site.\n const nestedDictionaryReferences = getNestedDictionaryReferences(\n Object.values(dictionaries)\n );\n\n // Dictionaries holding `nest()` references: their static import is\n // re-pointed at the companion module carrying the nest targets.\n const nestingDictionaryKeys = [\n ...getNestedDictionaryGraph(Object.values(dictionaries)).keys(),\n ];\n\n const isBuildOptimizeEnabled = (\n _config: unknown,\n env: { command: string }\n ) => {\n const isBuildCommand = env.command === 'build';\n return (optimize === undefined && isBuildCommand) || optimize === true;\n };\n\n // Field renaming rewrites the content keys the interpreter walks, so the\n // `keyPath` reported by `ContentSelector` would no longer resolve against\n // the unmerged dictionaries the visual editor edits. Purging and the\n // keyPath-neutral part of minification stay active while the editor is on.\n const isFieldRenameEnabled = !editorEnabled && !!minify;\n\n const isAnalysisEnabled = (_config: unknown, env: { command: string }) =>\n (!!purge || !!minify) && isBuildOptimizeEnabled(_config, env);\n\n let partiallyMinifiedDictionariesCount = 0;\n\n return [\n intlayerVueAsyncPlugin(intlayerConfig, transformableFilesList),\n\n // Plugin 1: Usage analyser\n {\n name: 'vite-intlayer-usage-analyzer',\n enforce: 'pre',\n apply: isAnalysisEnabled,\n\n buildStart: async () => {\n if (!pruneContext) return;\n\n const extraCallerNames = (compatCallers ?? []).map(\n (caller) => caller.callerName\n );\n const usageCheckRegex = buildUsageCheckRegex(extraCallerNames);\n\n // Phase 1: Babel-based field-usage analysis for all component files\n await Promise.all(\n componentFilesList.map(async (sourceFilePath) => {\n if (!SOURCE_FILE_REGEX.test(sourceFilePath)) return;\n\n let sourceCode: string;\n try {\n sourceCode = await readFile(sourceFilePath, 'utf-8');\n } catch {\n return; // unreadable file – skip silently\n }\n\n if (!usageCheckRegex.test(sourceCode)) return;\n\n // For Vue/Svelte SFCs, the usage analyzer expects the raw script\n // content. `analyzeFieldUsageInFile` handles block extraction\n // internally via `extractScriptBlocks`.\n try {\n await analyzeFieldUsageInFile(\n sourceFilePath,\n sourceCode,\n pruneContext,\n compatCallers\n );\n } catch (parseError) {\n pruneContext.hasUnparsableSourceFiles = true;\n logger(\n [\n `Could not parse`,\n formatPath(sourceFilePath),\n `for field-usage analysis.`,\n 'Dictionaries whose usage cannot be confirmed will not be pruned.',\n parseError instanceof Error\n ? `(${parseError.message})`\n : String(parseError),\n ],\n { level: 'warn' }\n );\n }\n })\n );\n\n // Phase 2: Framework-specific analysis for Vue / Svelte / Astro SFC\n // bindings that Babel scope analysis cannot resolve:\n // Vue → `.value` ref-accessor indirection\n // Svelte → `$` reactive store prefix\n // Astro → frontmatter variables referenced in the HTML template\n if (pruneContext.pendingFrameworkAnalysis.size > 0) {\n const vuePending = new Map<\n string,\n { variableName: string; dictionaryKey: string }[]\n >();\n const sveltePending = new Map<\n string,\n { variableName: string; dictionaryKey: string }[]\n >();\n const astroPending = new Map<\n string,\n { variableName: string; dictionaryKey: string }[]\n >();\n\n for (const [\n filePath,\n entries,\n ] of pruneContext.pendingFrameworkAnalysis) {\n if (filePath.endsWith('.vue')) {\n vuePending.set(filePath, entries);\n } else if (filePath.endsWith('.svelte')) {\n sveltePending.set(filePath, entries);\n } else if (filePath.endsWith('.astro')) {\n astroPending.set(filePath, entries);\n }\n }\n\n /** Merge framework-extracted field usage into pruneContext. */\n const mergeFrameworkResult = (\n dictionaryKey: string,\n fields: Set<string> | undefined\n ): void => {\n if (fields && fields.size > 0) {\n // The Babel rename plugin cannot update source-code property\n // accesses for SFC indirect patterns → suppress field renaming.\n pruneContext.dictionariesSkippingFieldRename.add(dictionaryKey);\n\n const existing =\n pruneContext.dictionaryKeyToFieldUsageMap.get(dictionaryKey);\n if (existing === 'all') return;\n\n const merged =\n existing instanceof Set\n ? new Set([...existing, ...fields])\n : new Set(fields);\n pruneContext.dictionaryKeyToFieldUsageMap.set(\n dictionaryKey,\n merged\n );\n } else {\n pruneContext.dictionaryKeyToFieldUsageMap.set(\n dictionaryKey,\n 'all'\n );\n }\n };\n\n // Vue files\n if (vuePending.size > 0) {\n let extractVueIntlayerFieldUsage:\n | ((\n code: string,\n vars: { variableName: string; dictionaryKey: string }[]\n ) => Map<string, Set<string>>)\n | null = null;\n\n try {\n const vueCompiler = await import('@intlayer/vue-compiler');\n extractVueIntlayerFieldUsage =\n vueCompiler.extractVueIntlayerFieldUsage;\n } catch {\n // @intlayer/vue-compiler not installed – fall back to 'all'\n }\n\n for (const [filePath, entries] of vuePending) {\n if (!extractVueIntlayerFieldUsage) {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n let fileCode: string;\n try {\n fileCode = await readFile(filePath, 'utf-8');\n } catch {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n const result = extractVueIntlayerFieldUsage(fileCode, entries);\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(\n dictionaryKey,\n result.get(dictionaryKey)\n );\n }\n }\n }\n\n // Svelte files\n if (sveltePending.size > 0) {\n let extractSvelteIntlayerFieldUsage:\n | ((\n code: string,\n vars: { variableName: string; dictionaryKey: string }[]\n ) => Map<string, Set<string>>)\n | null = null;\n\n try {\n const svelteCompiler = await import(\n '@intlayer/svelte-compiler'\n );\n extractSvelteIntlayerFieldUsage =\n svelteCompiler.extractSvelteIntlayerFieldUsage;\n } catch {\n // @intlayer/svelte-compiler not installed – fall back to 'all'\n }\n\n for (const [filePath, entries] of sveltePending) {\n if (!extractSvelteIntlayerFieldUsage) {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n let fileCode: string;\n try {\n fileCode = await readFile(filePath, 'utf-8');\n } catch {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n const result = extractSvelteIntlayerFieldUsage(\n fileCode,\n entries\n );\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(\n dictionaryKey,\n result.get(dictionaryKey)\n );\n }\n }\n }\n\n // Astro files\n // Frontmatter variables are used in the HTML template, which is not\n // visible to Babel's scope analysis. Scan the template section for\n // `variableName.fieldName` accesses using a lightweight regex pass.\n if (astroPending.size > 0) {\n for (const [filePath, entries] of astroPending) {\n let fileCode: string;\n try {\n fileCode = await readFile(filePath, 'utf-8');\n } catch {\n for (const { dictionaryKey } of entries) {\n mergeFrameworkResult(dictionaryKey, undefined);\n }\n continue;\n }\n\n // Extract only the template (everything after the closing ---).\n // The frontmatter was already handled by Babel in Phase 1.\n const fenceMatch = /^---\\r?\\n[\\s\\S]*?\\r?\\n---/.exec(fileCode);\n const template = fenceMatch\n ? fileCode.slice(fenceMatch.index + fenceMatch[0].length)\n : fileCode;\n\n for (const { variableName, dictionaryKey } of entries) {\n const escapedVar = variableName.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n '\\\\$&'\n );\n const fieldRe = new RegExp(\n `\\\\b${escapedVar}\\\\.([a-zA-Z_$][a-zA-Z0-9_$]*)`,\n 'g'\n );\n const foundFields = new Set<string>();\n let m = fieldRe.exec(template);\n while (m !== null) {\n foundFields.add(m[1]!);\n m = fieldRe.exec(template);\n }\n mergeFrameworkResult(\n dictionaryKey,\n foundFields.size > 0 ? foundFields : undefined\n );\n }\n }\n }\n }\n\n // Phase 2.5: Keep `nest()` targets resolvable — must run before the\n // rename maps of Phase 4 are built.\n preserveNestedDictionaryFields(\n pruneContext,\n nestedDictionaryReferences\n );\n\n // Phase 3: Warn about untracked bindings (plain variable assignments)\n for (const [\n dictionaryKey,\n sourceFilePaths,\n ] of pruneContext.dictionaryKeysWithUntrackedBindings) {\n logger(\n [\n `Dictionary`,\n colorizeKey(dictionaryKey),\n `cannot be purged or minified.`,\n `\\n Reason: the result of`,\n `${colorize(`useIntlayer(`, ANSIColors.GREY_LIGHT)}${colorizeKey(\n `'${dictionaryKey}'`\n )}${colorize(`)`, ANSIColors.GREY_LIGHT)}`,\n `is assigned to a plain variable in:`,\n ...sourceFilePaths.map(\n (filePath) => `\\n - ${formatPath(filePath)}`\n ),\n ],\n { level: 'warn' }\n );\n }\n\n // Phase 4: Build field-rename map for minification\n // Reads each compiled dictionary JSON to discover the full nested\n // user-defined field structure, then builds a NestedRenameMap that\n // assigns short alphabetic aliases at every level.\n if (isFieldRenameEnabled) {\n for (const [\n dictionaryKey,\n fieldUsage,\n ] of pruneContext.dictionaryKeyToFieldUsageMap) {\n if (fieldUsage === 'all') continue;\n\n // Fetch-mode dictionaries are served from a remote API using\n // original field names – renaming would break the client/server\n // contract.\n if (dictionaryKeyToImportModeMap[dictionaryKey] === 'fetch')\n continue;\n\n // SFC indirect access: skip field rename for these dictionaries\n // to avoid a JSON ↔ source mismatch at runtime.\n if (\n pruneContext.dictionariesSkippingFieldRename.has(dictionaryKey)\n )\n continue;\n\n // Read dictionary content (static JSON first, then dynamic per-locale)\n let dictionaryContent: unknown = null;\n\n const staticJsonPath = join(\n dictionariesDir,\n `${dictionaryKey}.json`\n );\n try {\n const raw = await readFile(staticJsonPath, 'utf-8');\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n dictionaryContent = parsed.content;\n } catch {\n try {\n const dynamicDir = join(\n dynamicDictionariesDir,\n dictionaryKey\n );\n const localeFiles = await readdir(dynamicDir);\n const firstJsonFile = localeFiles.find((f) =>\n f.endsWith('.json')\n );\n if (firstJsonFile) {\n const raw = await readFile(\n join(dynamicDir, firstJsonFile),\n 'utf-8'\n );\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n dictionaryContent = parsed.content;\n }\n } catch {\n // Dictionary file not readable – skip rename for this key\n }\n }\n\n if (!dictionaryContent) continue;\n\n // Build the rename map from ALL user-defined fields in the\n // dictionary — not just the ones statically consumed by source\n // files. Using the full set ensures that:\n // 1. Every field in the compiled JSON is renamed (even if\n // pruned-out fields still appear when purge is disabled).\n // 2. The short-name assignment is stable: the alphabetical\n // order of all fields determines each short name, so adding\n // or removing a consumer never changes names for others.\n // 3. There is no source ↔ JSON mismatch: both sides use the\n // identical map regardless of which subset is consumed.\n const nestedRenameMap =\n buildNestedRenameMapFromContent(dictionaryContent);\n\n // Skip renaming below opaque values that have nested\n // user-defined structure – renaming those sub-keys would\n // silently break child components that consume the value as-is.\n const opaqueFieldMap =\n pruneContext.dictionaryKeysWithOpaqueFields.get(dictionaryKey);\n\n if (opaqueFieldMap) {\n const dangerousOccurrences = [\n ...opaqueFieldMap.values(),\n ].filter(\n (occurrence) =>\n (getNestedRenameEntryAtPath(\n nestedRenameMap,\n occurrence.fieldPath\n )?.children.size ?? 0) > 0\n );\n if (dangerousOccurrences.length > 0) {\n partiallyMinifiedDictionariesCount += 1;\n\n logger(\n [\n `Dictionary`,\n colorizeKey(dictionaryKey),\n `partially minified.`,\n ...dangerousOccurrences.flatMap((occurrence) => [\n `\\n Opaque field:`,\n colorize(\n `'${occurrence.fieldPath.join('.')}'`,\n ANSIColors.BLUE\n ),\n `(nested keys preserved for stability).`,\n ...occurrence.locations.map(\n (loc) => `\\n at ${formatPath(loc)}`\n ),\n ]),\n ],\n { level: 'warn', isVerbose: true }\n );\n\n // Disable renaming for the children of opaque values to\n // prevent breaking components that receive the value as a\n // prop.\n for (const occurrence of dangerousOccurrences) {\n const entry = getNestedRenameEntryAtPath(\n nestedRenameMap,\n occurrence.fieldPath\n );\n if (entry) {\n entry.children = new Map();\n }\n }\n }\n }\n\n if (nestedRenameMap.size > 0) {\n pruneContext.dictionaryKeyToFieldRenameMap.set(\n dictionaryKey,\n nestedRenameMap\n );\n }\n }\n\n if (partiallyMinifiedDictionariesCount > 0) {\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-partial-minify-summary.lock'\n ),\n () => {\n logger([\n `Partially minified`,\n colorizeNumber(partiallyMinifiedDictionariesCount),\n `dictionar${partiallyMinifiedDictionariesCount === 1 ? 'y' : 'ies'}`,\n `(preserved nested keys for opaque fields).`,\n ]);\n },\n { cacheTimeoutMs: 1000 * 5 }\n );\n }\n }\n },\n },\n\n // Plugin 2: Babel transform\n {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after framework transformations (e.g. Vue SFC)\n apply: (_config, env) => {\n const isBuildCommand = env.command === 'build';\n const isEnabled =\n (optimize === undefined && isBuildCommand) || optimize === true;\n\n if (!isBuildCommand || !isEnabled) return false;\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-optimize-plugin-enabled.lock'\n ),\n () => {\n logger([\n `Build optimization ${colorize('enabled', ANSIColors.GREEN)}`,\n colorize('(import mode:', ANSIColors.GREY_DARK),\n colorize(importMode ?? IMPORT_MODE, ANSIColors.BLUE),\n colorize(')', ANSIColors.GREY_DARK),\n ]);\n\n // The minify plugin reports the field-rename step standing down\n // when the editor is enabled, so this line stays a plain one.\n if (minify) {\n logger(\n `Dictionary minification ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n\n if (purge) {\n logger(\n `Dictionary purge unused keys ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n },\n { cacheTimeoutMs: 1000 * 10 }\n );\n\n return true;\n },\n\n transform: async (sourceCode, moduleId, options) => {\n // Strip query parameters added by Vue/Svelte loaders\n // e.g. \"HelloWorld.vue?vue&type=script&setup=true&lang.ts\" → \"HelloWorld.vue\"\n const sourceFilePath = normalizePath(\n moduleId.split('?', 1)[0] ?? moduleId\n );\n\n if (!SOURCE_FILE_REGEX.test(sourceFilePath)) return null;\n if (!transformableFilesList.includes(sourceFilePath)) return null;\n\n const isDictionaryEntryFile = [\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n ].includes(sourceFilePath);\n\n // Match native intlayer calls plus any configured compat callers\n // (`useTranslation`, `useTranslations`, …) so compat-only files are\n // still optimized.\n const optimizeUsageRegex = compatCallers?.length\n ? buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n )\n : INTLAYER_USAGE_REGEX;\n\n const isUsingIntlayer = optimizeUsageRegex.test(sourceCode);\n if (!isUsingIntlayer && !isDictionaryEntryFile) return null;\n\n // Step 1: Field rename (must run before the optimize pass, which\n // replaces useIntlayer → useDictionary and erases the dictionary key)\n let codeToOptimize = sourceCode;\n\n if (isFieldRenameEnabled && pruneContext && isUsingIntlayer) {\n const renamedCode = await renameFieldsInSourceFile(\n sourceFilePath,\n sourceCode,\n pruneContext\n );\n if (renamedCode) {\n codeToOptimize = renamedCode;\n }\n }\n\n // Step 2: Optimize (useIntlayer('key') → useDictionary(_hash))\n const transformResult = await optimizeSourceFile(\n codeToOptimize,\n sourceFilePath,\n {\n optimize,\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath: join(\n mainDir,\n 'fetch_dictionaries.mjs'\n ),\n importMode,\n filesList: transformableFilesList,\n replaceDictionaryEntry: isBuildOptimizeEnabled(null, {\n command: 'build',\n }),\n nestingDictionaryKeys,\n dictionaryModeMap: dictionaryKeyToImportModeMap,\n isServer: options?.ssr === true,\n compatCallers,\n }\n );\n\n if (!transformResult) return null;\n\n return {\n code: transformResult.code,\n map: transformResult.map as any,\n };\n },\n },\n ];\n } catch (pluginInitError) {\n console.warn(\n '[vite-intlayer] Failed to initialise optimization plugin:',\n pluginInitError\n );\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,mB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A;MACA;MACA;MACA;MACA,4BAA4B,KAC1B,SACA,wBACF;MACA;MACA,WAAW;MACX,wBAAwB,uBAAuB,MAAM,EACnD,SAAS,QACX,CAAC;MACD;MACA,mBAAmB;MACnB,UAAU,SAAS,QAAQ;MAC3B;KACF,CACF;KAEA,IAAI,CAAC,iBAAiB,OAAO;KAE7B,OAAO;MACL,MAAM,gBAAgB;MACtB,KAAK,gBAAgB;KACvB;IACF;GACF;EACF;CACF,SAAS,iBAAiB;EACxB,QAAQ,KACN,6DACA,eACF;EACA,OAAO,CAAC;CACV;AACF"}
|
|
@@ -18,6 +18,17 @@ import { logConfigDetails } from "@intlayer/engine/logConfigDetails";
|
|
|
18
18
|
|
|
19
19
|
//#region src/intlayerPlugin.ts
|
|
20
20
|
/**
|
|
21
|
+
* Packages that must go through Vite's transform pipeline instead of being
|
|
22
|
+
* loaded natively by Node.
|
|
23
|
+
*
|
|
24
|
+
* `intlayer` and every `@intlayer/*` package resolve `@intlayer/dictionaries-entry`
|
|
25
|
+
* through a Vite alias pointing at the generated `.intlayer` entry. A package
|
|
26
|
+
* loaded natively by Node never sees that alias: it resolves the published stub
|
|
27
|
+
* instead, whose CJS `require` of the generated dictionaries is cached for the
|
|
28
|
+
* lifetime of the process — so content edits stop reaching the running server.
|
|
29
|
+
*/
|
|
30
|
+
const INTLAYER_NO_EXTERNAL_PATTERN = /(^@intlayer\/|intlayer$)/;
|
|
31
|
+
/**
|
|
21
32
|
* Vite plugin that integrates Intlayer into the Vite build process.
|
|
22
33
|
*
|
|
23
34
|
* It handles:
|
|
@@ -92,7 +103,7 @@ const intlayerPlugin = (configOptions) => {
|
|
|
92
103
|
define,
|
|
93
104
|
resolve: { alias },
|
|
94
105
|
optimizeDeps: { exclude: aliasPackages },
|
|
95
|
-
ssr: { noExternal: [
|
|
106
|
+
ssr: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] }
|
|
96
107
|
};
|
|
97
108
|
},
|
|
98
109
|
configureServer: async (server) => {
|
|
@@ -141,5 +152,5 @@ const intlayer = intlayerPlugin;
|
|
|
141
152
|
const intLayerPlugin = intlayerPlugin;
|
|
142
153
|
|
|
143
154
|
//#endregion
|
|
144
|
-
export { intLayerPlugin, intlayer, intlayerPlugin };
|
|
155
|
+
export { INTLAYER_NO_EXTERNAL_PATTERN, intLayerPlugin, intlayer, intlayerPlugin };
|
|
145
156
|
//# sourceMappingURL=intlayerPlugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPlugin.mjs","names":[],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { type CompatCallerConfig, createPruneContext } from '@intlayer/babel';\nimport { BLUE } from '@intlayer/config/colors';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n formatOptimizedNestingEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n getAlias,\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n} from '@intlayer/config/utils';\nimport { resolveProxyMode } from '@intlayer/core/localization';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { logConfigDetails } from '@intlayer/engine/logConfigDetails';\nimport type { PluginOption } from 'vite';\nimport { intlayerCompiler } from './IntlayerCompilerPlugin';\nimport { intlayerChunk } from './intlayerChunkPlugin';\nimport { intlayerMinify } from './intlayerMinifyPlugin';\nimport { intlayerOptimize } from './intlayerOptimizePlugin';\nimport { intlayerPreload } from './intlayerPreloadPlugin';\nimport {\n type IntlayerProxyPluginOptions,\n intlayerProxy,\n} from './intlayerProxyPlugin';\nimport { intlayerPrune } from './intlayerPrunePlugin';\n\n/**\n * Extended options accepted by the intlayer Vite plugin.\n *\n * Extends {@link GetConfigurationOptions} with compat-adapter caller\n * configurations. Compat adapter packages (e.g. `@intlayer/react-i18next/plugin`,\n * `@intlayer/vue-i18n/plugin`) inject their own caller configs here so the\n * field-usage analyser can recognise their translation function call patterns\n * and prune unused dictionary fields accordingly.\n */\nexport type IntlayerPluginOptions = GetConfigurationOptions & {\n /**\n * Compat-adapter namespace caller configurations to pass to the\n * field-usage analyser (Vite `buildStart` phase).\n *\n * Defined by each compat adapter package; the core `vite-intlayer` package\n * ships with an empty default to stay framework-agnostic.\n */\n compatCallers?: CompatCallerConfig[];\n\n /**\n * Options forwarded to the bundled locale-routing proxy (`intlayerProxy`).\n *\n * Since Intlayer v9 the proxy is plugged directly into the main `intlayer()`\n * plugin (controlled by `routing.enableProxy`, unset by default, which\n * selects auto mode). These routing options let you tune that bundled proxy\n * without registering it separately — e.g. ignore API routes from locale\n * routing.\n *\n * @example\n * ```ts\n * intlayer({ proxy: { ignore: (req) => req.url?.startsWith('/api') } })\n * ```\n */\n proxy?: Pick<IntlayerProxyPluginOptions, 'ignore'>;\n};\n\n/**\n * Vite plugin that integrates Intlayer into the Vite build process.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) before build.\n * 2. Configuring Vite aliases for dictionary access.\n * 3. Setting up dev-server watchers for content changes.\n * 4. Applying build optimizations (tree-shaking dictionaries).\n *\n * @param configOptions - Optional configuration to override default Intlayer settings.\n * @returns A Vite plugin option.\n *\n * @example\n * ```ts\n * import { intlayer } from 'vite-intlayer';\n *\n * export default defineConfig({\n * plugins: [intlayer()],\n * });\n *\n * ```\n * @deprecated Rename to intlayer instead\n */\nexport const intlayerPlugin = (\n configOptions?: IntlayerPluginOptions\n): PluginOption => {\n const { compatCallers, proxy, ...getConfigOptions } = configOptions ?? {};\n const intlayerConfig = getConfiguration(getConfigOptions);\n logConfigDetails(getConfigOptions);\n const appLogger = getAppLogger(intlayerConfig);\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 apply: (_config, env) => {\n // Don't apply intlayer plugin during `preview` command\n const isPreviewCommand =\n env.command === 'serve' && env.mode === 'production';\n\n // But if liveSync is enabled, ensure the data are fresh\n const isLiveSyncEnabled = intlayerConfig.editor.liveSync;\n\n return !isPreviewCommand || isLiveSyncEnabled;\n },\n\n config: async (_config, env) => {\n const { mode } = intlayerConfig.build;\n\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 `preview`)\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 || mode === 'auto') {\n // Lazily load the heavy build pipeline (`@intlayer/engine/build`) only\n // when a rebuild is actually required, keeping the Vite config phase\n // lightweight (e.g. during `preview`).\n const { prepareIntlayer } = await import('@intlayer/engine/build');\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 env: isBuildCommand ? 'prod' : 'dev',\n });\n }\n\n let define: Record<string, string> = {\n // Preset an env var to avoid 'process is not defined' error\n // Needed for some libraries that does not add process.env\n 'process.env.INTLAYER': '\"true\"',\n };\n\n if (isBuildCommand) {\n const dictionaries = getDictionaries(intlayerConfig);\n\n // Mirrors the optimize plugin's own `apply` condition: the local\n // `nest()` resolver may only be selected when that transform runs,\n // since it is the transform that injects the nest attachment.\n const isOptimizeEnabled = intlayerConfig.build.optimize !== false;\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger(\n 'No dictionaries found. Please check your configuration.',\n {\n isVerbose: true,\n }\n );\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n\n if (unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out unused logic:',\n unusedNodeTypes\n .filter(\n (key) =>\n !['reactNode', 'solidNode', 'preactNode'].includes(key)\n )\n .map((key) => colorize(key, BLUE))\n .join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n define = {\n ...define,\n\n // Tree shacking env var based on config\n ...formatNodeTypeToEnvVar(\n unusedNodeTypes,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"`\n ),\n\n // Selects the local `nest()` resolver, which reads the nest\n // targets attached to each dictionary by the optimize transform\n // instead of the registry that transform empties.\n ...formatOptimizedNestingEnvVar(\n isOptimizeEnabled,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"`\n ),\n\n // Tree shacking env var for the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"`\n ),\n\n // Tree shacking env var based on config\n ...getConfigEnvVars(\n intlayerConfig,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"` // Wrap by \"\" to ensure env var set properly\n ),\n };\n }\n\n // mergeConfig handles both array and record alias formats,\n // and correctly appends to optimizeDeps.exclude / ssr.noExternal\n return {\n define,\n resolve: {\n alias,\n },\n optimizeDeps: {\n // Exclude alias entry points since they're local files, not npm packages\n exclude: aliasPackages,\n },\n ssr: {\n // Ensure intlayer packages are bundled so aliases are applied\n noExternal: [/(^@intlayer\\/|intlayer$)/],\n },\n };\n },\n\n configureServer: async (server) => {\n if (server.config.mode === 'development') {\n // Lazily load the file watcher (`@intlayer/engine/watcher`, which pulls\n // in `@parcel/watcher`) only when the dev server actually starts.\n const { watch } = await import('@intlayer/engine/watcher');\n\n // Start watching (assuming watch is also async)\n await watch({ configuration: intlayerConfig });\n }\n },\n },\n ];\n\n // Shared mutable state: the optimize plugin writes field-usage data during\n // buildStart; the prune and minify plugins read it during transform.\n const pruneContext = createPruneContext();\n\n // Babel transform: rewrites useIntlayer/getIntlayer calls and injects\n // JSON / dynamic-mjs imports. Also runs the usage analyser in buildStart.\n plugins.push(intlayerOptimize(intlayerConfig, pruneContext, compatCallers));\n\n // Prune: removes unused content fields from dictionary JSON files.\n // Runs with enforce:'pre' so it intercepts raw JSON before Vite's\n // built-in JSON → ESM conversion.\n plugins.push(intlayerPrune(intlayerConfig, pruneContext));\n\n // Minify: compacts dictionary JSON files (parse + re-stringify).\n // Registered after prune so it receives already-pruned output when both options are active.\n plugins.push(intlayerMinify(intlayerConfig, pruneContext));\n\n // Chunk: regroups the per-dictionary chunks that `importMode: 'dynamic'`\n // emits, so each code-split boundary loads its content in one request.\n plugins.push(intlayerChunk(intlayerConfig));\n\n // Preload: makes each dynamic entry point await its locale's dictionary while\n // it evaluates, so the content travels with the chunk that needs it instead\n // of being fetched — and suspended on — once that chunk renders.\n plugins.push(intlayerPreload(intlayerConfig));\n\n // Compiler: extracts content declared inline in components into dictionaries.\n // Bundled directly into the main plugin so users no longer need to register\n // `intlayerCompiler()` separately. Only added when the compiler is enabled and\n // an `output` path is configured. Registering `intlayerCompiler()` manually as\n // well is safe — the compiler deduplicates itself.\n if (intlayerConfig.compiler?.enabled && intlayerConfig.compiler?.output) {\n plugins.push(intlayerCompiler({ configOptions: getConfigOptions }));\n }\n\n // Proxy: locale-routing middleware (detection / redirect / rewrite) for dev,\n // preview, and production SSR. Bundled directly into the main plugin and\n // controlled by the `routing.enableProxy` option, which is unset by default\n // and therefore resolves to auto mode. Only an explicit `false` skips\n // registration — a plain truthiness check would wrongly drop the proxy for\n // every project that never set the option.\n // Registering `intlayerProxy()` manually as well is safe — the proxy\n // deduplicates itself.\n if (resolveProxyMode(intlayerConfig.routing.enableProxy) !== 'disabled') {\n plugins.push(intlayerProxy({ ...proxy, configOptions: getConfigOptions }));\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,MAAa,kBACX,kBACiB;CACjB,MAAM,EAAE,eAAe,OAAO,GAAG,qBAAqB,iBAAiB,CAAC;CACxE,MAAM,iBAAiB,iBAAiB,gBAAgB;CACxD,iBAAiB,gBAAgB;CACjC,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,QAAQ,SAAS;EACrB,eAAe;EACf,YAAY,UAAkB,QAAQ,KAAK;CAC7C,CAAC;CAED,MAAM,gBAAgB,OAAO,KAAK,KAAK;CAEvC,MAAM,UAA0B,CAC9B;EACE,MAAM;EAEN,QAAQ,SAAS,QAAQ;GAEvB,MAAM,mBACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAG1C,MAAM,oBAAoB,eAAe,OAAO;GAEhD,OAAO,CAAC,oBAAoB;EAC9B;EAEA,QAAQ,OAAO,SAAS,QAAQ;GAC9B,MAAM,EAAE,SAAS,eAAe;GAEhC,MAAM,eACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAC1C,MAAM,iBAAiB,IAAI,YAAY;GAKvC,IAAI,gBAAgB,kBAAkB,SAAS,QAAQ;IAIrD,MAAM,EAAE,oBAAoB,MAAM,OAAO;IAGzC,MAAM,gBAAgB,gBAAgB;KACpC,OAAO;KACP,gBAAgB,iBACZ,MACA;KACJ,KAAK,iBAAiB,SAAS;IACjC,CAAC;GACH;GAEA,IAAI,SAAiC,EAGnC,wBAAwB,WAC1B;GAEA,IAAI,gBAAgB;IAClB,MAAM,eAAe,gBAAgB,cAAc;IAKnD,MAAM,oBAAoB,eAAe,MAAM,aAAa;IAE5D,IAAI,OAAO,KAAK,YAAY,CAAC,CAAC,WAAW,GACvC,UACE,2DAC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iBAAiB,CAAC,CAAC;CAWpE,IAAI,iBAAiB,eAAe,QAAQ,WAAW,MAAM,YAC3D,QAAQ,KAAK,cAAc;EAAE,GAAG;EAAO,eAAe;CAAiB,CAAC,CAAC;CAG3E,OAAO;AACT;;;;;;;;;;;AAYA,MAAa,WAAW;;;;;;;;;;;;;AAaxB,MAAa,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"intlayerPlugin.mjs","names":[],"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { type CompatCallerConfig, createPruneContext } from '@intlayer/babel';\nimport { BLUE } from '@intlayer/config/colors';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n formatOptimizedNestingEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n getAlias,\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n} from '@intlayer/config/utils';\nimport { resolveProxyMode } from '@intlayer/core/localization';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { logConfigDetails } from '@intlayer/engine/logConfigDetails';\nimport type { PluginOption } from 'vite';\nimport { intlayerCompiler } from './IntlayerCompilerPlugin';\nimport { intlayerChunk } from './intlayerChunkPlugin';\nimport { intlayerMinify } from './intlayerMinifyPlugin';\nimport { intlayerOptimize } from './intlayerOptimizePlugin';\nimport { intlayerPreload } from './intlayerPreloadPlugin';\nimport {\n type IntlayerProxyPluginOptions,\n intlayerProxy,\n} from './intlayerProxyPlugin';\nimport { intlayerPrune } from './intlayerPrunePlugin';\n\n/**\n * Packages that must go through Vite's transform pipeline instead of being\n * loaded natively by Node.\n *\n * `intlayer` and every `@intlayer/*` package resolve `@intlayer/dictionaries-entry`\n * through a Vite alias pointing at the generated `.intlayer` entry. A package\n * loaded natively by Node never sees that alias: it resolves the published stub\n * instead, whose CJS `require` of the generated dictionaries is cached for the\n * lifetime of the process — so content edits stop reaching the running server.\n */\nexport const INTLAYER_NO_EXTERNAL_PATTERN = /(^@intlayer\\/|intlayer$)/;\n\n/**\n * Extended options accepted by the intlayer Vite plugin.\n *\n * Extends {@link GetConfigurationOptions} with compat-adapter caller\n * configurations. Compat adapter packages (e.g. `@intlayer/react-i18next/plugin`,\n * `@intlayer/vue-i18n/plugin`) inject their own caller configs here so the\n * field-usage analyser can recognise their translation function call patterns\n * and prune unused dictionary fields accordingly.\n */\nexport type IntlayerPluginOptions = GetConfigurationOptions & {\n /**\n * Compat-adapter namespace caller configurations to pass to the\n * field-usage analyser (Vite `buildStart` phase).\n *\n * Defined by each compat adapter package; the core `vite-intlayer` package\n * ships with an empty default to stay framework-agnostic.\n */\n compatCallers?: CompatCallerConfig[];\n\n /**\n * Options forwarded to the bundled locale-routing proxy (`intlayerProxy`).\n *\n * Since Intlayer v9 the proxy is plugged directly into the main `intlayer()`\n * plugin (controlled by `routing.enableProxy`, unset by default, which\n * selects auto mode). These routing options let you tune that bundled proxy\n * without registering it separately — e.g. ignore API routes from locale\n * routing.\n *\n * @example\n * ```ts\n * intlayer({ proxy: { ignore: (req) => req.url?.startsWith('/api') } })\n * ```\n */\n proxy?: Pick<IntlayerProxyPluginOptions, 'ignore'>;\n};\n\n/**\n * Vite plugin that integrates Intlayer into the Vite build process.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) before build.\n * 2. Configuring Vite aliases for dictionary access.\n * 3. Setting up dev-server watchers for content changes.\n * 4. Applying build optimizations (tree-shaking dictionaries).\n *\n * @param configOptions - Optional configuration to override default Intlayer settings.\n * @returns A Vite plugin option.\n *\n * @example\n * ```ts\n * import { intlayer } from 'vite-intlayer';\n *\n * export default defineConfig({\n * plugins: [intlayer()],\n * });\n *\n * ```\n * @deprecated Rename to intlayer instead\n */\nexport const intlayerPlugin = (\n configOptions?: IntlayerPluginOptions\n): PluginOption => {\n const { compatCallers, proxy, ...getConfigOptions } = configOptions ?? {};\n const intlayerConfig = getConfiguration(getConfigOptions);\n logConfigDetails(getConfigOptions);\n const appLogger = getAppLogger(intlayerConfig);\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 apply: (_config, env) => {\n // Don't apply intlayer plugin during `preview` command\n const isPreviewCommand =\n env.command === 'serve' && env.mode === 'production';\n\n // But if liveSync is enabled, ensure the data are fresh\n const isLiveSyncEnabled = intlayerConfig.editor.liveSync;\n\n return !isPreviewCommand || isLiveSyncEnabled;\n },\n\n config: async (_config, env) => {\n const { mode } = intlayerConfig.build;\n\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 `preview`)\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 || mode === 'auto') {\n // Lazily load the heavy build pipeline (`@intlayer/engine/build`) only\n // when a rebuild is actually required, keeping the Vite config phase\n // lightweight (e.g. during `preview`).\n const { prepareIntlayer } = await import('@intlayer/engine/build');\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 env: isBuildCommand ? 'prod' : 'dev',\n });\n }\n\n let define: Record<string, string> = {\n // Preset an env var to avoid 'process is not defined' error\n // Needed for some libraries that does not add process.env\n 'process.env.INTLAYER': '\"true\"',\n };\n\n if (isBuildCommand) {\n const dictionaries = getDictionaries(intlayerConfig);\n\n // Mirrors the optimize plugin's own `apply` condition: the local\n // `nest()` resolver may only be selected when that transform runs,\n // since it is the transform that injects the nest attachment.\n const isOptimizeEnabled = intlayerConfig.build.optimize !== false;\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger(\n 'No dictionaries found. Please check your configuration.',\n {\n isVerbose: true,\n }\n );\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n\n if (unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out unused logic:',\n unusedNodeTypes\n .filter(\n (key) =>\n !['reactNode', 'solidNode', 'preactNode'].includes(key)\n )\n .map((key) => colorize(key, BLUE))\n .join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n define = {\n ...define,\n\n // Tree shacking env var based on config\n ...formatNodeTypeToEnvVar(\n unusedNodeTypes,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"`\n ),\n\n // Selects the local `nest()` resolver, which reads the nest\n // targets attached to each dictionary by the optimize transform\n // instead of the registry that transform empties.\n ...formatOptimizedNestingEnvVar(\n isOptimizeEnabled,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"`\n ),\n\n // Tree shacking env var for the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"`\n ),\n\n // Tree shacking env var based on config\n ...getConfigEnvVars(\n intlayerConfig,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"` // Wrap by \"\" to ensure env var set properly\n ),\n };\n }\n\n // mergeConfig handles both array and record alias formats,\n // and correctly appends to optimizeDeps.exclude / ssr.noExternal\n return {\n define,\n resolve: {\n alias,\n },\n optimizeDeps: {\n // Exclude alias entry points since they're local files, not npm packages\n exclude: aliasPackages,\n },\n ssr: {\n // Ensure intlayer packages are bundled so aliases are applied\n noExternal: [INTLAYER_NO_EXTERNAL_PATTERN],\n },\n };\n },\n\n configureServer: async (server) => {\n if (server.config.mode === 'development') {\n // Lazily load the file watcher (`@intlayer/engine/watcher`, which pulls\n // in `@parcel/watcher`) only when the dev server actually starts.\n const { watch } = await import('@intlayer/engine/watcher');\n\n // Start watching (assuming watch is also async)\n await watch({ configuration: intlayerConfig });\n }\n },\n },\n ];\n\n // Shared mutable state: the optimize plugin writes field-usage data during\n // buildStart; the prune and minify plugins read it during transform.\n const pruneContext = createPruneContext();\n\n // Babel transform: rewrites useIntlayer/getIntlayer calls and injects\n // JSON / dynamic-mjs imports. Also runs the usage analyser in buildStart.\n plugins.push(intlayerOptimize(intlayerConfig, pruneContext, compatCallers));\n\n // Prune: removes unused content fields from dictionary JSON files.\n // Runs with enforce:'pre' so it intercepts raw JSON before Vite's\n // built-in JSON → ESM conversion.\n plugins.push(intlayerPrune(intlayerConfig, pruneContext));\n\n // Minify: compacts dictionary JSON files (parse + re-stringify).\n // Registered after prune so it receives already-pruned output when both options are active.\n plugins.push(intlayerMinify(intlayerConfig, pruneContext));\n\n // Chunk: regroups the per-dictionary chunks that `importMode: 'dynamic'`\n // emits, so each code-split boundary loads its content in one request.\n plugins.push(intlayerChunk(intlayerConfig));\n\n // Preload: makes each dynamic entry point await its locale's dictionary while\n // it evaluates, so the content travels with the chunk that needs it instead\n // of being fetched — and suspended on — once that chunk renders.\n plugins.push(intlayerPreload(intlayerConfig));\n\n // Compiler: extracts content declared inline in components into dictionaries.\n // Bundled directly into the main plugin so users no longer need to register\n // `intlayerCompiler()` separately. Only added when the compiler is enabled and\n // an `output` path is configured. Registering `intlayerCompiler()` manually as\n // well is safe — the compiler deduplicates itself.\n if (intlayerConfig.compiler?.enabled && intlayerConfig.compiler?.output) {\n plugins.push(intlayerCompiler({ configOptions: getConfigOptions }));\n }\n\n // Proxy: locale-routing middleware (detection / redirect / rewrite) for dev,\n // preview, and production SSR. Bundled directly into the main plugin and\n // controlled by the `routing.enableProxy` option, which is unset by default\n // and therefore resolves to auto mode. Only an explicit `false` skips\n // registration — a plain truthiness check would wrongly drop the proxy for\n // every project that never set the option.\n // Registering `intlayerProxy()` manually as well is safe — the proxy\n // deduplicates itself.\n if (resolveProxyMode(intlayerConfig.routing.enableProxy) !== 'disabled') {\n plugins.push(intlayerProxy({ ...proxy, configOptions: getConfigOptions }));\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;AA6D5C,MAAa,kBACX,kBACiB;CACjB,MAAM,EAAE,eAAe,OAAO,GAAG,qBAAqB,iBAAiB,CAAC;CACxE,MAAM,iBAAiB,iBAAiB,gBAAgB;CACxD,iBAAiB,gBAAgB;CACjC,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,QAAQ,SAAS;EACrB,eAAe;EACf,YAAY,UAAkB,QAAQ,KAAK;CAC7C,CAAC;CAED,MAAM,gBAAgB,OAAO,KAAK,KAAK;CAEvC,MAAM,UAA0B,CAC9B;EACE,MAAM;EAEN,QAAQ,SAAS,QAAQ;GAEvB,MAAM,mBACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAG1C,MAAM,oBAAoB,eAAe,OAAO;GAEhD,OAAO,CAAC,oBAAoB;EAC9B;EAEA,QAAQ,OAAO,SAAS,QAAQ;GAC9B,MAAM,EAAE,SAAS,eAAe;GAEhC,MAAM,eACJ,IAAI,YAAY,WAAW,IAAI,SAAS;GAC1C,MAAM,iBAAiB,IAAI,YAAY;GAKvC,IAAI,gBAAgB,kBAAkB,SAAS,QAAQ;IAIrD,MAAM,EAAE,oBAAoB,MAAM,OAAO;IAGzC,MAAM,gBAAgB,gBAAgB;KACpC,OAAO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aAAa,CAAC;CAK1E,QAAQ,KAAK,cAAc,gBAAgB,YAAY,CAAC;CAIxD,QAAQ,KAAK,eAAe,gBAAgB,YAAY,CAAC;CAIzD,QAAQ,KAAK,cAAc,cAAc,CAAC;CAK1C,QAAQ,KAAK,gBAAgB,cAAc,CAAC;CAO5C,IAAI,eAAe,UAAU,WAAW,eAAe,UAAU,QAC/D,QAAQ,KAAK,iBAAiB,EAAE,eAAe,iBAAiB,CAAC,CAAC;CAWpE,IAAI,iBAAiB,eAAe,QAAQ,WAAW,MAAM,YAC3D,QAAQ,KAAK,cAAc;EAAE,GAAG;EAAO,eAAe;CAAiB,CAAC,CAAC;CAG3E,OAAO;AACT;;;;;;;;;;;AAYA,MAAa,WAAW;;;;;;;;;;;;;AAaxB,MAAa,iBAAiB"}
|
|
@@ -5,7 +5,7 @@ import { PluginOption } from "vite";
|
|
|
5
5
|
/**
|
|
6
6
|
* Options for initializing the compiler
|
|
7
7
|
*/
|
|
8
|
-
type IntlayerCompilerOptions = {
|
|
8
|
+
export type IntlayerCompilerOptions = {
|
|
9
9
|
/**
|
|
10
10
|
* Configuration options for getting the intlayer configuration
|
|
11
11
|
*/
|
|
@@ -37,7 +37,6 @@ type IntlayerCompilerOptions = {
|
|
|
37
37
|
*
|
|
38
38
|
* @deprecated Since Intlayer v9, the compiler is bundled directly into the `intlayer()` plugin and activates automatically once `compiler.enabled` is set with a `compiler.output` path. Registering `intlayerCompiler()` separately as shown below is now optional. See the [v9 release notes](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/releases/v9.md).
|
|
39
39
|
*/
|
|
40
|
-
declare const intlayerCompiler: (options?: IntlayerCompilerOptions) => PluginOption;
|
|
40
|
+
export declare const intlayerCompiler: (options?: IntlayerCompilerOptions) => PluginOption;
|
|
41
41
|
//#endregion
|
|
42
|
-
export { IntlayerCompilerOptions, intlayerCompiler };
|
|
43
42
|
//# sourceMappingURL=IntlayerCompilerPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerCompilerPlugin.d.ts","names":[],"sources":["../../src/IntlayerCompilerPlugin.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"IntlayerCompilerPlugin.d.ts","names":[],"sources":["../../src/IntlayerCompilerPlugin.ts"],"mappings":";;;;;;;YAkCY;;;;EAIV,gBAAgB;;;;EAKhB,iBAAiB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;qBAyBd,mBAAgB,UACjB,4BACT"}
|
|
@@ -19,7 +19,7 @@ type ResolvedConfigWithPlugins = {
|
|
|
19
19
|
* plugin array (so Vite stays happy) while only the first instance sharing a
|
|
20
20
|
* given `name` is treated as "primary" and actually executes.
|
|
21
21
|
*/
|
|
22
|
-
type PrimaryInstanceGuard = {
|
|
22
|
+
export type PrimaryInstanceGuard = {
|
|
23
23
|
/**
|
|
24
24
|
* Records the plugin object so the guard can later find the first instance by
|
|
25
25
|
* identity in the resolved config.
|
|
@@ -41,7 +41,6 @@ type PrimaryInstanceGuard = {
|
|
|
41
41
|
*
|
|
42
42
|
* @param pluginName - The `name` of the Vite plugin to deduplicate.
|
|
43
43
|
*/
|
|
44
|
-
declare const createPrimaryInstanceGuard: (pluginName: string) => PrimaryInstanceGuard;
|
|
44
|
+
export declare const createPrimaryInstanceGuard: (pluginName: string) => PrimaryInstanceGuard;
|
|
45
45
|
//#endregion
|
|
46
|
-
export { PrimaryInstanceGuard, createPrimaryInstanceGuard };
|
|
47
46
|
//# sourceMappingURL=dedupePlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedupePlugin.d.ts","names":[],"sources":["../../src/dedupePlugin.ts"],"mappings":";;;;;;KAMK;EACH;IAAoB;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"dedupePlugin.d.ts","names":[],"sources":["../../src/dedupePlugin.ts"],"mappings":";;;;;;KAMK;EACH;IAAoB;;;;;;;;;;;;;YAaV;;;;;EAKV,YAAY,QAAQ;;;;;EAMpB,UAAU,QAAQ;;;;;WAMT;;;;;;;qBAQE,6BAA0B,uBAEpC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ChunkingContext, DictionaryModule, ModuleGraphNode, createDictionaryMod
|
|
|
3
3
|
import { intlayerMinify } from "./intlayerMinifyPlugin.js";
|
|
4
4
|
import { intlayerOptimize } from "./intlayerOptimizePlugin.js";
|
|
5
5
|
import { IntlayerProxyPluginOptions, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy } from "./intlayerProxyPlugin.js";
|
|
6
|
-
import { IntlayerPluginOptions, intLayerPlugin, intlayer, intlayerPlugin } from "./intlayerPlugin.js";
|
|
6
|
+
import { INTLAYER_NO_EXTERNAL_PATTERN, IntlayerPluginOptions, intLayerPlugin, intlayer, intlayerPlugin } from "./intlayerPlugin.js";
|
|
7
7
|
import { intlayerPreload } from "./intlayerPreloadPlugin.js";
|
|
8
8
|
import { intlayerPrune } from "./intlayerPrunePlugin.js";
|
|
9
|
-
export { ChunkingContext, DictionaryModule, IntlayerCompilerOptions, IntlayerPluginOptions, IntlayerProxyPluginOptions, ModuleGraphNode, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, toBoundaryName };
|
|
9
|
+
export { ChunkingContext, DictionaryModule, INTLAYER_NO_EXTERNAL_PATTERN, IntlayerCompilerOptions, IntlayerPluginOptions, IntlayerProxyPluginOptions, ModuleGraphNode, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, toBoundaryName };
|
|
@@ -8,10 +8,10 @@ import { Plugin } from "vite";
|
|
|
8
8
|
* keeps working against the Rolldown bundled inside Vite, whose types are not
|
|
9
9
|
* re-exported.
|
|
10
10
|
*/
|
|
11
|
-
type ChunkingContext = {
|
|
11
|
+
export type ChunkingContext = {
|
|
12
12
|
getModuleInfo: (moduleId: string) => ModuleGraphNode | null;
|
|
13
13
|
};
|
|
14
|
-
type ModuleGraphNode = {
|
|
14
|
+
export type ModuleGraphNode = {
|
|
15
15
|
id: string;
|
|
16
16
|
isEntry: boolean;
|
|
17
17
|
/** Ids of the modules that statically `import` this one. */
|
|
@@ -20,7 +20,7 @@ type ModuleGraphNode = {
|
|
|
20
20
|
dynamicImporters: string[];
|
|
21
21
|
};
|
|
22
22
|
/** A per-locale dictionary chunk, identified from its module id. */
|
|
23
|
-
type DictionaryModule = {
|
|
23
|
+
export type DictionaryModule = {
|
|
24
24
|
key: string;
|
|
25
25
|
locale: string;
|
|
26
26
|
};
|
|
@@ -38,9 +38,9 @@ type DictionaryModule = {
|
|
|
38
38
|
* @param dynamicDictionariesDir - Absolute, POSIX-normalized dictionaries root.
|
|
39
39
|
* @returns Parser returning the key and locale, or `null` for any other module.
|
|
40
40
|
*/
|
|
41
|
-
declare const createDictionaryModuleParser: (dynamicDictionariesDir: string) => ((moduleId: string) => DictionaryModule | null);
|
|
41
|
+
export declare const createDictionaryModuleParser: (dynamicDictionariesDir: string) => ((moduleId: string) => DictionaryModule | null);
|
|
42
42
|
/** Turns a boundary module id into a readable chunk-name fragment. */
|
|
43
|
-
declare const toBoundaryName: (moduleId: string) => string;
|
|
43
|
+
export declare const toBoundaryName: (moduleId: string) => string;
|
|
44
44
|
/**
|
|
45
45
|
* Walks up the import graph from a dictionary JSON to the code-split boundaries
|
|
46
46
|
* that reach it.
|
|
@@ -55,7 +55,7 @@ declare const toBoundaryName: (moduleId: string) => string;
|
|
|
55
55
|
* @returns Boundary ids reaching this dictionary, empty when the graph is
|
|
56
56
|
* unavailable (the module was pruned, or resolution failed).
|
|
57
57
|
*/
|
|
58
|
-
declare const resolveBoundaries: (jsonModuleId: string, context: ChunkingContext) => string[];
|
|
58
|
+
export declare const resolveBoundaries: (jsonModuleId: string, context: ChunkingContext) => string[];
|
|
59
59
|
/**
|
|
60
60
|
* Groups dynamically imported dictionaries by the code-split boundary that
|
|
61
61
|
* consumes them, so each lazily loaded page or section fetches its content in
|
|
@@ -82,7 +82,6 @@ declare const resolveBoundaries: (jsonModuleId: string, context: ChunkingContext
|
|
|
82
82
|
*
|
|
83
83
|
* @param intlayerConfig - Resolved Intlayer configuration.
|
|
84
84
|
*/
|
|
85
|
-
declare const intlayerChunk: (intlayerConfig: IntlayerConfig) => Plugin;
|
|
85
|
+
export declare const intlayerChunk: (intlayerConfig: IntlayerConfig) => Plugin;
|
|
86
86
|
//#endregion
|
|
87
|
-
export { ChunkingContext, DictionaryModule, ModuleGraphNode, createDictionaryModuleParser, intlayerChunk, resolveBoundaries, toBoundaryName };
|
|
88
87
|
//# sourceMappingURL=intlayerChunkPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerChunkPlugin.d.ts","names":[],"sources":["../../src/intlayerChunkPlugin.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerChunkPlugin.d.ts","names":[],"sources":["../../src/intlayerChunkPlugin.ts"],"mappings":";;;;;;;;;;YAaY;EACV,gBAAgB,qBAAqB;;YAG3B;EACV;EACA;;EAEA;;EAEA;;;YAIU;EACV;EACA;;;;;;;;;;;;;;;;qBAiBW,+BAA4B,qCAEpC,qBAAqB;;qBAuCb,iBAAc;;;;;;;;;;;;;;;qBAuBd,oBAAiB,sBACR,SACX;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAyDE,gBAAa,gBAAoB,mBAAiB"}
|
|
@@ -38,7 +38,6 @@ import { PruneContext } from "@intlayer/babel";
|
|
|
38
38
|
* skipped and field renames are applied. Pass `null`
|
|
39
39
|
* if the prune plugin is not active.
|
|
40
40
|
*/
|
|
41
|
-
declare const intlayerMinify: (intlayerConfig: IntlayerConfig, pruneContext: PruneContext | null) => PluginOption[];
|
|
41
|
+
export declare const intlayerMinify: (intlayerConfig: IntlayerConfig, pruneContext: PruneContext | null) => PluginOption[];
|
|
42
42
|
//#endregion
|
|
43
|
-
export { intlayerMinify };
|
|
44
43
|
//# sourceMappingURL=intlayerMinifyPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerMinifyPlugin.d.ts","names":[],"sources":["../../src/intlayerMinifyPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerMinifyPlugin.d.ts","names":[],"sources":["../../src/intlayerMinifyPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwKa,iBAAc,gBACT,gBAAc,cAChB,wBACb"}
|
|
@@ -24,7 +24,6 @@ import { CallerDescriptor, PruneContext } from "@intlayer/babel";
|
|
|
24
24
|
* analysis (e.g. when both `purge` and `minify` are
|
|
25
25
|
* disabled).
|
|
26
26
|
*/
|
|
27
|
-
declare const intlayerOptimize: (intlayerConfig: IntlayerConfig, pruneContext: PruneContext | null, compatCallers?: CallerDescriptor[]) => Promise<PluginOption[]>;
|
|
27
|
+
export declare const intlayerOptimize: (intlayerConfig: IntlayerConfig, pruneContext: PruneContext | null, compatCallers?: CallerDescriptor[]) => Promise<PluginOption[]>;
|
|
28
28
|
//#endregion
|
|
29
|
-
export { intlayerOptimize };
|
|
30
29
|
//# sourceMappingURL=intlayerOptimizePlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerOptimizePlugin.d.ts","names":[],"sources":["../../src/intlayerOptimizePlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerOptimizePlugin.d.ts","names":[],"sources":["../../src/intlayerOptimizePlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;qBA+Da,mBAAgB,gBACX,gBAAc,cAChB,qBAAmB,gBACjB,uBACf,QAAQ"}
|
|
@@ -3,6 +3,17 @@ import { GetConfigurationOptions } from "@intlayer/config/node";
|
|
|
3
3
|
import { PluginOption } from "vite";
|
|
4
4
|
import { CompatCallerConfig } from "@intlayer/babel";
|
|
5
5
|
//#region src/intlayerPlugin.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Packages that must go through Vite's transform pipeline instead of being
|
|
8
|
+
* loaded natively by Node.
|
|
9
|
+
*
|
|
10
|
+
* `intlayer` and every `@intlayer/*` package resolve `@intlayer/dictionaries-entry`
|
|
11
|
+
* through a Vite alias pointing at the generated `.intlayer` entry. A package
|
|
12
|
+
* loaded natively by Node never sees that alias: it resolves the published stub
|
|
13
|
+
* instead, whose CJS `require` of the generated dictionaries is cached for the
|
|
14
|
+
* lifetime of the process — so content edits stop reaching the running server.
|
|
15
|
+
*/
|
|
16
|
+
export declare const INTLAYER_NO_EXTERNAL_PATTERN: RegExp;
|
|
6
17
|
/**
|
|
7
18
|
* Extended options accepted by the intlayer Vite plugin.
|
|
8
19
|
*
|
|
@@ -12,7 +23,7 @@ import { CompatCallerConfig } from "@intlayer/babel";
|
|
|
12
23
|
* field-usage analyser can recognise their translation function call patterns
|
|
13
24
|
* and prune unused dictionary fields accordingly.
|
|
14
25
|
*/
|
|
15
|
-
type IntlayerPluginOptions = GetConfigurationOptions & {
|
|
26
|
+
export type IntlayerPluginOptions = GetConfigurationOptions & {
|
|
16
27
|
/**
|
|
17
28
|
* Compat-adapter namespace caller configurations to pass to the
|
|
18
29
|
* field-usage analyser (Vite `buildStart` phase).
|
|
@@ -60,7 +71,7 @@ type IntlayerPluginOptions = GetConfigurationOptions & {
|
|
|
60
71
|
* ```
|
|
61
72
|
* @deprecated Rename to intlayer instead
|
|
62
73
|
*/
|
|
63
|
-
declare const intlayerPlugin: (configOptions?: IntlayerPluginOptions) => PluginOption;
|
|
74
|
+
export declare const intlayerPlugin: (configOptions?: IntlayerPluginOptions) => PluginOption;
|
|
64
75
|
/**
|
|
65
76
|
* A Vite plugin that integrates Intlayer configuration into the build process
|
|
66
77
|
*
|
|
@@ -71,7 +82,7 @@ declare const intlayerPlugin: (configOptions?: IntlayerPluginOptions) => PluginO
|
|
|
71
82
|
* });
|
|
72
83
|
* ```
|
|
73
84
|
*/
|
|
74
|
-
declare const intlayer: typeof intlayerPlugin;
|
|
85
|
+
export declare const intlayer: typeof intlayerPlugin;
|
|
75
86
|
/**
|
|
76
87
|
* @deprecated Rename to intlayer instead
|
|
77
88
|
*
|
|
@@ -84,7 +95,6 @@ declare const intlayer: typeof intlayerPlugin;
|
|
|
84
95
|
* });
|
|
85
96
|
* ```
|
|
86
97
|
*/
|
|
87
|
-
declare const intLayerPlugin: typeof intlayerPlugin;
|
|
98
|
+
export declare const intLayerPlugin: typeof intlayerPlugin;
|
|
88
99
|
//#endregion
|
|
89
|
-
export { IntlayerPluginOptions, intLayerPlugin, intlayer, intlayerPlugin };
|
|
90
100
|
//# sourceMappingURL=intlayerPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPlugin.d.ts","names":[],"sources":["../../src/intlayerPlugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"intlayerPlugin.d.ts","names":[],"sources":["../../src/intlayerPlugin.ts"],"mappings":";;;;;;;;;;;;;;;qBA4Ca,8BAA4B;;;;;;;;;;YAW7B,wBAAwB;;;;;;;;EAQlC,gBAAgB;;;;;;;;;;;;;;;EAgBhB,QAAQ,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;qBA0BF,iBAAc,gBACT,0BACf;;;;;;;;;;;qBAgOU,iBAAQ;;;;;;;;;;;;;qBAaR,uBAAc"}
|
|
@@ -28,7 +28,6 @@ import { Plugin } from "vite";
|
|
|
28
28
|
*
|
|
29
29
|
* @param intlayerConfig - Resolved Intlayer configuration.
|
|
30
30
|
*/
|
|
31
|
-
declare const intlayerPreload: (intlayerConfig: IntlayerConfig) => Plugin;
|
|
31
|
+
export declare const intlayerPreload: (intlayerConfig: IntlayerConfig) => Plugin;
|
|
32
32
|
//#endregion
|
|
33
|
-
export { intlayerPreload };
|
|
34
33
|
//# sourceMappingURL=intlayerPreloadPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPreloadPlugin.d.ts","names":[],"sources":["../../src/intlayerPreloadPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerPreloadPlugin.d.ts","names":[],"sources":["../../src/intlayerPreloadPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmDa,kBAAe,gBAAoB,mBAAiB"}
|
|
@@ -6,8 +6,8 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
6
6
|
* Compatible with Vite dev/preview server, Node.js http, Express, and h3's
|
|
7
7
|
* `fromNodeMiddleware` wrapper for Nitro/TanStack Start production use.
|
|
8
8
|
*/
|
|
9
|
-
type NodeMiddleware = (req: IncomingMessage, res: ServerResponse<IncomingMessage>, next: () => void) => void;
|
|
10
|
-
type IntlayerProxyHandlerOptions = {
|
|
9
|
+
export type NodeMiddleware = (req: IncomingMessage, res: ServerResponse<IncomingMessage>, next: () => void) => void;
|
|
10
|
+
export type IntlayerProxyHandlerOptions = {
|
|
11
11
|
/**
|
|
12
12
|
* The resolved Intlayer configuration driving locale detection and routing.
|
|
13
13
|
*/
|
|
@@ -44,7 +44,6 @@ type IntlayerProxyHandlerOptions = {
|
|
|
44
44
|
*
|
|
45
45
|
* @see `createIntlayerProxyHandler` for the public, configuration-loading entry point.
|
|
46
46
|
*/
|
|
47
|
-
declare const createProxyHandler: (options: IntlayerProxyHandlerOptions) => NodeMiddleware;
|
|
47
|
+
export declare const createProxyHandler: (options: IntlayerProxyHandlerOptions) => NodeMiddleware;
|
|
48
48
|
//#endregion
|
|
49
|
-
export { IntlayerProxyHandlerOptions, NodeMiddleware, createProxyHandler };
|
|
50
49
|
//# sourceMappingURL=intlayerProxyHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxyHandler.d.ts","names":[],"sources":["../../src/intlayerProxyHandler.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerProxyHandler.d.ts","names":[],"sources":["../../src/intlayerProxyHandler.ts"],"mappings":";;;;;;;;YAkIY,kBACV,KAAK,iBACL,KAAK,eAAe,kBACpB;YAGU;;;;EAIV,eAAe;;;;;;;EAOf,UAAU,KAAK;;;;;;;;;EASf;;;;;;;;;;;;;;;;;qBAkBW,qBAAkB,SACpB,gCACR"}
|
|
@@ -3,7 +3,7 @@ import { GetConfigurationOptions } from "@intlayer/config/node";
|
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
import { IncomingMessage } from "node:http";
|
|
5
5
|
//#region src/intlayerProxyPlugin.d.ts
|
|
6
|
-
type IntlayerProxyPluginOptions = {
|
|
6
|
+
export type IntlayerProxyPluginOptions = {
|
|
7
7
|
/**
|
|
8
8
|
* A function that allows you to ignore specific requests from the intlayer proxy.
|
|
9
9
|
*
|
|
@@ -66,7 +66,7 @@ type IntlayerProxyPluginOptions = {
|
|
|
66
66
|
* @param options - Plugin-specific options, such as path ignoring and Intlayer configuration overrides.
|
|
67
67
|
* @returns A Connect-compatible `(req, res, next) => void` middleware.
|
|
68
68
|
*/
|
|
69
|
-
declare const createIntlayerProxyHandler: (options?: IntlayerProxyPluginOptions) => NodeMiddleware;
|
|
69
|
+
export declare const createIntlayerProxyHandler: (options?: IntlayerProxyPluginOptions) => NodeMiddleware;
|
|
70
70
|
/**
|
|
71
71
|
* Vite plugin that provides locale-based routing middleware for **all environments**:
|
|
72
72
|
* development, preview, and production SSR (Nitro / TanStack Start).
|
|
@@ -108,7 +108,7 @@ declare const createIntlayerProxyHandler: (options?: IntlayerProxyPluginOptions)
|
|
|
108
108
|
*
|
|
109
109
|
* @deprecated Since Intlayer v9, `intlayerProxy()` is bundled directly into the `intlayer()` plugin and enabled by default through the `routing.enableProxy` option (unset by default, which selects auto mode). Registering it separately as shown below is now optional.
|
|
110
110
|
*/
|
|
111
|
-
declare const intlayerProxy: (options?: IntlayerProxyPluginOptions) => Plugin;
|
|
111
|
+
export declare const intlayerProxy: (options?: IntlayerProxyPluginOptions) => Plugin;
|
|
112
112
|
/**
|
|
113
113
|
* @deprecated Rename to intlayerProxy instead
|
|
114
114
|
*
|
|
@@ -121,7 +121,7 @@ declare const intlayerProxy: (options?: IntlayerProxyPluginOptions) => Plugin;
|
|
|
121
121
|
* });
|
|
122
122
|
* ```
|
|
123
123
|
*/
|
|
124
|
-
declare const intlayerMiddleware: typeof intlayerProxy;
|
|
124
|
+
export declare const intlayerMiddleware: typeof intlayerProxy;
|
|
125
125
|
/**
|
|
126
126
|
* @deprecated Rename to intlayerProxy instead
|
|
127
127
|
*
|
|
@@ -134,7 +134,6 @@ declare const intlayerMiddleware: typeof intlayerProxy;
|
|
|
134
134
|
* });
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
declare const intLayerMiddlewarePlugin: typeof intlayerProxy;
|
|
137
|
+
export declare const intLayerMiddlewarePlugin: typeof intlayerProxy;
|
|
138
138
|
//#endregion
|
|
139
|
-
export { IntlayerProxyPluginOptions, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy };
|
|
140
139
|
//# sourceMappingURL=intlayerProxyPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxyPlugin.d.ts","names":[],"sources":["../../src/intlayerProxyPlugin.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"intlayerProxyPlugin.d.ts","names":[],"sources":["../../src/intlayerProxyPlugin.ts"],"mappings":";;;;;YA6BY;;;;;;;;;;;;;;EAcV,UAAU,KAAK;;;;;;;;;;;EAWf,gBAAgB;;;;;;;;;;;;;;EAchB;;;;;;;;;;;;;;;;;;;;;;;;qBAyBW,6BAA0B,UAC3B,+BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgDU,gBAAa,UAAc,+BAA6B;;;;;;;;;;;;;qBAuIxD,2BAAkB;;;;;;;;;;;;;qBAclB,iCAAwB"}
|
|
@@ -34,7 +34,6 @@ import { PruneContext } from "@intlayer/babel";
|
|
|
34
34
|
* @param pruneContext - Shared state produced by the usage analyser that
|
|
35
35
|
* runs inside `intlayerOptimizePlugin`.
|
|
36
36
|
*/
|
|
37
|
-
declare const intlayerPrune: (intlayerConfig: IntlayerConfig, pruneContext: PruneContext) => PluginOption[];
|
|
37
|
+
export declare const intlayerPrune: (intlayerConfig: IntlayerConfig, pruneContext: PruneContext) => PluginOption[];
|
|
38
38
|
//#endregion
|
|
39
|
-
export { intlayerPrune };
|
|
40
39
|
//# sourceMappingURL=intlayerPrunePlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPrunePlugin.d.ts","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerPrunePlugin.d.ts","names":[],"sources":["../../src/intlayerPrunePlugin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiNa,gBAAa,gBACR,gBAAc,cAChB,iBACb"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IntlayerConfig } from "@intlayer/types/config";
|
|
2
2
|
import { PluginOption } from "vite";
|
|
3
3
|
//#region src/intlayerVueAsyncPlugin.d.ts
|
|
4
|
-
declare const intlayerVueAsyncPlugin: (configuration: IntlayerConfig, filesList: string[]) => PluginOption;
|
|
4
|
+
export declare const intlayerVueAsyncPlugin: (configuration: IntlayerConfig, filesList: string[]) => PluginOption;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { intlayerVueAsyncPlugin };
|
|
7
6
|
//# sourceMappingURL=intlayerVueAsyncPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerVueAsyncPlugin.d.ts","names":[],"sources":["../../src/intlayerVueAsyncPlugin.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"intlayerVueAsyncPlugin.d.ts","names":[],"sources":["../../src/intlayerVueAsyncPlugin.ts"],"mappings":";;;qBAIa,yBAAsB,eAClB,gBAAc,wBAE5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.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": [
|
|
@@ -81,27 +81,27 @@
|
|
|
81
81
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@intlayer/babel": "9.
|
|
85
|
-
"@intlayer/config": "9.
|
|
86
|
-
"@intlayer/core": "9.
|
|
87
|
-
"@intlayer/dictionaries-entry": "9.
|
|
88
|
-
"@intlayer/engine": "9.
|
|
89
|
-
"@intlayer/types": "9.
|
|
84
|
+
"@intlayer/babel": "9.5.0",
|
|
85
|
+
"@intlayer/config": "9.5.0",
|
|
86
|
+
"@intlayer/core": "9.5.0",
|
|
87
|
+
"@intlayer/dictionaries-entry": "9.5.0",
|
|
88
|
+
"@intlayer/engine": "9.5.0",
|
|
89
|
+
"@intlayer/types": "9.5.0"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@types/node": "26.
|
|
92
|
+
"@types/node": "26.5.0",
|
|
93
93
|
"@utils/ts-config": "1.0.4",
|
|
94
94
|
"@utils/ts-config-types": "1.0.4",
|
|
95
95
|
"@utils/tsdown-config": "1.0.4",
|
|
96
96
|
"rimraf": "6.1.3",
|
|
97
|
-
"tsdown": "0.
|
|
97
|
+
"tsdown": "0.23.0",
|
|
98
98
|
"typescript": "7.0.2",
|
|
99
|
-
"vitest": "
|
|
99
|
+
"vitest": "5.0.0"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"@babel/core": ">=6.0.0",
|
|
103
|
-
"@intlayer/svelte-compiler": "9.
|
|
104
|
-
"@intlayer/vue-compiler": "9.
|
|
103
|
+
"@intlayer/svelte-compiler": "9.5.0",
|
|
104
|
+
"@intlayer/vue-compiler": "9.5.0",
|
|
105
105
|
"h3": ">=1.0.0",
|
|
106
106
|
"vite": ">=4.0.0"
|
|
107
107
|
},
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/pruneContext.ts
|
|
2
|
-
const createPruneContext = () => ({
|
|
3
|
-
dictionaryKeyToFieldUsageMap: /* @__PURE__ */ new Map(),
|
|
4
|
-
dictionariesWithEdgeCases: /* @__PURE__ */ new Set(),
|
|
5
|
-
hasUnparsableSourceFiles: false,
|
|
6
|
-
dictionaryKeysWithUntrackedBindings: /* @__PURE__ */ new Map(),
|
|
7
|
-
dictionaryKeyToFieldRenameMap: /* @__PURE__ */ new Map(),
|
|
8
|
-
dictionaryKeysWithOpaqueFields: /* @__PURE__ */ new Map(),
|
|
9
|
-
dictionariesSkippingFieldRename: /* @__PURE__ */ new Set(),
|
|
10
|
-
pendingFrameworkAnalysis: /* @__PURE__ */ new Map()
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { createPruneContext };
|
|
15
|
-
//# sourceMappingURL=pruneContext.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pruneContext.mjs","names":[],"sources":["../../src/pruneContext.ts"],"sourcesContent":["// Re-export PruneContext types from @intlayer/babel so both the vite plugins\n// and the babel plugins share the same type definitions.\n\nimport type { PruneContext } from '@intlayer/babel';\n\n// createPruneContext is kept here as a local runtime value so that\n// vite-intlayer does not depend on @intlayer/babel's dist being built\n// with the new exports before this plugin can load.\nexport const createPruneContext = (): PruneContext => ({\n dictionaryKeyToFieldUsageMap: new Map(),\n dictionariesWithEdgeCases: new Set(),\n hasUnparsableSourceFiles: false,\n dictionaryKeysWithUntrackedBindings: new Map(),\n dictionaryKeyToFieldRenameMap: new Map(),\n dictionaryKeysWithOpaqueFields: new Map(),\n dictionariesSkippingFieldRename: new Set(),\n pendingFrameworkAnalysis: new Map(),\n});\n"],"mappings":";AAQA,MAAa,4BAA0C;CACrD,8CAA8B,IAAI,IAAI;CACtC,2CAA2B,IAAI,IAAI;CACnC,0BAA0B;CAC1B,qDAAqC,IAAI,IAAI;CAC7C,+CAA+B,IAAI,IAAI;CACvC,gDAAgC,IAAI,IAAI;CACxC,iDAAiC,IAAI,IAAI;CACzC,0CAA0B,IAAI,IAAI;AACpC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pruneContext.d.ts","names":[],"sources":["../../src/pruneContext.ts"],"mappings":";;cAQa,0BAAyB"}
|