DataDog / expo-datadog

Datadog SDK for Expo
Apache License 2.0
8 stars 5 forks source link

iOS source maps not uploaded in monorepo #17

Closed dereklucas closed 1 year ago

dereklucas commented 1 year ago

Describe what happened I moved my working Expo app into a subfolder in order to turn the repo into a Yarn 3 monorepo. Functionally, that means a folder structure like this:

.
├── node_modules
└── stringer/ (Expo app)
    └── ios

Previously, the structure would have been:

.
├── node_modules
└── ios

When the app is built in Xcode (on EAS, I don't have the ability to build it locally) I get the error:

PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/Library/Developer/Xcode/DerivedData/BrightsideStaging-gcfedobscoaamwcylcgmwekhggoz/Build/Intermediates.noindex/ArchiveIntermediates/BrightsideStaging/IntermediateBuildFilesPath/BrightsideStaging.build/Release-iphoneos/BrightsideStaging.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'BrightsideStaging' from project 'BrightsideStaging')
    cd /Users/expo/workingdir/build/stringer/ios
... many many environment exports ...
    /bin/sh -c /Users/expo/Library/Developer/Xcode/DerivedData/BrightsideStaging-gcfedobscoaamwcylcgmwekhggoz/Build/Intermediates.noindex/ArchiveIntermediates/BrightsideStaging/IntermediateBuildFilesPath/BrightsideStaging.build/Release-iphoneos/BrightsideStaging.build/Script-00DD1BFF1BD5951E006B06BC.sh
/Users/expo/Library/Developer/Xcode/DerivedData/BrightsideStaging-gcfedobscoaamwcylcgmwekhggoz/Build/Intermediates.noindex/ArchiveIntermediates/BrightsideStaging/IntermediateBuildFilesPath/BrightsideStaging.build/Release-iphoneos/BrightsideStaging.build/Script-00DD1BFF1BD5951E006B06BC.sh: line 30: ../node_modules/.bin/datadog-ci: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code

(The relevant bit being line 30: ../node_modules/.bin/datadog-ci: No such file or directory)

I think that the hardcoded datadog-ci path is failing in the monorepo, because stringer/node_modules doesn't exist. I know there's potentially the ability to tell yarn to not hoist node_modules, but wouldn't it be preferable for this script to look up the correct root path? That's what it is doing here, right? https://github.com/DataDog/expo-datadog/blob/main/src/plugin/withIosSourcemaps/withIosSourcemaps.ts#L43

Steps to reproduce the issue:

Describe what you expected: Successful build.

Additional context

dereklucas commented 1 year ago

This same issue applies to DSYMs:

PhaseScriptExecution Upload\ dSYMs\ to\ Datadog /Users/expo/Library/Developer/Xcode/DerivedData/BrightsideStaging-gcfedobscoaamwcylcgmwekhggoz/Build/Intermediates.noindex/ArchiveIntermediates/BrightsideStaging/IntermediateBuildFilesPath/BrightsideStaging.build/Release-iphoneos/BrightsideStaging.build/Script-944A32652AD942D9803A0ADA.sh (in target 'BrightsideStaging' from project 'BrightsideStaging')
    cd /Users/expo/workingdir/build/stringer/ios
... Environment ...

    /bin/sh -c /Users/expo/Library/Developer/Xcode/DerivedData/BrightsideStaging-gcfedobscoaamwcylcgmwekhggoz/Build/Intermediates.noindex/ArchiveIntermediates/BrightsideStaging/IntermediateBuildFilesPath/BrightsideStaging.build/Release-iphoneos/BrightsideStaging.build/Script-944A32652AD942D9803A0ADA.sh
/Users/expo/Library/Developer/Xcode/DerivedData/BrightsideStaging-gcfedobscoaamwcylcgmwekhggoz/Build/Intermediates.noindex/ArchiveIntermediates/BrightsideStaging/IntermediateBuildFilesPath/BrightsideStaging.build/Release-iphoneos/BrightsideStaging.build/Script-944A32652AD942D9803A0ADA.sh: line 3: ../node_modules/.bin/datadog-ci: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
louiszawadzki commented 1 year ago

