react-native-intlayer 9.0.0-canary.8 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/applyIntlayerPolyfill.cjs +22 -0
- package/dist/cjs/applyIntlayerPolyfill.cjs.map +1 -0
- package/dist/cjs/configMetroIntlayer.cjs +2 -2
- package/dist/cjs/configMetroIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/intlayerPolyfill.cjs +38 -3
- package/dist/cjs/intlayerPolyfill.cjs.map +1 -1
- package/dist/cjs/intlayerProvider.cjs +1 -2
- package/dist/cjs/intlayerProvider.cjs.map +1 -1
- package/dist/esm/applyIntlayerPolyfill.mjs +22 -0
- package/dist/esm/applyIntlayerPolyfill.mjs.map +1 -0
- package/dist/esm/configMetroIntlayer.mjs +1 -1
- package/dist/esm/configMetroIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/intlayerPolyfill.mjs +38 -3
- package/dist/esm/intlayerPolyfill.mjs.map +1 -1
- package/dist/esm/intlayerProvider.mjs +1 -2
- package/dist/esm/intlayerProvider.mjs.map +1 -1
- package/dist/types/applyIntlayerPolyfill.d.ts +1 -0
- package/dist/types/configMetroIntlayer.d.ts +0 -1
- package/dist/types/configMetroIntlayer.d.ts.map +1 -1
- package/dist/types/intlayerPolyfill.d.ts.map +1 -1
- package/dist/types/intlayerProvider.d.ts +1 -6
- package/dist/types/intlayerProvider.d.ts.map +1 -1
- package/package.json +17 -13
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const require_intlayerPolyfill = require('./intlayerPolyfill.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/applyIntlayerPolyfill.ts
|
|
4
|
+
/**
|
|
5
|
+
* Side-effect module that installs the React Native polyfills as soon as it is
|
|
6
|
+
* imported.
|
|
7
|
+
*
|
|
8
|
+
* It exists so the polyfills can be applied *before* `react-intlayer` (and its
|
|
9
|
+
* transitive dependencies) are evaluated. ES module imports are hoisted, so a
|
|
10
|
+
* top-level `intlayerPolyfill()` call inside a module that also imports
|
|
11
|
+
* `react-intlayer` would run too late: the dependency's module scope is
|
|
12
|
+
* executed first, and any module-scope access to `window.location` there
|
|
13
|
+
* crashes with `Cannot read property 'href' of undefined` before a single
|
|
14
|
+
* component renders.
|
|
15
|
+
*
|
|
16
|
+
* Import this module with a bare `import './applyIntlayerPolyfill';` placed
|
|
17
|
+
* above every other import.
|
|
18
|
+
*/
|
|
19
|
+
require_intlayerPolyfill.intlayerPolyfill();
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//# sourceMappingURL=applyIntlayerPolyfill.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyIntlayerPolyfill.cjs","names":["intlayerPolyfill"],"sources":["../../src/applyIntlayerPolyfill.ts"],"sourcesContent":["import { intlayerPolyfill } from './intlayerPolyfill';\n\n/**\n * Side-effect module that installs the React Native polyfills as soon as it is\n * imported.\n *\n * It exists so the polyfills can be applied *before* `react-intlayer` (and its\n * transitive dependencies) are evaluated. ES module imports are hoisted, so a\n * top-level `intlayerPolyfill()` call inside a module that also imports\n * `react-intlayer` would run too late: the dependency's module scope is\n * executed first, and any module-scope access to `window.location` there\n * crashes with `Cannot read property 'href' of undefined` before a single\n * component renders.\n *\n * Import this module with a bare `import './applyIntlayerPolyfill';` placed\n * above every other import.\n */\nintlayerPolyfill();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBAA,0CAAiB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
let node_path = require("node:path");
|
|
3
|
-
let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
|
|
4
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
5
4
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
5
|
+
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
6
6
|
|
|
7
7
|
//#region src/configMetroIntlayer.ts
|
|
8
8
|
const getMetroResolve = () => {
|
|
@@ -133,7 +133,7 @@ const configMetroIntlayerSync = (baseConfig) => {
|
|
|
133
133
|
* > Note: `configMetroIntlayer` builds intlayer dictionaries on server start. Use `configMetroIntlayerSync` instead if you want to skip that.
|
|
134
134
|
*/
|
|
135
135
|
const configMetroIntlayer = async (baseConfig) => {
|
|
136
|
-
await (0,
|
|
136
|
+
await (0, _intlayer_engine_build.prepareIntlayer)((0, _intlayer_config_node.getConfiguration)());
|
|
137
137
|
return configMetroIntlayerSync(baseConfig);
|
|
138
138
|
};
|
|
139
139
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configMetroIntlayer.cjs","names":["pathResolve"],"sources":["../../src/configMetroIntlayer.ts"],"sourcesContent":["import { resolve as pathResolve } from 'node:path';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport type { getDefaultConfig } from 'expo/metro-config';\n\n/**\n * Returns the `resolve` function from metro-resolver, preferring the copy\n * bundled inside Metro itself. Loading from Metro's own package directory\n * ensures we use the same resolver instance that Metro uses internally,\n * which prevents the cross-version recursion described in\n * https://github.com/aymericzip/intlayer/issues/457.\n */\ntype AnyResolver = (context: any, moduleName: string, ...args: any[]) => any;\n\nconst getMetroResolve = (): AnyResolver => {\n try {\n const metroPackageDir = pathResolve(\n require.resolve('metro/package.json'),\n '..'\n );\n return (\n require(\n pathResolve(metroPackageDir, 'node_modules', 'metro-resolver')\n ) as typeof import('metro-resolver')\n ).resolve as AnyResolver;\n } catch {\n return (require('metro-resolver') as typeof import('metro-resolver'))\n .resolve as AnyResolver;\n }\n};\n\ntype MetroConfig = ReturnType<typeof getDefaultConfig>;\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayerSync } = require(\"react-native-intlayer/metro\");\n *\n *\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return configMetroIntlayerSync(defaultConfig);\n * ```\n *\n * > Note: `configMetroIntlayerSync` does not build intlayer dictionaries on server start. Use `configMetroIntlayer` for that.\n */\nexport const configMetroIntlayerSync = (\n baseConfig?: MetroConfig\n): MetroConfig => {\n const configuration = getConfiguration();\n\n const alias = getAlias({\n configuration,\n formatter: pathResolve, // get absolute path\n });\n\n /**\n * Project root, used to force `react-intlayer` to resolve to a single copy.\n *\n * Metro does not deduplicate packages the way web bundlers do. When a\n * dependency (e.g. `react-native-intlayer`) pins a different patch of\n * `react-intlayer` than the app, npm/yarn keep two physical copies. The\n * provider would then create its React context from one copy while\n * `useLocale`/`useIntlayer` read the context from the other — two distinct\n * `IntlayerClientContext` instances. The provider's updates never reach the\n * consumers, so `setLocale()` silently does nothing on native.\n *\n * Resolving every `react-intlayer` request from the project root collapses\n * those copies to a single module instance (and therefore a single context).\n */\n const projectRoot = configuration.system.baseDir;\n\n const existingBlockList = baseConfig?.resolver?.blockList;\n const existingPatterns: RegExp[] =\n existingBlockList instanceof RegExp\n ? [existingBlockList]\n : (existingBlockList ?? []);\n\n const existingResolveRequest = baseConfig?.resolver?.resolveRequest;\n\n /**\n * Tracks resolution contexts that are currently executing inside the\n * metro-resolver fallback call. When metro-resolver cannot find a module it\n * may call back through `context.resolveRequest` (the outermost resolver in\n * the chain, e.g. Sentry → NativeWind → ours). That callback eventually\n * reaches our resolver again. Without a guard we would recurse indefinitely\n * (see issue #457).\n *\n * On the second entry we break the cycle by stripping `resolveRequest` from\n * the context so metro-resolver finishes with its built-in logic only\n * (alias, extraNodeModules, …) rather than calling back a third time.\n *\n * Metro creates a fresh context object per module resolution, so using a\n * WeakSet keyed on context is safe and causes no cross-resolution\n * interference.\n */\n const inflightFallbackContexts = new WeakSet<object>();\n\n const config = {\n ...baseConfig,\n\n resolver: {\n ...baseConfig?.resolver,\n resolveRequest: (context, moduleName, ...args) => {\n if (Object.keys(alias).includes(moduleName)) {\n return {\n filePath: alias[moduleName as keyof typeof alias],\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/config/client') {\n return {\n filePath: require.resolve('@intlayer/config/client'),\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/core/file') {\n // Force React Native to use the correct transpiled version\n return {\n filePath: require.resolve('@intlayer/core/file/browser'),\n type: 'sourceFile',\n };\n }\n\n // Force a single `react-intlayer` instance regardless of which package\n // imports it (the app or a nested dependency). This prevents the\n // duplicate-context bug that silently breaks locale switching on native\n // when two `react-intlayer` copies are installed (see projectRoot doc).\n if (\n moduleName === 'react-intlayer' ||\n moduleName.startsWith('react-intlayer/')\n ) {\n try {\n return {\n filePath: require.resolve(moduleName, { paths: [projectRoot] }),\n type: 'sourceFile',\n };\n } catch {\n // Fall through to the default resolution below if the project root\n // copy cannot be resolved for some reason.\n }\n }\n\n // @formatjs packages have invalid exports configuration or missing exports for polyfills\n // By disabling package exports for these modules, we avoid the Metro warnings and let it\n // fall back cleanly to file-based resolution.\n if (moduleName.startsWith('@formatjs/')) {\n inflightFallbackContexts.add(context);\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cleanContext = {\n ...(context as any),\n unstable_enablePackageExports: false,\n };\n return getMetroResolve()(cleanContext, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n }\n\n // Delegate to the user-provided resolver if present\n if (existingResolveRequest) {\n return existingResolveRequest(context, moduleName, ...args);\n }\n\n // Re-entry guard: metro-resolver has already been invoked for this\n // context and is now calling back through context.resolveRequest (the\n // outer chain) which has bubbled back to us. Strip resolveRequest so\n // metro-resolver resolves the module with only its built-in rules\n // (alias, extraNodeModules, etc.) and does not recurse again.\n if (inflightFallbackContexts.has(context)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { resolveRequest: _r, ...pureContext } = context as any;\n return getMetroResolve()(pureContext, moduleName, ...args);\n }\n\n // First pass: call metro-resolver while preserving context.resolveRequest\n // so outer wrappers (NativeWind, Sentry, …) still get a chance to\n // handle modules that metro-resolver cannot locate on its own (e.g. @/\n // tsconfig path aliases that a wrapper resolves via its own logic).\n inflightFallbackContexts.add(context);\n try {\n return getMetroResolve()(context, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n },\n blockList: [\n ...existingPatterns,\n ...configuration.content.fileExtensions.map(\n (ext) => new RegExp(`.*${ext.replace(/\\./g, '\\\\.')}$`)\n ),\n ],\n },\n } as MetroConfig;\n\n return config;\n};\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayer } = require(\"react-native-intlayer/metro\");\n *\n * module.exports = (async () => {\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return await configMetroIntlayer(defaultConfig);\n * })();\n * ```\n *\n * > Note: `configMetroIntlayer` builds intlayer dictionaries on server start. Use `configMetroIntlayerSync` instead if you want to skip that.\n */\nexport const configMetroIntlayer = async (\n baseConfig?: MetroConfig\n): Promise<MetroConfig> => {\n const configuration = getConfiguration();\n\n await prepareIntlayer(configuration);\n\n return configMetroIntlayerSync(baseConfig);\n};\n"],"mappings":";;;;;;;AAeA,MAAM,wBAAqC;AACzC,KAAI;EACF,MAAM,yCACJ,QAAQ,QAAQ,qBAAqB,EACrC,KACD;AACD,SACE,+BACc,iBAAiB,gBAAgB,iBAAiB,CAC/D,CACD;SACI;AACN,SAAQ,QAAQ,iBAAiB,CAC9B;;;;;;;;;;;;;;;;AAmBP,MAAa,2BACX,eACgB;CAChB,MAAM,6DAAkC;CAExC,MAAM,6CAAiB;EACrB;EACA,WAAWA;EACZ,CAAC;;;;;;;;;;;;;;;CAgBF,MAAM,cAAc,cAAc,OAAO;CAEzC,MAAM,oBAAoB,YAAY,UAAU;CAChD,MAAM,mBACJ,6BAA6B,SACzB,CAAC,kBAAkB,GAClB,qBAAqB,EAA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Q,OAAO,MAAM,CAAC,GAAG,CACvD,CACF;GACF;EAGU;;;;;;;;;;;;;;;;AAiBf,MAAa,sBAAsB,OACjC,eACyB;AAGzB,kGAAmC,CAAC;AAEpC,QAAO,wBAAwB,WAAW"}
|
|
1
|
+
{"version":3,"file":"configMetroIntlayer.cjs","names":["pathResolve"],"sources":["../../src/configMetroIntlayer.ts"],"sourcesContent":["import { resolve as pathResolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { getDefaultConfig } from 'expo/metro-config';\n\n/**\n * Returns the `resolve` function from metro-resolver, preferring the copy\n * bundled inside Metro itself. Loading from Metro's own package directory\n * ensures we use the same resolver instance that Metro uses internally,\n * which prevents the cross-version recursion described in\n * https://github.com/aymericzip/intlayer/issues/457.\n */\ntype AnyResolver = (context: any, moduleName: string, ...args: any[]) => any;\n\nconst getMetroResolve = (): AnyResolver => {\n try {\n const metroPackageDir = pathResolve(\n require.resolve('metro/package.json'),\n '..'\n );\n return (\n require(\n pathResolve(metroPackageDir, 'node_modules', 'metro-resolver')\n ) as typeof import('metro-resolver')\n ).resolve as AnyResolver;\n } catch {\n return (require('metro-resolver') as typeof import('metro-resolver'))\n .resolve as AnyResolver;\n }\n};\n\ntype MetroConfig = ReturnType<typeof getDefaultConfig>;\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayerSync } = require(\"react-native-intlayer/metro\");\n *\n *\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return configMetroIntlayerSync(defaultConfig);\n * ```\n *\n * > Note: `configMetroIntlayerSync` does not build intlayer dictionaries on server start. Use `configMetroIntlayer` for that.\n */\nexport const configMetroIntlayerSync = (\n baseConfig?: MetroConfig\n): MetroConfig => {\n const configuration = getConfiguration();\n\n const alias = getAlias({\n configuration,\n formatter: pathResolve, // get absolute path\n });\n\n /**\n * Project root, used to force `react-intlayer` to resolve to a single copy.\n *\n * Metro does not deduplicate packages the way web bundlers do. When a\n * dependency (e.g. `react-native-intlayer`) pins a different patch of\n * `react-intlayer` than the app, npm/yarn keep two physical copies. The\n * provider would then create its React context from one copy while\n * `useLocale`/`useIntlayer` read the context from the other — two distinct\n * `IntlayerClientContext` instances. The provider's updates never reach the\n * consumers, so `setLocale()` silently does nothing on native.\n *\n * Resolving every `react-intlayer` request from the project root collapses\n * those copies to a single module instance (and therefore a single context).\n */\n const projectRoot = configuration.system.baseDir;\n\n const existingBlockList = baseConfig?.resolver?.blockList;\n const existingPatterns: RegExp[] =\n existingBlockList instanceof RegExp\n ? [existingBlockList]\n : (existingBlockList ?? []);\n\n const existingResolveRequest = baseConfig?.resolver?.resolveRequest;\n\n /**\n * Tracks resolution contexts that are currently executing inside the\n * metro-resolver fallback call. When metro-resolver cannot find a module it\n * may call back through `context.resolveRequest` (the outermost resolver in\n * the chain, e.g. Sentry → NativeWind → ours). That callback eventually\n * reaches our resolver again. Without a guard we would recurse indefinitely\n * (see issue #457).\n *\n * On the second entry we break the cycle by stripping `resolveRequest` from\n * the context so metro-resolver finishes with its built-in logic only\n * (alias, extraNodeModules, …) rather than calling back a third time.\n *\n * Metro creates a fresh context object per module resolution, so using a\n * WeakSet keyed on context is safe and causes no cross-resolution\n * interference.\n */\n const inflightFallbackContexts = new WeakSet<object>();\n\n const config = {\n ...baseConfig,\n\n resolver: {\n ...baseConfig?.resolver,\n resolveRequest: (context, moduleName, ...args) => {\n if (Object.keys(alias).includes(moduleName)) {\n return {\n filePath: alias[moduleName as keyof typeof alias],\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/config/client') {\n return {\n filePath: require.resolve('@intlayer/config/client'),\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/core/file') {\n // Force React Native to use the correct transpiled version\n return {\n filePath: require.resolve('@intlayer/core/file/browser'),\n type: 'sourceFile',\n };\n }\n\n // Force a single `react-intlayer` instance regardless of which package\n // imports it (the app or a nested dependency). This prevents the\n // duplicate-context bug that silently breaks locale switching on native\n // when two `react-intlayer` copies are installed (see projectRoot doc).\n if (\n moduleName === 'react-intlayer' ||\n moduleName.startsWith('react-intlayer/')\n ) {\n try {\n return {\n filePath: require.resolve(moduleName, { paths: [projectRoot] }),\n type: 'sourceFile',\n };\n } catch {\n // Fall through to the default resolution below if the project root\n // copy cannot be resolved for some reason.\n }\n }\n\n // @formatjs packages have invalid exports configuration or missing exports for polyfills\n // By disabling package exports for these modules, we avoid the Metro warnings and let it\n // fall back cleanly to file-based resolution.\n if (moduleName.startsWith('@formatjs/')) {\n inflightFallbackContexts.add(context);\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cleanContext = {\n ...(context as any),\n unstable_enablePackageExports: false,\n };\n return getMetroResolve()(cleanContext, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n }\n\n // Delegate to the user-provided resolver if present\n if (existingResolveRequest) {\n return existingResolveRequest(context, moduleName, ...args);\n }\n\n // Re-entry guard: metro-resolver has already been invoked for this\n // context and is now calling back through context.resolveRequest (the\n // outer chain) which has bubbled back to us. Strip resolveRequest so\n // metro-resolver resolves the module with only its built-in rules\n // (alias, extraNodeModules, etc.) and does not recurse again.\n if (inflightFallbackContexts.has(context)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { resolveRequest: _r, ...pureContext } = context as any;\n return getMetroResolve()(pureContext, moduleName, ...args);\n }\n\n // First pass: call metro-resolver while preserving context.resolveRequest\n // so outer wrappers (NativeWind, Sentry, …) still get a chance to\n // handle modules that metro-resolver cannot locate on its own (e.g. @/\n // tsconfig path aliases that a wrapper resolves via its own logic).\n inflightFallbackContexts.add(context);\n try {\n return getMetroResolve()(context, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n },\n blockList: [\n ...existingPatterns,\n ...configuration.content.fileExtensions.map(\n (ext) => new RegExp(`.*${ext.replace(/\\./g, '\\\\.')}$`)\n ),\n ],\n },\n } as MetroConfig;\n\n return config;\n};\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayer } = require(\"react-native-intlayer/metro\");\n *\n * module.exports = (async () => {\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return await configMetroIntlayer(defaultConfig);\n * })();\n * ```\n *\n * > Note: `configMetroIntlayer` builds intlayer dictionaries on server start. Use `configMetroIntlayerSync` instead if you want to skip that.\n */\nexport const configMetroIntlayer = async (\n baseConfig?: MetroConfig\n): Promise<MetroConfig> => {\n const configuration = getConfiguration();\n\n await prepareIntlayer(configuration);\n\n return configMetroIntlayerSync(baseConfig);\n};\n"],"mappings":";;;;;;;AAeA,MAAM,wBAAqC;CACzC,IAAI;EACF,MAAM,yCACJ,QAAQ,QAAQ,oBAAoB,GACpC,IACF;EACA,OACE,+BACc,iBAAiB,gBAAgB,gBAAgB,CAC/D,CAAC,CACD;CACJ,QAAQ;EACN,OAAQ,QAAQ,gBAAgB,CAAC,CAC9B;CACL;AACF;;;;;;;;;;;;;;AAiBA,MAAa,2BACX,eACgB;CAChB,MAAM,4DAAiC;CAEvC,MAAM,6CAAiB;EACrB;EACA,WAAWA;CACb,CAAC;;;;;;;;;;;;;;;CAgBD,MAAM,cAAc,cAAc,OAAO;CAEzC,MAAM,oBAAoB,YAAY,UAAU;CAChD,MAAM,mBACJ,6BAA6B,SACzB,CAAC,iBAAiB,IACjB,qBAAqB,CAAC;CAE7B,MAAM,yBAAyB,YAAY,UAAU;;;;;;;;;;;;;;;;;CAkBrD,MAAM,2CAA2B,IAAI,QAAgB;CAwGrD,OAAO;EArGL,GAAG;EAEH,UAAU;GACR,GAAG,YAAY;GACf,iBAAiB,SAAS,YAAY,GAAG,SAAS;IAChD,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,UAAU,GACxC,OAAO;KACL,UAAU,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-1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_intlayerPolyfill = require('./intlayerPolyfill.cjs');
|
|
3
|
+
require('./applyIntlayerPolyfill.cjs');
|
|
3
4
|
const require_intlayerProvider = require('./intlayerProvider.cjs');
|
|
4
5
|
let react_intlayer = require("react-intlayer");
|
|
5
6
|
|
|
@@ -7,7 +7,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
7
7
|
* This includes:
|
|
8
8
|
* - Polyfilling `structuredClone` if it is missing.
|
|
9
9
|
* - Providing no-op implementations for standard DOM `window` methods
|
|
10
|
-
* (`addEventListener`, `removeEventListener`, `postMessage`)
|
|
10
|
+
* (`addEventListener`, `removeEventListener`, `postMessage`) and a stub
|
|
11
|
+
* `window.location`, which React Native leaves undefined.
|
|
11
12
|
* - Providing in-memory stubs for `document.cookie`, `localStorage`, and
|
|
12
13
|
* `sessionStorage` so that `@intlayer/core`'s locale-storage helpers work
|
|
13
14
|
* without crashing in a React Native environment.
|
|
@@ -42,8 +43,31 @@ const intlayerPolyfill = () => {
|
|
|
42
43
|
if (typeof window.addEventListener !== "function") window.addEventListener = noop;
|
|
43
44
|
if (typeof window.removeEventListener !== "function") window.removeEventListener = noop;
|
|
44
45
|
if (typeof window.postMessage !== "function") window.postMessage = noop;
|
|
46
|
+
if (typeof window.location === "undefined") {
|
|
47
|
+
const appOrigin = "http://localhost";
|
|
48
|
+
Object.defineProperty(window, "location", {
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: {
|
|
52
|
+
href: `${appOrigin}/`,
|
|
53
|
+
origin: appOrigin,
|
|
54
|
+
protocol: "http:",
|
|
55
|
+
host: "localhost",
|
|
56
|
+
hostname: "localhost",
|
|
57
|
+
port: "",
|
|
58
|
+
pathname: "/",
|
|
59
|
+
search: "",
|
|
60
|
+
hash: "",
|
|
61
|
+
assign: noop,
|
|
62
|
+
replace: noop,
|
|
63
|
+
reload: noop,
|
|
64
|
+
toString: () => `${appOrigin}/`
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
45
68
|
}
|
|
46
|
-
|
|
69
|
+
const isNativeReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
70
|
+
if (typeof document === "undefined" && isNativeReactNative) {
|
|
47
71
|
let cookieJar = "";
|
|
48
72
|
Object.defineProperty(global, "document", {
|
|
49
73
|
configurable: true,
|
|
@@ -56,7 +80,18 @@ const intlayerPolyfill = () => {
|
|
|
56
80
|
const [key, val] = pair?.split("=") ?? [];
|
|
57
81
|
const name = key?.trim();
|
|
58
82
|
cookieJar = [...cookieJar.split(";").filter((c) => !c.trim().startsWith(`${name}=`)).filter(Boolean), `${name}=${val ?? ""}`].join("; ");
|
|
59
|
-
}
|
|
83
|
+
},
|
|
84
|
+
documentElement: {
|
|
85
|
+
lang: "",
|
|
86
|
+
dir: "ltr",
|
|
87
|
+
style: {}
|
|
88
|
+
},
|
|
89
|
+
createElement: () => null,
|
|
90
|
+
getElementById: () => null,
|
|
91
|
+
querySelector: () => null,
|
|
92
|
+
querySelectorAll: () => [],
|
|
93
|
+
addEventListener: () => void 0,
|
|
94
|
+
removeEventListener: () => void 0
|
|
60
95
|
})
|
|
61
96
|
});
|
|
62
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPolyfill.cjs","names":[],"sources":["../../src/intlayerPolyfill.ts"],"sourcesContent":["/**\n * Applies necessary polyfills for React Native to support Intlayer.\n *\n * This includes:\n * - Polyfilling `structuredClone` if it is missing.\n * - Providing no-op implementations for standard DOM `window` methods\n * (`addEventListener`, `removeEventListener`, `postMessage`).\n * - Providing in-memory stubs for `document.cookie`, `localStorage`, and\n * `sessionStorage` so that `@intlayer/core`'s locale-storage helpers work\n * without crashing in a React Native environment.\n *\n * Note: These stubs are in-memory only. The locale selection will survive\n * hot-reloads but not full app restarts. To persist across restarts, pass a\n * custom `setLocale` to `<IntlayerProvider>` backed by AsyncStorage.\n */\nconst createStorage = () => {\n const store: Record<string, string> = {};\n return {\n getItem: (key: string) => store[key] ?? null,\n setItem: (key: string, value: string) => {\n store[key] = String(value);\n },\n removeItem: (key: string) => {\n delete store[key];\n },\n clear: () => {\n for (const key in store) {\n delete store[key];\n }\n },\n get length() {\n return Object.keys(store).length;\n },\n key: (index: number) => Object.keys(store)[index] ?? null,\n };\n};\n\nexport const intlayerPolyfill = () => {\n if (typeof global.structuredClone !== 'function') {\n global.structuredClone = (obj) => JSON.parse(JSON.stringify(obj));\n }\n\n if (typeof window !== 'undefined') {\n const noop = () => null;\n if (typeof window.addEventListener !== 'function') {\n window.addEventListener = noop;\n }\n if (typeof window.removeEventListener !== 'function') {\n window.removeEventListener = noop;\n }\n if (typeof window.postMessage !== 'function') {\n window.postMessage = noop;\n }\n }\n\n // `@intlayer/core`'s localeStorageOptions accesses document.cookie directly.\n // In React Native, `document` is undefined — we provide a minimal
|
|
1
|
+
{"version":3,"file":"intlayerPolyfill.cjs","names":[],"sources":["../../src/intlayerPolyfill.ts"],"sourcesContent":["/**\n * Applies necessary polyfills for React Native to support Intlayer.\n *\n * This includes:\n * - Polyfilling `structuredClone` if it is missing.\n * - Providing no-op implementations for standard DOM `window` methods\n * (`addEventListener`, `removeEventListener`, `postMessage`) and a stub\n * `window.location`, which React Native leaves undefined.\n * - Providing in-memory stubs for `document.cookie`, `localStorage`, and\n * `sessionStorage` so that `@intlayer/core`'s locale-storage helpers work\n * without crashing in a React Native environment.\n *\n * Note: These stubs are in-memory only. The locale selection will survive\n * hot-reloads but not full app restarts. To persist across restarts, pass a\n * custom `setLocale` to `<IntlayerProvider>` backed by AsyncStorage.\n */\nconst createStorage = () => {\n const store: Record<string, string> = {};\n return {\n getItem: (key: string) => store[key] ?? null,\n setItem: (key: string, value: string) => {\n store[key] = String(value);\n },\n removeItem: (key: string) => {\n delete store[key];\n },\n clear: () => {\n for (const key in store) {\n delete store[key];\n }\n },\n get length() {\n return Object.keys(store).length;\n },\n key: (index: number) => Object.keys(store)[index] ?? null,\n };\n};\n\nexport const intlayerPolyfill = () => {\n if (typeof global.structuredClone !== 'function') {\n global.structuredClone = (obj) => JSON.parse(JSON.stringify(obj));\n }\n\n if (typeof window !== 'undefined') {\n const noop = () => null;\n if (typeof window.addEventListener !== 'function') {\n window.addEventListener = noop;\n }\n if (typeof window.removeEventListener !== 'function') {\n window.removeEventListener = noop;\n }\n if (typeof window.postMessage !== 'function') {\n window.postMessage = noop;\n }\n\n // React Native defines `window` (aliased to `global`) but leaves\n // `window.location` undefined. Any library reading `window.location.href`\n // — a very common `typeof window !== 'undefined'` guard pattern — then\n // crashes with `Cannot read property 'href' of undefined`, often at module\n // evaluation time, before any component renders.\n if (typeof window.location === 'undefined') {\n const appOrigin = 'http://localhost';\n\n Object.defineProperty(window, 'location', {\n configurable: true,\n writable: true,\n value: {\n href: `${appOrigin}/`,\n origin: appOrigin,\n protocol: 'http:',\n host: 'localhost',\n hostname: 'localhost',\n port: '',\n pathname: '/',\n search: '',\n hash: '',\n assign: noop,\n replace: noop,\n reload: noop,\n toString: () => `${appOrigin}/`,\n },\n });\n }\n }\n\n // `@intlayer/core`'s localeStorageOptions accesses document.cookie directly.\n // In React Native native, `document` is undefined — we provide a minimal\n // in-memory cookie jar so reads/writes work without throwing.\n //\n // We guard with `navigator.product === 'ReactNative'` to avoid installing\n // the stub in SSR / Expo Web pre-render contexts where `document` is also\n // undefined (Node.js) but browser code will later need the real DOM object\n // (e.g. document.createElement called by third-party RN libraries on web).\n const isNativeReactNative =\n typeof navigator !== 'undefined' &&\n (navigator as Navigator & { product?: string }).product === 'ReactNative';\n\n if (typeof document === 'undefined' && isNativeReactNative) {\n let cookieJar = '';\n Object.defineProperty(global, 'document', {\n configurable: true,\n get: () => ({\n get cookie() {\n return cookieJar;\n },\n set cookie(value: string) {\n // Simplified cookie setter: just append/overwrite the key\n const [pair] = value.split(';');\n const [key, val] = pair?.split('=') ?? [];\n const name = key?.trim();\n const existing = cookieJar\n .split(';')\n .filter((c) => !c.trim().startsWith(`${name}=`))\n .filter(Boolean);\n cookieJar = [...existing, `${name}=${val ?? ''}`].join('; ');\n },\n documentElement: { lang: '', dir: 'ltr', style: {} },\n createElement: () => null,\n getElementById: () => null,\n querySelector: () => null,\n querySelectorAll: () => [],\n addEventListener: () => undefined,\n removeEventListener: () => undefined,\n }),\n });\n }\n\n if (typeof localStorage === 'undefined') {\n Object.defineProperty(global, 'localStorage', {\n configurable: true,\n value: createStorage(),\n });\n }\n\n if (typeof sessionStorage === 'undefined') {\n Object.defineProperty(global, 'sessionStorage', {\n configurable: true,\n value: createStorage(),\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAM,sBAAsB;CAC1B,MAAM,QAAgC,CAAC;CACvC,OAAO;EACL,UAAU,QAAgB,MAAM,QAAQ;EACxC,UAAU,KAAa,UAAkB;GACvC,MAAM,OAAO,OAAO,KAAK;EAC3B;EACA,aAAa,QAAgB;GAC3B,OAAO,MAAM;EACf;EACA,aAAa;GACX,KAAK,MAAM,OAAO,OAChB,OAAO,MAAM;EAEjB;EACA,IAAI,SAAS;GACX,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC;EAC5B;EACA,MAAM,UAAkB,OAAO,KAAK,KAAK,CAAC,CAAC,UAAU;CACvD;AACF;AAEA,MAAa,yBAAyB;CACpC,IAAI,OAAO,OAAO,oBAAoB,YACpC,OAAO,mBAAmB,QAAQ,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;CAGlE,IAAI,OAAO,WAAW,aAAa;EACjC,MAAM,aAAa;EACnB,IAAI,OAAO,OAAO,qBAAqB,YACrC,OAAO,mBAAmB;EAE5B,IAAI,OAAO,OAAO,wBAAwB,YACxC,OAAO,sBAAsB;EAE/B,IAAI,OAAO,OAAO,gBAAgB,YAChC,OAAO,cAAc;EAQvB,IAAI,OAAO,OAAO,aAAa,aAAa;GAC1C,MAAM,YAA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|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
2
|
+
require('./applyIntlayerPolyfill.cjs');
|
|
3
3
|
let react_intlayer = require("react-intlayer");
|
|
4
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
5
|
|
|
6
6
|
//#region src/intlayerProvider.tsx
|
|
7
|
-
require_intlayerPolyfill.intlayerPolyfill();
|
|
8
7
|
/**
|
|
9
8
|
* Provider component that wraps your application and provides the Intlayer context.
|
|
10
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProvider.cjs","names":["
|
|
1
|
+
{"version":3,"file":"intlayerProvider.cjs","names":["IntlayerProviderContent"],"sources":["../../src/intlayerProvider.tsx"],"sourcesContent":["// Must stay first: installs the React Native polyfills before `react-intlayer`\n// module scope runs. See `applyIntlayerPolyfill.ts`.\nimport './applyIntlayerPolyfill';\nimport {\n IntlayerProviderContent,\n type IntlayerProviderProps as IntlayerProviderPropsBase,\n} from 'react-intlayer';\n\n/**\n * Props accepted by the React Native `IntlayerProvider`.\n *\n * Editor-specific (`disableEditor`) and cookie-specific (`isCookieEnabled`)\n * options are omitted because they are not applicable in a React Native\n * environment.\n */\nexport type IntlayerProviderProps = Omit<\n IntlayerProviderPropsBase,\n 'disableEditor' | 'isCookieEnabled'\n>;\n\n/**\n * Provider component that wraps your application and provides the Intlayer context.\n *\n * This provider also automatically applies necessary polyfills for React Native.\n *\n * @param props - The provider props, excluding editor-specific and cookie-specific options which are not applicable in React Native.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-native-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider = ({\n children,\n ...props\n}: IntlayerProviderProps) => (\n <IntlayerProviderContent {...props}>{children}</IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,oBAAoB,EAC/B,UACA,GAAG,YAEH,2CAACA,wCAAD;CAAyB,GAAI;CAAQ;AAAkC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { intlayerPolyfill } from "./intlayerPolyfill.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/applyIntlayerPolyfill.ts
|
|
4
|
+
/**
|
|
5
|
+
* Side-effect module that installs the React Native polyfills as soon as it is
|
|
6
|
+
* imported.
|
|
7
|
+
*
|
|
8
|
+
* It exists so the polyfills can be applied *before* `react-intlayer` (and its
|
|
9
|
+
* transitive dependencies) are evaluated. ES module imports are hoisted, so a
|
|
10
|
+
* top-level `intlayerPolyfill()` call inside a module that also imports
|
|
11
|
+
* `react-intlayer` would run too late: the dependency's module scope is
|
|
12
|
+
* executed first, and any module-scope access to `window.location` there
|
|
13
|
+
* crashes with `Cannot read property 'href' of undefined` before a single
|
|
14
|
+
* component renders.
|
|
15
|
+
*
|
|
16
|
+
* Import this module with a bare `import './applyIntlayerPolyfill';` placed
|
|
17
|
+
* above every other import.
|
|
18
|
+
*/
|
|
19
|
+
intlayerPolyfill();
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//# sourceMappingURL=applyIntlayerPolyfill.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyIntlayerPolyfill.mjs","names":[],"sources":["../../src/applyIntlayerPolyfill.ts"],"sourcesContent":["import { intlayerPolyfill } from './intlayerPolyfill';\n\n/**\n * Side-effect module that installs the React Native polyfills as soon as it is\n * imported.\n *\n * It exists so the polyfills can be applied *before* `react-intlayer` (and its\n * transitive dependencies) are evaluated. ES module imports are hoisted, so a\n * top-level `intlayerPolyfill()` call inside a module that also imports\n * `react-intlayer` would run too late: the dependency's module scope is\n * executed first, and any module-scope access to `window.location` there\n * crashes with `Cannot read property 'href' of undefined` before a single\n * component renders.\n *\n * Import this module with a bare `import './applyIntlayerPolyfill';` placed\n * above every other import.\n */\nintlayerPolyfill();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,iBAAiB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __require } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { prepareIntlayer } from "@intlayer/chokidar/build";
|
|
4
3
|
import { getConfiguration } from "@intlayer/config/node";
|
|
5
4
|
import { getAlias } from "@intlayer/config/utils";
|
|
5
|
+
import { prepareIntlayer } from "@intlayer/engine/build";
|
|
6
6
|
|
|
7
7
|
//#region src/configMetroIntlayer.ts
|
|
8
8
|
const getMetroResolve = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configMetroIntlayer.mjs","names":["pathResolve"],"sources":["../../src/configMetroIntlayer.ts"],"sourcesContent":["import { resolve as pathResolve } from 'node:path';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport type { getDefaultConfig } from 'expo/metro-config';\n\n/**\n * Returns the `resolve` function from metro-resolver, preferring the copy\n * bundled inside Metro itself. Loading from Metro's own package directory\n * ensures we use the same resolver instance that Metro uses internally,\n * which prevents the cross-version recursion described in\n * https://github.com/aymericzip/intlayer/issues/457.\n */\ntype AnyResolver = (context: any, moduleName: string, ...args: any[]) => any;\n\nconst getMetroResolve = (): AnyResolver => {\n try {\n const metroPackageDir = pathResolve(\n require.resolve('metro/package.json'),\n '..'\n );\n return (\n require(\n pathResolve(metroPackageDir, 'node_modules', 'metro-resolver')\n ) as typeof import('metro-resolver')\n ).resolve as AnyResolver;\n } catch {\n return (require('metro-resolver') as typeof import('metro-resolver'))\n .resolve as AnyResolver;\n }\n};\n\ntype MetroConfig = ReturnType<typeof getDefaultConfig>;\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayerSync } = require(\"react-native-intlayer/metro\");\n *\n *\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return configMetroIntlayerSync(defaultConfig);\n * ```\n *\n * > Note: `configMetroIntlayerSync` does not build intlayer dictionaries on server start. Use `configMetroIntlayer` for that.\n */\nexport const configMetroIntlayerSync = (\n baseConfig?: MetroConfig\n): MetroConfig => {\n const configuration = getConfiguration();\n\n const alias = getAlias({\n configuration,\n formatter: pathResolve, // get absolute path\n });\n\n /**\n * Project root, used to force `react-intlayer` to resolve to a single copy.\n *\n * Metro does not deduplicate packages the way web bundlers do. When a\n * dependency (e.g. `react-native-intlayer`) pins a different patch of\n * `react-intlayer` than the app, npm/yarn keep two physical copies. The\n * provider would then create its React context from one copy while\n * `useLocale`/`useIntlayer` read the context from the other — two distinct\n * `IntlayerClientContext` instances. The provider's updates never reach the\n * consumers, so `setLocale()` silently does nothing on native.\n *\n * Resolving every `react-intlayer` request from the project root collapses\n * those copies to a single module instance (and therefore a single context).\n */\n const projectRoot = configuration.system.baseDir;\n\n const existingBlockList = baseConfig?.resolver?.blockList;\n const existingPatterns: RegExp[] =\n existingBlockList instanceof RegExp\n ? [existingBlockList]\n : (existingBlockList ?? []);\n\n const existingResolveRequest = baseConfig?.resolver?.resolveRequest;\n\n /**\n * Tracks resolution contexts that are currently executing inside the\n * metro-resolver fallback call. When metro-resolver cannot find a module it\n * may call back through `context.resolveRequest` (the outermost resolver in\n * the chain, e.g. Sentry → NativeWind → ours). That callback eventually\n * reaches our resolver again. Without a guard we would recurse indefinitely\n * (see issue #457).\n *\n * On the second entry we break the cycle by stripping `resolveRequest` from\n * the context so metro-resolver finishes with its built-in logic only\n * (alias, extraNodeModules, …) rather than calling back a third time.\n *\n * Metro creates a fresh context object per module resolution, so using a\n * WeakSet keyed on context is safe and causes no cross-resolution\n * interference.\n */\n const inflightFallbackContexts = new WeakSet<object>();\n\n const config = {\n ...baseConfig,\n\n resolver: {\n ...baseConfig?.resolver,\n resolveRequest: (context, moduleName, ...args) => {\n if (Object.keys(alias).includes(moduleName)) {\n return {\n filePath: alias[moduleName as keyof typeof alias],\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/config/client') {\n return {\n filePath: require.resolve('@intlayer/config/client'),\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/core/file') {\n // Force React Native to use the correct transpiled version\n return {\n filePath: require.resolve('@intlayer/core/file/browser'),\n type: 'sourceFile',\n };\n }\n\n // Force a single `react-intlayer` instance regardless of which package\n // imports it (the app or a nested dependency). This prevents the\n // duplicate-context bug that silently breaks locale switching on native\n // when two `react-intlayer` copies are installed (see projectRoot doc).\n if (\n moduleName === 'react-intlayer' ||\n moduleName.startsWith('react-intlayer/')\n ) {\n try {\n return {\n filePath: require.resolve(moduleName, { paths: [projectRoot] }),\n type: 'sourceFile',\n };\n } catch {\n // Fall through to the default resolution below if the project root\n // copy cannot be resolved for some reason.\n }\n }\n\n // @formatjs packages have invalid exports configuration or missing exports for polyfills\n // By disabling package exports for these modules, we avoid the Metro warnings and let it\n // fall back cleanly to file-based resolution.\n if (moduleName.startsWith('@formatjs/')) {\n inflightFallbackContexts.add(context);\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cleanContext = {\n ...(context as any),\n unstable_enablePackageExports: false,\n };\n return getMetroResolve()(cleanContext, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n }\n\n // Delegate to the user-provided resolver if present\n if (existingResolveRequest) {\n return existingResolveRequest(context, moduleName, ...args);\n }\n\n // Re-entry guard: metro-resolver has already been invoked for this\n // context and is now calling back through context.resolveRequest (the\n // outer chain) which has bubbled back to us. Strip resolveRequest so\n // metro-resolver resolves the module with only its built-in rules\n // (alias, extraNodeModules, etc.) and does not recurse again.\n if (inflightFallbackContexts.has(context)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { resolveRequest: _r, ...pureContext } = context as any;\n return getMetroResolve()(pureContext, moduleName, ...args);\n }\n\n // First pass: call metro-resolver while preserving context.resolveRequest\n // so outer wrappers (NativeWind, Sentry, …) still get a chance to\n // handle modules that metro-resolver cannot locate on its own (e.g. @/\n // tsconfig path aliases that a wrapper resolves via its own logic).\n inflightFallbackContexts.add(context);\n try {\n return getMetroResolve()(context, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n },\n blockList: [\n ...existingPatterns,\n ...configuration.content.fileExtensions.map(\n (ext) => new RegExp(`.*${ext.replace(/\\./g, '\\\\.')}$`)\n ),\n ],\n },\n } as MetroConfig;\n\n return config;\n};\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayer } = require(\"react-native-intlayer/metro\");\n *\n * module.exports = (async () => {\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return await configMetroIntlayer(defaultConfig);\n * })();\n * ```\n *\n * > Note: `configMetroIntlayer` builds intlayer dictionaries on server start. Use `configMetroIntlayerSync` instead if you want to skip that.\n */\nexport const configMetroIntlayer = async (\n baseConfig?: MetroConfig\n): Promise<MetroConfig> => {\n const configuration = getConfiguration();\n\n await prepareIntlayer(configuration);\n\n return configMetroIntlayerSync(baseConfig);\n};\n"],"mappings":";;;;;;;AAeA,MAAM,wBAAqC;AACzC,KAAI;EACF,MAAM,kBAAkBA,kBACd,QAAQ,qBAAqB,EACrC,KACD;AACD,mBAEIA,QAAY,iBAAiB,gBAAgB,iBAAiB,CAC/D,CACD;SACI;AACN,mBAAgB,iBAAiB,CAC9B;;;;;;;;;;;;;;;;AAmBP,MAAa,2BACX,eACgB;CAChB,MAAM,gBAAgB,kBAAkB;CAExC,MAAM,QAAQ,SAAS;EACrB;EACA,WAAWA;EACZ,CAAC;;;;;;;;;;;;;;;CAgBF,MAAM,cAAc,cAAc,OAAO;CAEzC,MAAM,oBAAoB,YAAY,UAAU;CAChD,MAAM,mBACJ,6BAA6B,SACzB,CAAC,kBAAkB,GA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AQ,OAAO,MAAM,CAAC,GAAG,CACvD,CACF;GACF;EAGU;;;;;;;;;;;;;;;;AAiBf,MAAa,sBAAsB,OACjC,eACyB;AAGzB,OAAM,gBAFgB,kBAEa,CAAC;AAEpC,QAAO,wBAAwB,WAAW"}
|
|
1
|
+
{"version":3,"file":"configMetroIntlayer.mjs","names":["pathResolve"],"sources":["../../src/configMetroIntlayer.ts"],"sourcesContent":["import { resolve as pathResolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { getDefaultConfig } from 'expo/metro-config';\n\n/**\n * Returns the `resolve` function from metro-resolver, preferring the copy\n * bundled inside Metro itself. Loading from Metro's own package directory\n * ensures we use the same resolver instance that Metro uses internally,\n * which prevents the cross-version recursion described in\n * https://github.com/aymericzip/intlayer/issues/457.\n */\ntype AnyResolver = (context: any, moduleName: string, ...args: any[]) => any;\n\nconst getMetroResolve = (): AnyResolver => {\n try {\n const metroPackageDir = pathResolve(\n require.resolve('metro/package.json'),\n '..'\n );\n return (\n require(\n pathResolve(metroPackageDir, 'node_modules', 'metro-resolver')\n ) as typeof import('metro-resolver')\n ).resolve as AnyResolver;\n } catch {\n return (require('metro-resolver') as typeof import('metro-resolver'))\n .resolve as AnyResolver;\n }\n};\n\ntype MetroConfig = ReturnType<typeof getDefaultConfig>;\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayerSync } = require(\"react-native-intlayer/metro\");\n *\n *\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return configMetroIntlayerSync(defaultConfig);\n * ```\n *\n * > Note: `configMetroIntlayerSync` does not build intlayer dictionaries on server start. Use `configMetroIntlayer` for that.\n */\nexport const configMetroIntlayerSync = (\n baseConfig?: MetroConfig\n): MetroConfig => {\n const configuration = getConfiguration();\n\n const alias = getAlias({\n configuration,\n formatter: pathResolve, // get absolute path\n });\n\n /**\n * Project root, used to force `react-intlayer` to resolve to a single copy.\n *\n * Metro does not deduplicate packages the way web bundlers do. When a\n * dependency (e.g. `react-native-intlayer`) pins a different patch of\n * `react-intlayer` than the app, npm/yarn keep two physical copies. The\n * provider would then create its React context from one copy while\n * `useLocale`/`useIntlayer` read the context from the other — two distinct\n * `IntlayerClientContext` instances. The provider's updates never reach the\n * consumers, so `setLocale()` silently does nothing on native.\n *\n * Resolving every `react-intlayer` request from the project root collapses\n * those copies to a single module instance (and therefore a single context).\n */\n const projectRoot = configuration.system.baseDir;\n\n const existingBlockList = baseConfig?.resolver?.blockList;\n const existingPatterns: RegExp[] =\n existingBlockList instanceof RegExp\n ? [existingBlockList]\n : (existingBlockList ?? []);\n\n const existingResolveRequest = baseConfig?.resolver?.resolveRequest;\n\n /**\n * Tracks resolution contexts that are currently executing inside the\n * metro-resolver fallback call. When metro-resolver cannot find a module it\n * may call back through `context.resolveRequest` (the outermost resolver in\n * the chain, e.g. Sentry → NativeWind → ours). That callback eventually\n * reaches our resolver again. Without a guard we would recurse indefinitely\n * (see issue #457).\n *\n * On the second entry we break the cycle by stripping `resolveRequest` from\n * the context so metro-resolver finishes with its built-in logic only\n * (alias, extraNodeModules, …) rather than calling back a third time.\n *\n * Metro creates a fresh context object per module resolution, so using a\n * WeakSet keyed on context is safe and causes no cross-resolution\n * interference.\n */\n const inflightFallbackContexts = new WeakSet<object>();\n\n const config = {\n ...baseConfig,\n\n resolver: {\n ...baseConfig?.resolver,\n resolveRequest: (context, moduleName, ...args) => {\n if (Object.keys(alias).includes(moduleName)) {\n return {\n filePath: alias[moduleName as keyof typeof alias],\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/config/client') {\n return {\n filePath: require.resolve('@intlayer/config/client'),\n type: 'sourceFile',\n };\n }\n\n // Because metro does not resolve submodules, we need to resolve the path manually\n if (moduleName === '@intlayer/core/file') {\n // Force React Native to use the correct transpiled version\n return {\n filePath: require.resolve('@intlayer/core/file/browser'),\n type: 'sourceFile',\n };\n }\n\n // Force a single `react-intlayer` instance regardless of which package\n // imports it (the app or a nested dependency). This prevents the\n // duplicate-context bug that silently breaks locale switching on native\n // when two `react-intlayer` copies are installed (see projectRoot doc).\n if (\n moduleName === 'react-intlayer' ||\n moduleName.startsWith('react-intlayer/')\n ) {\n try {\n return {\n filePath: require.resolve(moduleName, { paths: [projectRoot] }),\n type: 'sourceFile',\n };\n } catch {\n // Fall through to the default resolution below if the project root\n // copy cannot be resolved for some reason.\n }\n }\n\n // @formatjs packages have invalid exports configuration or missing exports for polyfills\n // By disabling package exports for these modules, we avoid the Metro warnings and let it\n // fall back cleanly to file-based resolution.\n if (moduleName.startsWith('@formatjs/')) {\n inflightFallbackContexts.add(context);\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cleanContext = {\n ...(context as any),\n unstable_enablePackageExports: false,\n };\n return getMetroResolve()(cleanContext, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n }\n\n // Delegate to the user-provided resolver if present\n if (existingResolveRequest) {\n return existingResolveRequest(context, moduleName, ...args);\n }\n\n // Re-entry guard: metro-resolver has already been invoked for this\n // context and is now calling back through context.resolveRequest (the\n // outer chain) which has bubbled back to us. Strip resolveRequest so\n // metro-resolver resolves the module with only its built-in rules\n // (alias, extraNodeModules, etc.) and does not recurse again.\n if (inflightFallbackContexts.has(context)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { resolveRequest: _r, ...pureContext } = context as any;\n return getMetroResolve()(pureContext, moduleName, ...args);\n }\n\n // First pass: call metro-resolver while preserving context.resolveRequest\n // so outer wrappers (NativeWind, Sentry, …) still get a chance to\n // handle modules that metro-resolver cannot locate on its own (e.g. @/\n // tsconfig path aliases that a wrapper resolves via its own logic).\n inflightFallbackContexts.add(context);\n try {\n return getMetroResolve()(context, moduleName, ...args);\n } finally {\n inflightFallbackContexts.delete(context);\n }\n },\n blockList: [\n ...existingPatterns,\n ...configuration.content.fileExtensions.map(\n (ext) => new RegExp(`.*${ext.replace(/\\./g, '\\\\.')}$`)\n ),\n ],\n },\n } as MetroConfig;\n\n return config;\n};\n\n/**\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { configMetroIntlayer } = require(\"react-native-intlayer/metro\");\n *\n * module.exports = (async () => {\n * const defaultConfig = getDefaultConfig(__dirname);\n *\n * return await configMetroIntlayer(defaultConfig);\n * })();\n * ```\n *\n * > Note: `configMetroIntlayer` builds intlayer dictionaries on server start. Use `configMetroIntlayerSync` instead if you want to skip that.\n */\nexport const configMetroIntlayer = async (\n baseConfig?: MetroConfig\n): Promise<MetroConfig> => {\n const configuration = getConfiguration();\n\n await prepareIntlayer(configuration);\n\n return configMetroIntlayerSync(baseConfig);\n};\n"],"mappings":";;;;;;;AAeA,MAAM,wBAAqC;CACzC,IAAI;EACF,MAAM,kBAAkBA,kBACd,QAAQ,oBAAoB,GACpC,IACF;EACA,iBAEIA,QAAY,iBAAiB,gBAAgB,gBAAgB,CAC/D,CAAC,CACD;CACJ,QAAQ;EACN,iBAAgB,gBAAgB,CAAC,CAC9B;CACL;AACF;;;;;;;;;;;;;;AAiBA,MAAa,2BACX,eACgB;CAChB,MAAM,gBAAgB,iBAAiB;CAEvC,MAAM,QAAQ,SAAS;EACrB;EACA,WAAWA;CACb,CAAC;;;;;;;;;;;;;;;CAgBD,MAAM,cAAc,cAAc,OAAO;CAEzC,MAAM,oBAAoB,YAAY,UAAU;CAChD,MAAM,mBACJ,6BAA6B,SACzB,CAAC,iBAAiB,IACjB,qBAAqB,CAAC;CAE7B,MAAM,yBAAyB,YAAY,UAAU;;;;;;;;;;;;;;;;;CAkBrD,MAAM,2CAA2B,IAAI,QAAgB;CAwGrD,OAAO;EArGL,GAAG;EAEH,UAAU;GACR,GAAG,YAAY;GACf,iBAAiB,SAAS,YAAY,GAAG,SAAS;IAChD,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,UA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esm/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { intlayerPolyfill } from "./intlayerPolyfill.mjs";
|
|
2
|
+
import "./applyIntlayerPolyfill.mjs";
|
|
2
3
|
import { IntlayerProvider } from "./intlayerProvider.mjs";
|
|
3
4
|
import { IntlayerClientContext, IntlayerProviderContent, getDictionary, getIntlayer, localeInStorage, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage, useRewriteURL } from "react-intlayer";
|
|
4
5
|
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* This includes:
|
|
6
6
|
* - Polyfilling `structuredClone` if it is missing.
|
|
7
7
|
* - Providing no-op implementations for standard DOM `window` methods
|
|
8
|
-
* (`addEventListener`, `removeEventListener`, `postMessage`)
|
|
8
|
+
* (`addEventListener`, `removeEventListener`, `postMessage`) and a stub
|
|
9
|
+
* `window.location`, which React Native leaves undefined.
|
|
9
10
|
* - Providing in-memory stubs for `document.cookie`, `localStorage`, and
|
|
10
11
|
* `sessionStorage` so that `@intlayer/core`'s locale-storage helpers work
|
|
11
12
|
* without crashing in a React Native environment.
|
|
@@ -40,8 +41,31 @@ const intlayerPolyfill = () => {
|
|
|
40
41
|
if (typeof window.addEventListener !== "function") window.addEventListener = noop;
|
|
41
42
|
if (typeof window.removeEventListener !== "function") window.removeEventListener = noop;
|
|
42
43
|
if (typeof window.postMessage !== "function") window.postMessage = noop;
|
|
44
|
+
if (typeof window.location === "undefined") {
|
|
45
|
+
const appOrigin = "http://localhost";
|
|
46
|
+
Object.defineProperty(window, "location", {
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: {
|
|
50
|
+
href: `${appOrigin}/`,
|
|
51
|
+
origin: appOrigin,
|
|
52
|
+
protocol: "http:",
|
|
53
|
+
host: "localhost",
|
|
54
|
+
hostname: "localhost",
|
|
55
|
+
port: "",
|
|
56
|
+
pathname: "/",
|
|
57
|
+
search: "",
|
|
58
|
+
hash: "",
|
|
59
|
+
assign: noop,
|
|
60
|
+
replace: noop,
|
|
61
|
+
reload: noop,
|
|
62
|
+
toString: () => `${appOrigin}/`
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
43
66
|
}
|
|
44
|
-
|
|
67
|
+
const isNativeReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
68
|
+
if (typeof document === "undefined" && isNativeReactNative) {
|
|
45
69
|
let cookieJar = "";
|
|
46
70
|
Object.defineProperty(global, "document", {
|
|
47
71
|
configurable: true,
|
|
@@ -54,7 +78,18 @@ const intlayerPolyfill = () => {
|
|
|
54
78
|
const [key, val] = pair?.split("=") ?? [];
|
|
55
79
|
const name = key?.trim();
|
|
56
80
|
cookieJar = [...cookieJar.split(";").filter((c) => !c.trim().startsWith(`${name}=`)).filter(Boolean), `${name}=${val ?? ""}`].join("; ");
|
|
57
|
-
}
|
|
81
|
+
},
|
|
82
|
+
documentElement: {
|
|
83
|
+
lang: "",
|
|
84
|
+
dir: "ltr",
|
|
85
|
+
style: {}
|
|
86
|
+
},
|
|
87
|
+
createElement: () => null,
|
|
88
|
+
getElementById: () => null,
|
|
89
|
+
querySelector: () => null,
|
|
90
|
+
querySelectorAll: () => [],
|
|
91
|
+
addEventListener: () => void 0,
|
|
92
|
+
removeEventListener: () => void 0
|
|
58
93
|
})
|
|
59
94
|
});
|
|
60
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPolyfill.mjs","names":[],"sources":["../../src/intlayerPolyfill.ts"],"sourcesContent":["/**\n * Applies necessary polyfills for React Native to support Intlayer.\n *\n * This includes:\n * - Polyfilling `structuredClone` if it is missing.\n * - Providing no-op implementations for standard DOM `window` methods\n * (`addEventListener`, `removeEventListener`, `postMessage`).\n * - Providing in-memory stubs for `document.cookie`, `localStorage`, and\n * `sessionStorage` so that `@intlayer/core`'s locale-storage helpers work\n * without crashing in a React Native environment.\n *\n * Note: These stubs are in-memory only. The locale selection will survive\n * hot-reloads but not full app restarts. To persist across restarts, pass a\n * custom `setLocale` to `<IntlayerProvider>` backed by AsyncStorage.\n */\nconst createStorage = () => {\n const store: Record<string, string> = {};\n return {\n getItem: (key: string) => store[key] ?? null,\n setItem: (key: string, value: string) => {\n store[key] = String(value);\n },\n removeItem: (key: string) => {\n delete store[key];\n },\n clear: () => {\n for (const key in store) {\n delete store[key];\n }\n },\n get length() {\n return Object.keys(store).length;\n },\n key: (index: number) => Object.keys(store)[index] ?? null,\n };\n};\n\nexport const intlayerPolyfill = () => {\n if (typeof global.structuredClone !== 'function') {\n global.structuredClone = (obj) => JSON.parse(JSON.stringify(obj));\n }\n\n if (typeof window !== 'undefined') {\n const noop = () => null;\n if (typeof window.addEventListener !== 'function') {\n window.addEventListener = noop;\n }\n if (typeof window.removeEventListener !== 'function') {\n window.removeEventListener = noop;\n }\n if (typeof window.postMessage !== 'function') {\n window.postMessage = noop;\n }\n }\n\n // `@intlayer/core`'s localeStorageOptions accesses document.cookie directly.\n // In React Native, `document` is undefined — we provide a minimal
|
|
1
|
+
{"version":3,"file":"intlayerPolyfill.mjs","names":[],"sources":["../../src/intlayerPolyfill.ts"],"sourcesContent":["/**\n * Applies necessary polyfills for React Native to support Intlayer.\n *\n * This includes:\n * - Polyfilling `structuredClone` if it is missing.\n * - Providing no-op implementations for standard DOM `window` methods\n * (`addEventListener`, `removeEventListener`, `postMessage`) and a stub\n * `window.location`, which React Native leaves undefined.\n * - Providing in-memory stubs for `document.cookie`, `localStorage`, and\n * `sessionStorage` so that `@intlayer/core`'s locale-storage helpers work\n * without crashing in a React Native environment.\n *\n * Note: These stubs are in-memory only. The locale selection will survive\n * hot-reloads but not full app restarts. To persist across restarts, pass a\n * custom `setLocale` to `<IntlayerProvider>` backed by AsyncStorage.\n */\nconst createStorage = () => {\n const store: Record<string, string> = {};\n return {\n getItem: (key: string) => store[key] ?? null,\n setItem: (key: string, value: string) => {\n store[key] = String(value);\n },\n removeItem: (key: string) => {\n delete store[key];\n },\n clear: () => {\n for (const key in store) {\n delete store[key];\n }\n },\n get length() {\n return Object.keys(store).length;\n },\n key: (index: number) => Object.keys(store)[index] ?? null,\n };\n};\n\nexport const intlayerPolyfill = () => {\n if (typeof global.structuredClone !== 'function') {\n global.structuredClone = (obj) => JSON.parse(JSON.stringify(obj));\n }\n\n if (typeof window !== 'undefined') {\n const noop = () => null;\n if (typeof window.addEventListener !== 'function') {\n window.addEventListener = noop;\n }\n if (typeof window.removeEventListener !== 'function') {\n window.removeEventListener = noop;\n }\n if (typeof window.postMessage !== 'function') {\n window.postMessage = noop;\n }\n\n // React Native defines `window` (aliased to `global`) but leaves\n // `window.location` undefined. Any library reading `window.location.href`\n // — a very common `typeof window !== 'undefined'` guard pattern — then\n // crashes with `Cannot read property 'href' of undefined`, often at module\n // evaluation time, before any component renders.\n if (typeof window.location === 'undefined') {\n const appOrigin = 'http://localhost';\n\n Object.defineProperty(window, 'location', {\n configurable: true,\n writable: true,\n value: {\n href: `${appOrigin}/`,\n origin: appOrigin,\n protocol: 'http:',\n host: 'localhost',\n hostname: 'localhost',\n port: '',\n pathname: '/',\n search: '',\n hash: '',\n assign: noop,\n replace: noop,\n reload: noop,\n toString: () => `${appOrigin}/`,\n },\n });\n }\n }\n\n // `@intlayer/core`'s localeStorageOptions accesses document.cookie directly.\n // In React Native native, `document` is undefined — we provide a minimal\n // in-memory cookie jar so reads/writes work without throwing.\n //\n // We guard with `navigator.product === 'ReactNative'` to avoid installing\n // the stub in SSR / Expo Web pre-render contexts where `document` is also\n // undefined (Node.js) but browser code will later need the real DOM object\n // (e.g. document.createElement called by third-party RN libraries on web).\n const isNativeReactNative =\n typeof navigator !== 'undefined' &&\n (navigator as Navigator & { product?: string }).product === 'ReactNative';\n\n if (typeof document === 'undefined' && isNativeReactNative) {\n let cookieJar = '';\n Object.defineProperty(global, 'document', {\n configurable: true,\n get: () => ({\n get cookie() {\n return cookieJar;\n },\n set cookie(value: string) {\n // Simplified cookie setter: just append/overwrite the key\n const [pair] = value.split(';');\n const [key, val] = pair?.split('=') ?? [];\n const name = key?.trim();\n const existing = cookieJar\n .split(';')\n .filter((c) => !c.trim().startsWith(`${name}=`))\n .filter(Boolean);\n cookieJar = [...existing, `${name}=${val ?? ''}`].join('; ');\n },\n documentElement: { lang: '', dir: 'ltr', style: {} },\n createElement: () => null,\n getElementById: () => null,\n querySelector: () => null,\n querySelectorAll: () => [],\n addEventListener: () => undefined,\n removeEventListener: () => undefined,\n }),\n });\n }\n\n if (typeof localStorage === 'undefined') {\n Object.defineProperty(global, 'localStorage', {\n configurable: true,\n value: createStorage(),\n });\n }\n\n if (typeof sessionStorage === 'undefined') {\n Object.defineProperty(global, 'sessionStorage', {\n configurable: true,\n value: createStorage(),\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,sBAAsB;CAC1B,MAAM,QAAgC,CAAC;CACvC,OAAO;EACL,UAAU,QAAgB,MAAM,QAAQ;EACxC,UAAU,KAAa,UAAkB;GACvC,MAAM,OAAO,OAAO,KAAK;EAC3B;EACA,aAAa,QAAgB;GAC3B,OAAO,MAAM;EACf;EACA,aAAa;GACX,KAAK,MAAM,OAAO,OAChB,OAAO,MAAM;EAEjB;EACA,IAAI,SAAS;GACX,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC;EAC5B;EACA,MAAM,UAAkB,OAAO,KAAK,KAAK,CAAC,CAAC,UAAU;CACvD;AACF;AAEA,MAAa,yBAAyB;CACpC,IAAI,OAAO,OAAO,oBAAoB,YACpC,OAAO,mBAAmB,QAAQ,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;CAGlE,IAAI,OAAO,WAAW,aAAa;EACjC,MAAM,aAAa;EACnB,IAAI,OAAO,OAAO,qBAAqB,YACrC,OAAO,mBAAmB;EAE5B,IAAI,OAAO,OAAO,wBAAwB,YACxC,OAAO,sBAAsB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,IAAI,OAAO,mBAAmB,aAC5B,OAAO,eAAe,QAAQ,kBAAkB;EAC9C,cAAc;EACd,OAAO,cAAc;CACvB,CAAC;AAEL"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./applyIntlayerPolyfill.mjs";
|
|
2
2
|
import { IntlayerProviderContent } from "react-intlayer";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
|
|
5
5
|
//#region src/intlayerProvider.tsx
|
|
6
|
-
intlayerPolyfill();
|
|
7
6
|
/**
|
|
8
7
|
* Provider component that wraps your application and provides the Intlayer context.
|
|
9
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProvider.mjs","names":[],"sources":["../../src/intlayerProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"intlayerProvider.mjs","names":[],"sources":["../../src/intlayerProvider.tsx"],"sourcesContent":["// Must stay first: installs the React Native polyfills before `react-intlayer`\n// module scope runs. See `applyIntlayerPolyfill.ts`.\nimport './applyIntlayerPolyfill';\nimport {\n IntlayerProviderContent,\n type IntlayerProviderProps as IntlayerProviderPropsBase,\n} from 'react-intlayer';\n\n/**\n * Props accepted by the React Native `IntlayerProvider`.\n *\n * Editor-specific (`disableEditor`) and cookie-specific (`isCookieEnabled`)\n * options are omitted because they are not applicable in a React Native\n * environment.\n */\nexport type IntlayerProviderProps = Omit<\n IntlayerProviderPropsBase,\n 'disableEditor' | 'isCookieEnabled'\n>;\n\n/**\n * Provider component that wraps your application and provides the Intlayer context.\n *\n * This provider also automatically applies necessary polyfills for React Native.\n *\n * @param props - The provider props, excluding editor-specific and cookie-specific options which are not applicable in React Native.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-native-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider = ({\n children,\n ...props\n}: IntlayerProviderProps) => (\n <IntlayerProviderContent {...props}>{children}</IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,oBAAoB,EAC/B,UACA,GAAG,YAEH,oBAAC,yBAAD;CAAyB,GAAI;CAAQ;AAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configMetroIntlayer.d.ts","names":[],"sources":["../../src/configMetroIntlayer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"configMetroIntlayer.d.ts","names":[],"sources":["../../src/configMetroIntlayer.ts"],"mappings":";;KAgCK,cAAc,kBAAkB;;;;;;;;;;;;;;cAexB,0BAAuB,aACrB,gBACZ;;;;;;;;;;;;;;;cAyKU,sBAAmB,aACjB,gBACZ,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPolyfill.d.ts","names":[],"sources":["../../src/intlayerPolyfill.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"intlayerPolyfill.d.ts","names":[],"sources":["../../src/intlayerPolyfill.ts"],"mappings":";cAsCa"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { IntlayerProviderProps as IntlayerProviderProps$1 } from "react-intlayer";
|
|
2
|
-
import * as _$react from "react";
|
|
3
|
-
|
|
4
2
|
//#region src/intlayerProvider.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* Props accepted by the React Native `IntlayerProvider`.
|
|
@@ -29,10 +27,7 @@ type IntlayerProviderProps = Omit<IntlayerProviderProps$1, 'disableEditor' | 'is
|
|
|
29
27
|
* );
|
|
30
28
|
* ```
|
|
31
29
|
*/
|
|
32
|
-
declare const IntlayerProvider: ({
|
|
33
|
-
children,
|
|
34
|
-
...props
|
|
35
|
-
}: IntlayerProviderProps) => _$react.JSX.Element;
|
|
30
|
+
declare const IntlayerProvider: ({ children, ...props }: IntlayerProviderProps) => import("react").JSX.Element;
|
|
36
31
|
//#endregion
|
|
37
32
|
export { IntlayerProvider, IntlayerProviderProps };
|
|
38
33
|
//# sourceMappingURL=intlayerProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProvider.d.ts","names":[],"sources":["../../src/intlayerProvider.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"intlayerProvider.d.ts","names":[],"sources":["../../src/intlayerProvider.tsx"],"mappings":";;;;;;;;;KAeY,wBAAwB,KAClC;;;;;;;;;;;;;;;;;;;;cAuBW,qBAAgB,aAAA,SAG1B,0CAAqB,IAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-intlayer",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A React Native plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,11 @@
|
|
|
34
34
|
"url": "https://github.com/aymericzip"
|
|
35
35
|
}
|
|
36
36
|
],
|
|
37
|
-
"sideEffects":
|
|
37
|
+
"sideEffects": [
|
|
38
|
+
"./src/applyIntlayerPolyfill.ts",
|
|
39
|
+
"./dist/esm/applyIntlayerPolyfill.mjs",
|
|
40
|
+
"./dist/cjs/applyIntlayerPolyfill.cjs"
|
|
41
|
+
],
|
|
38
42
|
"exports": {
|
|
39
43
|
".": {
|
|
40
44
|
"types": "./dist/types/index.d.ts",
|
|
@@ -110,25 +114,25 @@
|
|
|
110
114
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
111
115
|
},
|
|
112
116
|
"dependencies": {
|
|
113
|
-
"@intlayer/
|
|
114
|
-
"@intlayer/
|
|
115
|
-
"@intlayer/
|
|
116
|
-
"@intlayer/types": "9.0.0
|
|
117
|
-
"react-intlayer": "9.0.0
|
|
117
|
+
"@intlayer/config": "9.0.0",
|
|
118
|
+
"@intlayer/core": "9.0.0",
|
|
119
|
+
"@intlayer/engine": "9.0.0",
|
|
120
|
+
"@intlayer/types": "9.0.0",
|
|
121
|
+
"react-intlayer": "9.0.0"
|
|
118
122
|
},
|
|
119
123
|
"devDependencies": {
|
|
120
|
-
"@types/node": "
|
|
124
|
+
"@types/node": "26.1.1",
|
|
121
125
|
"@types/react": ">=18.0.0",
|
|
122
126
|
"@utils/ts-config": "1.0.4",
|
|
123
127
|
"@utils/ts-config-types": "1.0.4",
|
|
124
128
|
"@utils/tsdown-config": "1.0.4",
|
|
125
|
-
"expo": "
|
|
126
|
-
"metro-resolver": "0.
|
|
129
|
+
"expo": "57.0.4",
|
|
130
|
+
"metro-resolver": "0.86.0",
|
|
127
131
|
"react": ">=18.0.0",
|
|
128
132
|
"rimraf": "6.1.3",
|
|
129
|
-
"tsdown": "0.
|
|
130
|
-
"typescript": "
|
|
131
|
-
"vitest": "4.1.
|
|
133
|
+
"tsdown": "0.22.13",
|
|
134
|
+
"typescript": "7.0.2",
|
|
135
|
+
"vitest": "4.1.10"
|
|
132
136
|
},
|
|
133
137
|
"peerDependencies": {
|
|
134
138
|
"expo": ">=52",
|