Fix MMKV persistence in Metro builds (#11504)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
diff --git a/index.js b/index.js
|
||||
index 49b3650..a690ec8 100644
|
||||
--- a/index.js
|
||||
+++ b/index.js
|
||||
@@ -153,6 +153,15 @@ module.exports = function(api, options = {}) {
|
||||
const key = path.toComputedKey()
|
||||
if (t.isStringLiteral(key)) {
|
||||
const importedId = key.value
|
||||
+ // Metro uses Jest workers to transform application code. Do not
|
||||
+ // leak the build worker's ID into the application runtime, where
|
||||
+ // libraries can mistake it for an actual test environment.
|
||||
+ if (
|
||||
+ importedId === 'JEST_WORKER_ID' ||
|
||||
+ importedId === 'VITEST_WORKER_ID'
|
||||
+ ) {
|
||||
+ return
|
||||
+ }
|
||||
const value = (env && importedId in env) ? env[importedId] : process.env[importedId]
|
||||
if (value !== undefined) {
|
||||
path.replaceWith(t.valueToNode(value))
|
||||
@@ -0,0 +1,4 @@
|
||||
# react-native-dotenv@3.4.11.patch
|
||||
|
||||
Avoid inlining Metro's `JEST_WORKER_ID` or `VITEST_WORKER_ID` into application
|
||||
code, which causes libraries such as react-native-mmkv to use test-only mocks.
|
||||
Generated
+3
-2
@@ -228,6 +228,7 @@ patchedDependencies:
|
||||
expo@57.0.8: 1722861d12907a2d412d04230545b2fcbfa5547a79f99d763cb3e8de6f3a6f2a
|
||||
react-native-compressor@1.13.0: 58379dfaace6ced8590cb341c77f2ca8099dfa8f7df6297032ec51de767a9925
|
||||
react-native-date-picker@5.0.13: 92943fb79d17d7342a29bbb12b0d8ee3cf6f7bca12ed322dc8d124a3e9fb75bd
|
||||
react-native-dotenv@3.4.11: 16b34eb974399935d3cf7c2526534f906991ccd876215176658347059cdd2021
|
||||
react-native-drawer-layout@4.2.3: 74f2c043cc22ab87054f219e7c7373a509b779b18bfa79d27e7d051d73355130
|
||||
react-native-keyboard-controller@1.21.9: ac52bf7502ff3ad34a8594b5e1a916b96bf87a2523b6abc87c31f03607d52271
|
||||
react-native-pager-view@6.8.0: c8316acd33c9aef6531e8c272c2bfab7bd02af1255969eeaab2bad5ab48531cc
|
||||
@@ -853,7 +854,7 @@ importers:
|
||||
version: 3.9.6
|
||||
react-native-dotenv:
|
||||
specifier: ^3.4.11
|
||||
version: 3.4.11(@babel/runtime@7.29.2)
|
||||
version: 3.4.11(patch_hash=16b34eb974399935d3cf7c2526534f906991ccd876215176658347059cdd2021)(@babel/runtime@7.29.2)
|
||||
react-refresh:
|
||||
specifier: ^0.14.0
|
||||
version: 0.14.2
|
||||
@@ -18190,7 +18191,7 @@ snapshots:
|
||||
react: 19.2.3
|
||||
react-native: 0.86.0(patch_hash=dd549527bb84c88acc7b0b1d521c9f4b666fda484c75cd0b282f8e9838524909)(@babel/core@7.29.0(supports-color@8.1.1))(@react-native/jest-preset@0.86.0(@babel/core@7.29.0(supports-color@8.1.1))(react@19.2.3)(supports-color@8.1.1))(@react-native/metro-config@0.86.0(@babel/core@7.29.0(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1)
|
||||
|
||||
react-native-dotenv@3.4.11(@babel/runtime@7.29.2):
|
||||
react-native-dotenv@3.4.11(patch_hash=16b34eb974399935d3cf7c2526534f906991ccd876215176658347059cdd2021)(@babel/runtime@7.29.2):
|
||||
dependencies:
|
||||
'@babel/runtime': 7.29.2
|
||||
dotenv: 16.6.1
|
||||
|
||||
@@ -40,6 +40,7 @@ patchedDependencies:
|
||||
expo@57.0.8: patches/expo@57.0.8.patch
|
||||
'react-native-compressor@1.13.0': patches/react-native-compressor@1.13.0.patch
|
||||
'react-native-date-picker@5.0.13': patches/react-native-date-picker@5.0.13.patch
|
||||
'react-native-dotenv@3.4.11': patches/react-native-dotenv@3.4.11.patch
|
||||
'react-native-drawer-layout@4.2.3': patches/react-native-drawer-layout@4.2.3.patch
|
||||
'react-native-keyboard-controller@1.21.9': patches/react-native-keyboard-controller@1.21.9.patch
|
||||
'react-native-pager-view@6.8.0': patches/react-native-pager-view@6.8.0.patch
|
||||
|
||||
Reference in New Issue
Block a user