Skip to content

Commit

Permalink
Fix corrupted yarn.locks (software-mansion#4249)
Browse files Browse the repository at this point in the history
## Summary

Our `yarn.lock` files are corrupted and somehow they were not updating
properly when using `yarn`. That caused adding multiple versions of some
libraries into `node_modules` and TypeScript was going 🤪. I removed all
the `yarn.lock` files and recreated them with `yarn` and then had to fix
all the issues that were coming with that.

## Commentary on some changes

### FabricExample
@WoLewicki stated that
`FabricExample/patches/react-native-svg+13.7.0.patch` is not necessary
anymore. Bumped version in the name of the other patch file since we
didn't forbid a bump anyway.

### Jest snapshots

```diff
--- a/__tests__/__snapshots__/plugin.test.js.snap
+++ b/__tests__/__snapshots__/plugin.test.js.snap
@@ -400,7 +400,7 @@ var foo = function () {
     }, {
       b: 2,
       c: 3
-    }, {}, bar);
+    }, bar);
   };
   _f._closure = {};
   _f.__initData = _worklet_792186851025_init_data;
``` 
This was actually an overlooked bug and somehow got fixed with these
changes (my guess would be that newer versions of plugins for babel that
got included fixed it).

### babel.config.js

```diff
--- a/babel.config.js
+++ b/babel.config.js
@@ -14,5 +14,11 @@ module.exports = {
      'module:metro-react-native-babel-preset',
   ],
   plugins: [
     '@babel/plugin-proposal-class-properties',
     ['./plugin', { disableInlineStylesWarning: true }],
+    [
+      '@babel/plugin-transform-react-jsx',
+      {
+        runtime: 'classic',
+      },
+    ],
   ],
 };
```

This isn't necessary but I would recommend it for now. The reason for
this change is the fact that in newer versions of plugins that are
included in `module:metro-react-native-babel-preset` [jsx-runtime is set
as
default](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
and since we don't include old versions anymore we have to restore this
behaviour.

If we don't include this change babel will for eg. do:

```diff
@@ -1,7 +1,8 @@
+ var _jsxRuntime = require("react/jsx-runtime");
  function App() {
-   return React.createElement(Animated.View, {
+   return (0, _jsxRuntime.jsx)(Animated.View, {
```
Which I guess is not bad for us since we actually use it if we develop
apps that run this preset and use default config. For now though I'd
suggest keeping this change.

### package.json

```diff
--- a/package.json
+++ b/package.json
@@ -21,7 +21,7 @@
     "format:common": "find Common/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
     "release": "npm login && release-it",
     "type:check": "yarn tsc --noEmit && cd plugin && yarn type:check && cd ..",
-    "prepare": "bob build && husky install",
+    "prepare": "bob build && husky install && yarn plugin",
     "circular_dependency_check": "yarn madge --extensions js,ts,tsx --circular src lib",
     "setup": "yarn && cd Example && yarn && cd ios && pod install --verbose && cd ../..",
     "clean": "rm -rf node_modules && cd Example && rm -rf node_modules && cd ios && pod deintegrate && cd ../..",
@@ -91,6 +91,7 @@
     "react-native": "*"
   },
   "devDependencies": {
+    "@types/node": "12.7.12",
     "@babel/cli": "^7.17.6",
     "@babel/core": "^7.20.0",
     "@babel/plugin-proposal-class-properties": "^7.16.7",
```

First change is self-explanatory. Second one is more tricky. With the
old version of `yarn.lock` we had `@types/node` with exactly this
version( it's 3 years old!) installed when doing `yarn`. Regenerating
`yarn.lock` and doing `yarn` would install much newer version and cause
a TypeScript issue, because in newer versions of `@types/node` there is
an extra file `@types/node/globals.global.d.ts` which causes our usage
of `global` to produce a lot of errors. I plan to dive into this issue
later on but for now I want to just keep status quo.

### src/reanimated2/animation/styleAnimation.ts

```diff
--- a/src/reanimated2/animation/styleAnimation.ts
+++ b/src/reanimated2/animation/styleAnimation.ts
@@ -24,7 +24,11 @@ export function resolvePath<T>(
   return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {
     if (Array.isArray(acc) && typeof current === 'number') {
       return acc[current];
-    } else if (typeof acc === 'object' && (current as number | string) in acc) {
+    } else if (
+      acc !== null &&
+      typeof acc === 'object' &&
+      (current as number | string) in acc
+    ) {
       return (acc as { [key: string]: NestedObjectValues<T> })[
         current as number | string
       ];
```

null guard (error stemmed from bumping packages through new yarn.lock)

### src/reanimated2/shareables.ts

```diff
--- a/src/reanimated2/shareables.ts
+++ b/src/reanimated2/shareables.ts
@@ -125,7 +125,7 @@ export function makeShareableCloneOnUIRecursive<T>(value: T): ShareableRef<T> {
       let toAdapt: any;
       if (Array.isArray(value)) {
         toAdapt = value.map((element) => cloneRecursive(element));
-      } else {
+      } else if (value !== undefined) {
         toAdapt = {};
         for (const [key, element] of Object.entries(value)) {
           toAdapt[key] = cloneRecursive(element);
```

undefined guard (error stemmed from bumping packages through new
yarn.lock)

## Test plan

- `yarn jest`
- build Example and run it
- build FabricExample and run it
- build TVOSExample and run it to see that it doesn't work same as on
current main
- build WebExample and run it to see that it might not work same as on
current main
  • Loading branch information
tjzel authored and fluiddot committed Jun 5, 2023
1 parent 4d6777a commit fcc023f
Show file tree
Hide file tree
Showing 17 changed files with 9,020 additions and 13,160 deletions.
16 changes: 8 additions & 8 deletions Example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ PODS:
- React-jsinspector (0.71.3)
- React-logger (0.71.3):
- glog
- react-native-pager-view (5.4.1):
- react-native-pager-view (5.4.25):
- React-Core
- react-native-safe-area-context (4.5.0):
- RCT-Folly
- RCTRequired
- RCTTypeSafety
- React-Core
- ReactCommon/turbomodule/core
- react-native-slider (4.4.0):
- react-native-slider (4.4.2):
- React-Core
- React-perflogger (0.71.3)
- React-RCTActionSheet (0.71.3):
Expand Down Expand Up @@ -456,10 +456,10 @@ PODS:
- React-RCTText
- ReactCommon/turbomodule/core
- Yoga
- RNScreens (3.19.0):
- RNScreens (3.20.0):
- React-Core
- React-RCTImage
- RNSVG (13.7.0):
- RNSVG (13.8.0):
- React-Core
- SocketRocket (0.6.0)
- Yoga (1.14.0)
Expand Down Expand Up @@ -676,9 +676,9 @@ SPEC CHECKSUMS:
React-jsiexecutor: 515b703d23ffadeac7687bc2d12fb08b90f0aaa1
React-jsinspector: 9f7c9137605e72ca0343db4cea88006cb94856dd
React-logger: 957e5dc96d9dbffc6e0f15e0ee4d2b42829ff207
react-native-pager-view: 43f51f45f37ec9715f6c188e4af46ccdf79872e8
react-native-pager-view: da490aa1f902c9a5aeecf0909cc975ad0e92e53e
react-native-safe-area-context: 39c2d8be3328df5d437ac1700f4f3a4f75716acc
react-native-slider: d2938a12c4e439a227c70eec65d119136eb4aeb5
react-native-slider: 33b8d190b59d4f67a541061bb91775d53d617d9d
React-perflogger: af8a3d31546077f42d729b949925cc4549f14def
React-RCTActionSheet: 57cc5adfefbaaf0aae2cf7e10bccd746f2903673
React-RCTAnimation: 11c61e94da700c4dc915cf134513764d87fc5e2b
Expand All @@ -696,8 +696,8 @@ SPEC CHECKSUMS:
RNCPicker: 914b557e20b3b8317b084aca9ff4b4edb95f61e4
RNGestureHandler: 071d7a9ad81e8b83fe7663b303d132406a7d8f39
RNReanimated: f0dd6b881808e635ef0673f89642937d6c141314
RNScreens: ea4cd3a853063cda19a4e3c28d2e52180c80f4eb
RNSVG: d787d64ca06b9158e763ad2638a8c4edce00782a
RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f
RNSVG: c1e76b81c76cdcd34b4e1188852892dc280eb902
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Yoga: 5ed1699acbba8863755998a4245daa200ff3817b
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
6 changes: 3 additions & 3 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
},
"dependencies": {
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/react-native-fontawesome": "^0.2.3",
"@fortawesome/fontawesome-svg-core": "6.3.0",
"@fortawesome/free-solid-svg-icons": "6.3.0",
"@fortawesome/react-native-fontawesome": "0.3.0",
"@react-native-community/picker": "^1.8.1",
"@react-native-community/slider": "^4.4.0",
"@react-native-masked-view/masked-view": "^0.2.8",
Expand Down
Loading

0 comments on commit fcc023f

Please sign in to comment.