morrowdigital / watermelondb-expo-plugin

119 stars 30 forks source link

Support for Usage In Monorepos #36

Closed garygcchiu closed 4 months ago

garygcchiu commented 7 months ago

I have my project structure in a typical monorepo structure like the following:

I believe the paths to dependencies are hardcoded to be in ../node_modules/: https://github.com/morrowdigital/watermelondb-expo-plugin/blob/main/src/withWatermelon.ts#L250-L252

  pod 'WatermelonDB', :path => '../node_modules/@nozbe/watermelondb'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true
  pod 'simdjson', path: '../node_modules/@nozbe/simdjson', :modular_headers => true\n\n  `;

This would lead to the following issue during the build, since in a Yarn monorepo workspace, dependencies are hoisted higher together in the hierarchy and this error would occur locally and via EAS Build (with or without dev client enabled):

➜ npx expo prebuild --platform ios                                                                              
✔ Created native directory
✔ Updated package.json | no changes
» ios: icon: This is the image that your app uses on your home screen, you will need to configure it manually.
✔ Finished prebuild
⚠️  Something went wrong running `pod install` in the `ios` directory.
Command `pod install` failed.
└─ Cause: There are multiple dependencies with different sources for `simdjson` in `Podfile`:

- simdjson (from `../../../node_modules/@nozbe/simdjson`)
- simdjson (from `../node_modules/@nozbe/simdjson`)

pod install --repo-update --ansi exited with non-zero code: 1

Failed build from EAS: image

I think some people would like to develop in a monorepo structure, an example here using WatermelonDB + Expo + monorepo: [ShareMyStack]

Is there a way to specify the path for the workspace root, (i.e. ../../ instead of ./)? Or a way to pass the paths to the dependencies another way?

Thank you!

garygcchiu commented 7 months ago

For others that may run into this issue, as inspired by the repo above, their workaround/solution is to not use this plugin altogether, and specify simdjson as an extraPods in the expo-build-properties plugin: [Code]

[
      "expo-build-properties",
      {
        ios: {
          extraPods: [
            {
              name: "simdjson",
              configurations: ["Debug", "Release"],
              path: "../../../node_modules/@nozbe/simdjson",
              modular_headers: true,
            },
          ],
        },
      },
    ],
]

However, I feel like this plugin solves other issues, and would be ideal if we can use this plugin.

Note: this is not a blocker and the workaround/alternative above works. As I understand it, simdjson is the only native library that is required, looking at WatermelonDB's docs.

killerchip commented 7 months ago

@garygcchiu Thanks for your feedback. I'll check first chance if we can have this as an option to the plugin for easier configuration.

atanaskanchev commented 7 months ago

I wonder how wmdb works in this production app that is using turborepo 🤔

killerchip commented 7 months ago

this production app

I think it just adds 'extra pods' for ios, without using the plugin. On Android part, I don't think it enables JSI interface (not thoroughly checked though)

clmoreno commented 6 months ago

I created a PR to add monorepo support https://github.com/morrowdigital/watermelondb-expo-plugin/pull/37

killerchip commented 5 months ago

I created a PR to add monorepo support #37

It is now in beta. yarn add @morrowdigital/watermelondb-expo-plugin@beta to install and test it.

thanks @clmoreno

killerchip commented 4 months ago

This fix is now public in 2.3.2