Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix corrupted yarn.locks (software-mansion#4249)
## 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