Hi @dereklucas, thanks for reaching out!

Indeed we don't support monorepos for Expo yet, I added it to our backlog. If this is urgent for you, you can reach out to our support team to bump its priority.

In the meantime, you can get unblocked by using a custom fork or patch-package with the following expo-datadog+49.0.1.patch patch:

diff --git a/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js b/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js
index 67dcd3b..855daae 100644
--- a/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js
+++ b/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js
@@ -15,7 +15,7 @@ const withIosDsyms = (config) => {
             return config;
         }
         xcodeProject.addBuildPhase([], "PBXShellScriptBuildPhase", BUILD_PHASE_NAME, null /* target */, {
-            shellScript: `set -e\\n ../node_modules/.bin/datadog-ci dsyms upload $DWARF_DSYM_FOLDER_PATH`,
+            shellScript: `set -e\\n ../../node_modules/.bin/datadog-ci dsyms upload $DWARF_DSYM_FOLDER_PATH`,
             shellPath: "/bin/sh",
         });
         return config;
diff --git a/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js b/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js
index bbbf2b1..ad1686a 100644
--- a/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js
+++ b/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js
@@ -7,7 +7,7 @@
 Object.defineProperty(exports, "__esModule", { value: true });
 const config_plugins_1 = require("@expo/config-plugins");
 const SOURCEMAP_FILE_COMMAND = "export SOURCEMAP_FILE=$DERIVED_FILE_DIR/main.jsbundle.map";
-const DATADOG_XCODE_COMMAND = `../node_modules/.bin/datadog-ci react-native xcode \`\\\"$NODE_BINARY\\\" --print \\\"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\\\"\``;
+const DATADOG_XCODE_COMMAND = `../../node_modules/.bin/datadog-ci react-native xcode \`\\\"$NODE_BINARY\\\" --print \\\"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\\\"\``;
 const withIosSourcemaps = (config) => {
     return (0, config_plugins_1.withXcodeProject)(config, async (config) => {
         const xcodeProject = config.modResults;
diff --git a/node_modules/expo-datadog/src/plugin/withIosDsyms/withIosDsyms.ts b/node_modules/expo-datadog/src/plugin/withIosDsyms/withIosDsyms.ts
index b75239b..d8bb21c 100644
--- a/node_modules/expo-datadog/src/plugin/withIosDsyms/withIosDsyms.ts
+++ b/node_modules/expo-datadog/src/plugin/withIosDsyms/withIosDsyms.ts
@@ -26,7 +26,7 @@ const withIosDsyms: ConfigPlugin<void> = (config) => {
       BUILD_PHASE_NAME,
       null /* target */,
       {
-        shellScript: `set -e\\n ../node_modules/.bin/datadog-ci dsyms upload $DWARF_DSYM_FOLDER_PATH`,
+        shellScript: `set -e\\n ../../node_modules/.bin/datadog-ci dsyms upload $DWARF_DSYM_FOLDER_PATH`,
         shellPath: "/bin/sh",
       }
     );
diff --git a/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts b/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts
index e3c1899..0dce4e5 100644
--- a/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts
+++ b/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts
@@ -9,7 +9,7 @@ import { withXcodeProject } from "@expo/config-plugins";

 const SOURCEMAP_FILE_COMMAND =
   "export SOURCEMAP_FILE=$DERIVED_FILE_DIR/main.jsbundle.map";
-const DATADOG_XCODE_COMMAND = `../node_modules/.bin/datadog-ci react-native xcode \`\\\"$NODE_BINARY\\\" --print \\\"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\\\"\``;
+const DATADOG_XCODE_COMMAND = `../../node_modules/.bin/datadog-ci react-native xcode \`\\\"$NODE_BINARY\\\" --print \\\"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\\\"\``;

 const withIosSourcemaps: ConfigPlugin<void> = (config) => {
   return withXcodeProject(config, async (config) => {

Let me know if we can help further!

dereklucas commented 1 year ago

Thank you for the quick solution! This worked perfectly, and should be enough for now.

wcastand commented 8 months ago

Hi, is the patch still necessary? having trouble making datadog work with expo for sourcemaps on both ios and android right now (error in EAS build)