@intlayer/next-i18next 9.0.0-canary.11 → 9.0.0-canary.12
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.
|
@@ -5,8 +5,9 @@ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
|
5
5
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
6
|
let node_module = require("node:module");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
|
-
let
|
|
8
|
+
let _intlayer_config_callers = require("@intlayer/config/callers");
|
|
9
9
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
10
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
10
11
|
let next_intlayer_server = require("next-intlayer/server");
|
|
11
12
|
|
|
12
13
|
//#region src/plugin/index.ts
|
|
@@ -81,17 +82,12 @@ const resolveEsmPath = (specifier) => {
|
|
|
81
82
|
* @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.
|
|
82
83
|
*/
|
|
83
84
|
const toTurbopackAlias = (absolutePath) => `./${(0, node_path.relative)(process.cwd(), absolutePath).split(node_path.sep).join("/")}`;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
],
|
|
91
|
-
namespaceArgIndex: 0,
|
|
92
|
-
staticReplacement: "useDictionary",
|
|
93
|
-
dynamicReplacement: "useDictionaryDynamic"
|
|
94
|
-
}];
|
|
85
|
+
/**
|
|
86
|
+
* SWC extra-caller configs derived from the shared caller registry
|
|
87
|
+
* (`@intlayer/config/callers`) — the single source of truth also consumed by
|
|
88
|
+
* the babel analyzer/optimizer and the LSP.
|
|
89
|
+
*/
|
|
90
|
+
const NEXT_I18NEXT_SWC_CALLERS = (0, _intlayer_config_callers.toSwcExtraCallers)(_intlayer_config_callers.REACT_I18NEXT_CALLERS);
|
|
95
91
|
/**
|
|
96
92
|
* Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js
|
|
97
93
|
* config so the runtime dictionary registry stays populated. Mutates the
|
|
@@ -118,7 +114,7 @@ const createNextI18nPlugin = (_i18nPath) => {
|
|
|
118
114
|
return async (nextConfig = {}) => {
|
|
119
115
|
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
120
116
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
121
|
-
(0,
|
|
117
|
+
(0, _intlayer_engine_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
122
118
|
appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
|
|
123
119
|
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
124
120
|
const customWebpack = nextConfig.webpack;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["sep","ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\nconst NEXT_I18NEXT_SWC_CALLERS = [\n {\n callerName: 'useTranslation',\n importSources: ['react-i18next', '@intlayer/react-i18next', 'next-i18next'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n];\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\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ACnD,iBAAiB,0BAClB,CAAC;AAUF,yBAAuB,YAAY;AAEnC,SAAO;;;;;;;;;;;;;AAgBX,MAAa,cAAc,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["sep","REACT_I18NEXT_CALLERS","ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport {\n REACT_I18NEXT_CALLERS,\n toSwcExtraCallers,\n} from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * SWC extra-caller configs derived from the shared caller registry\n * (`@intlayer/config/callers`) — the single source of truth also consumed by\n * the babel analyzer/optimizer and the LSP.\n */\nconst NEXT_I18NEXT_SWC_CALLERS = toSwcExtraCallers(REACT_I18NEXT_CALLERS);\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,6FAA8C;;;;;AAMpD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAgB,aAAa;EAA0B;CAClE;EAAE,SAAS;EAAiB,aAAa;EAA2B;CACpE;EAAE,SAAS;EAAW,aAAa;EAAqB;CACzD;;;;;;;;AASD,MAAM,kBACJ,cAC+C;CAC/C,MAAM,WAAW,UAAU,MAAM,IAAI;CACrC,MAAM,cAAc,UAAU,WAAW,IAAI,GACzC,SAAS,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI,GAC7B,SAAS,MAAM;CACpB,MAAM,U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CACF;EAED,MAAM,gBAAgB,WAAW;EAEjC,MAAM,kBAAkB,cAAc,KAAK,EAAE,SAAS,mBAAmB;GACvE;GACA,cAAc,eAAe,YAAY;GAC1C,EAAE;EAGH,MAAM,eAAe,OAAO,YAC1B,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,aACD,CAAC,CACH;EAGD,MAAM,aAAa,OAAO,YACxB,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,iBAAiB,aAAa,CAC/B,CAAC,CACH;EAED,MAAM,cAAc,EAClB,UAAU,QAAa,YAAiB;AACtC,UAAO,QAAQ,QAAQ;IACrB,GAAG,OAAO,QAAQ;IAClB,GAAG;IACJ;AAED,OAAI,OAAO,kBAAkB,WAC3B,QAAO,cAAc,QAAQ,QAAQ;AAEvC,UAAO;KAEV;EAcD,MAAM,cAAc,6CAAmB;GAXrC,GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,EAAE;IAC9B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,EAAE;KAC5C,GAAG;KACJ;IACF;GAGgD,EAAE,EACnD,iBAAiB,0BAClB,CAAC;AAUF,yBAAuB,YAAY;AAEnC,SAAO;;;;;;;;;;;;;AAgBX,MAAa,cAAc,sBAAsB"}
|
|
@@ -2,8 +2,9 @@ import * as ANSIColors from "@intlayer/config/colors";
|
|
|
2
2
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { REACT_I18NEXT_CALLERS, toSwcExtraCallers } from "@intlayer/config/callers";
|
|
6
6
|
import { getConfiguration } from "@intlayer/config/node";
|
|
7
|
+
import { runOnce } from "@intlayer/engine/utils";
|
|
7
8
|
import { withIntlayer } from "next-intlayer/server";
|
|
8
9
|
|
|
9
10
|
//#region src/plugin/index.ts
|
|
@@ -78,17 +79,12 @@ const resolveEsmPath = (specifier) => {
|
|
|
78
79
|
* @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.
|
|
79
80
|
*/
|
|
80
81
|
const toTurbopackAlias = (absolutePath) => `./${relative(process.cwd(), absolutePath).split(sep).join("/")}`;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
],
|
|
88
|
-
namespaceArgIndex: 0,
|
|
89
|
-
staticReplacement: "useDictionary",
|
|
90
|
-
dynamicReplacement: "useDictionaryDynamic"
|
|
91
|
-
}];
|
|
82
|
+
/**
|
|
83
|
+
* SWC extra-caller configs derived from the shared caller registry
|
|
84
|
+
* (`@intlayer/config/callers`) — the single source of truth also consumed by
|
|
85
|
+
* the babel analyzer/optimizer and the LSP.
|
|
86
|
+
*/
|
|
87
|
+
const NEXT_I18NEXT_SWC_CALLERS = toSwcExtraCallers(REACT_I18NEXT_CALLERS);
|
|
92
88
|
/**
|
|
93
89
|
* Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js
|
|
94
90
|
* config so the runtime dictionary registry stays populated. Mutates the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\nconst NEXT_I18NEXT_SWC_CALLERS = [\n {\n callerName: 'useTranslation',\n importSources: ['react-i18next', '@intlayer/react-i18next', 'next-i18next'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n];\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,gBAAgB,cAAc,OAAO,KAAK,IAAI;;;;;AAMpD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAgB,aAAa;EAA0B;CAClE;EAAE,SAAS;EAAiB,aAAa;EAA2B;CACpE;EAAE,SAAS;EAAW,aAAa;EAAqB;CACzD;;;;;;;;AASD,MAAM,kBACJ,cAC+C;CAC/C,MAAM,WAAW,UAAU,MAAM,IAAI;CACrC,MAAM,cAAc,UAAU,WAAW,IAAI,GACzC,SAAS,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI,GAC7B,SAAS,MAAM;CACpB,MAAM,UAAU,UAAU,MAAM,YAAY,OAAO;AACnD,QAAO;EAAE;EAAa,WAAW,YAAY,KAAK,MAAM,IAAI;EAAW;;;;;;;;;;;;;AAczE,MAAM,kBAAkB,cAA8B;CACpD,MAAM,EAAE,aAAa,cAAc,eAAe,UAAU;CAC5D,MAAM,cAAc,cAAc,GAAG,YAAY,eAAe;CAMhE,MAAM,aAAa,QACjB,cAAc,QAAQ,GAAG,YAAY,eAAe,CACrD;CAED,MAAM,cAAc,YAAY,UAAU;CAC1C,MAAM,eACJ,OAAO,gBAAgB,WACnB,cACC,aAAa,UAAU,aAAa,WAAW,aAAa;AAGnE,KAAI,CAAC,aAAc,QAAO,cAAc,QAAQ,UAAU;AAE1D,QAAO,QAAQ,YAAY,aAAa;;;;;;;;;;;;AAa1C,MAAM,oBAAoB,iBACxB,KAAK,SAAS,QAAQ,KAAK,EAAE,aAAa,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI;AAEjE,MAAM,2BAA2B,CAC/B;CACE,YAAY;CACZ,eAAe;EAAC;EAAiB;EAA2B;EAAe;CAC3E,mBAAmB;CACn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GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,EAAE;IAC9B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,EAAE;KAC5C,GAAG;KACJ;IACF;GAGgD,EAAE,EACnD,iBAAiB,0BAClB,CAAC;AAUF,yBAAuB,YAAY;AAEnC,SAAO;;;;;;;;;;;;;AAgBX,MAAa,cAAc,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport {\n REACT_I18NEXT_CALLERS,\n toSwcExtraCallers,\n} from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * SWC extra-caller configs derived from the shared caller registry\n * (`@intlayer/config/callers`) — the single source of truth also consumed by\n * the babel analyzer/optimizer and the LSP.\n */\nconst NEXT_I18NEXT_SWC_CALLERS = toSwcExtraCallers(REACT_I18NEXT_CALLERS);\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAM,gBAAgB,cAAc,OAAO,KAAK,IAAI;;;;;AAMpD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAgB,aAAa;EAA0B;CAClE;EAAE,SAAS;EAAiB,aAAa;EAA2B;CACpE;EAAE,SAAS;EAAW,aAAa;EAAqB;CACzD;;;;;;;;AASD,MAAM,kBACJ,cAC+C;CAC/C,MAAM,WAAW,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E9C,UACE,KACE,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,aAAU,CACR,SACE,+CACA,WAAW,KACZ,EACD,SACE,iDACA,WAAW,WACZ,CACF,CAAC;KAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;EAED,MAAM,gBAAgB,WAAW;EAEjC,MAAM,kBAAkB,cAAc,KAAK,EAAE,SAAS,mBAAmB;GACvE;GACA,cAAc,eAAe,YAAY;GAC1C,EAAE;EAGH,MAAM,eAAe,OAAO,YAC1B,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,aACD,CAAC,CACH;EAGD,MAAM,aAAa,OAAO,YACxB,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,iBAAiB,aAAa,CAC/B,CAAC,CACH;EAED,MAAM,cAAc,EAClB,UAAU,QAAa,YAAiB;AACtC,UAAO,QAAQ,QAAQ;IACrB,GAAG,OAAO,QAAQ;IAClB,GAAG;IACJ;AAED,OAAI,OAAO,kBAAkB,WAC3B,QAAO,cAAc,QAAQ,QAAQ;AAEvC,UAAO;KAEV;EAcD,MAAM,cAAc,MAAM,aAAa;GAXrC,GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,EAAE;IAC9B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,EAAE;KAC5C,GAAG;KACJ;IACF;GAGgD,EAAE,EACnD,iBAAiB,0BAClB,CAAC;AAUF,yBAAuB,YAAY;AAEnC,SAAO;;;;;;;;;;;;;AAgBX,MAAa,cAAc,sBAAsB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;AAwIA;;;cAAa,oBAAA,GAAwB,SAAA,eACrB,UAAA,GAAY,UAAA,KAAkB,OAAA,CAAQ,UAAA;;;;;;;;;;;cA2GzC,WAAA,GAAW,UAAA,GA3GI,UAAA,KAAkB,OAAA,CAAQ,UAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/next-i18next",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "next-i18next API adapter for intlayer — serverSideTranslations, appWithTranslation, useTranslation backed by next-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -79,14 +79,14 @@
|
|
|
79
79
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@intlayer/
|
|
83
|
-
"@intlayer/
|
|
84
|
-
"@intlayer/
|
|
85
|
-
"@intlayer/i18next": "9.0.0-canary.
|
|
86
|
-
"@intlayer/react-i18next": "9.0.0-canary.
|
|
87
|
-
"@intlayer/types": "9.0.0-canary.
|
|
88
|
-
"next-intlayer": "9.0.0-canary.
|
|
89
|
-
"react-intlayer": "9.0.0-canary.
|
|
82
|
+
"@intlayer/config": "9.0.0-canary.12",
|
|
83
|
+
"@intlayer/core": "9.0.0-canary.12",
|
|
84
|
+
"@intlayer/engine": "9.0.0-canary.12",
|
|
85
|
+
"@intlayer/i18next": "9.0.0-canary.12",
|
|
86
|
+
"@intlayer/react-i18next": "9.0.0-canary.12",
|
|
87
|
+
"@intlayer/types": "9.0.0-canary.12",
|
|
88
|
+
"next-intlayer": "9.0.0-canary.12",
|
|
89
|
+
"react-intlayer": "9.0.0-canary.12"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@types/node": "25.9.4",
|