From 8236a9e54af2632468c5bfb066f1c21206e900a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:05:32 +0200 Subject: [PATCH] fix(gradle): Dynamically resolve `collectModulesScript` path (#3092) Co-authored-by: Mateus Craveiro --- CHANGELOG.md | 4 ++++ sentry.gradle | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c92d9963..b43a7a65a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Dynamically resolve `collectModulesScript` path to support monorepos ([#3092])(https://github.com/getsentry/sentry-react-native/pull/3092) + ### Dependencies - Bump JavaScript SDK from v7.52.0 to v7.53.1 ([#3071](https://github.com/getsentry/sentry-react-native/pull/3071), [#3088](https://github.com/getsentry/sentry-react-native/pull/3088)) diff --git a/sentry.gradle b/sentry.gradle index 28230102c..b4671fa47 100644 --- a/sentry.gradle +++ b/sentry.gradle @@ -166,9 +166,15 @@ gradle.projectsEvaluated { workingDir reactRoot + def resolvedSentryPath = null + try { + resolvedSentryPath = new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile(); + } catch (Throwable ignored) {} // if the resolve fails we fallback to the default path + def sentryPackage = resolvedSentryPath != null && resolvedSentryPath.exists() ? resolvedSentryPath.getAbsolutePath() : "$reactRoot/node_modules/@sentry/react-native" + def collectModulesScript = config.collectModulesScript ? file(config.collectModulesScript).getAbsolutePath() - : "$reactRoot/node_modules/@sentry/react-native/dist/js/tools/collectModules.js" + : "$sentryPackage/dist/js/tools/collectModules.js" def modulesPaths = config.modulesPaths ? config.modulesPaths.join(',') : "$reactRoot/node_modules"