Repository: getsentry/sentry-capacitor
Pull request #771 (2024-11-05 06:03:37)

scripts/check-siblings: Update to work with yarn patch.
I'm using `@sentry/nextjs` version `8.27.0`, and I cannot update to the latest version because of a [bug](https://github.com/getsentry/sentry-javascript/issues/14077) introduced in the next version. And there was another [bug](https://github.com/getsentry/sentry-javascript/issues/13270) on `8.27.0`. So I had to use `yarn patch` to fix the latter mentioned bug without updating the package.

`yarn patch` changes the version to something like this: `patch:@sentry/nextjs@npm%3A8.27.0#~/.yarn/patches/@sentry-nextjs-npm-8.27.0-0e3a1ce4c2.patch` This means that exact version `8.27.0` was used as base and patched.

This PR updates the sibling version check to work with `yarn patch` versions.

#skip-changelog


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 626acf5..8f69abe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@
 > [migration guide](https://docs.sentry.io/platforms/javascript/guides/capacitor/migration/) first.
 <!-- prettier-ignore-end -->
 
+## Unreleased
+
+### Fixes
+
+- options normalizeDepth and normalizeMaxBreadth are now being respected when adding a breadcrumb. ([#766](https://github.com/getsentry/sentry-capacitor/pull/766))
+
 ## 1.0.1
 
 ### Dependencies
diff --git a/scripts/check-siblings.js b/scripts/check-siblings.js
index 9785da2..8c3e05b 100644
--- a/scripts/check-siblings.js
+++ b/scripts/check-siblings.js
@@ -68,7 +68,7 @@ function ValidateSentryPackageParameters(packages) {
       if (installedVersion.split('@').length === 2) {
         errorMessages.push("You must specify the version to the package " + installedVersion + ". ( " + installedVersion + "@" + siblingVersion + ")");
       }
-      else if (!installedVersion.endsWith(siblingVersion)) {
+      else if (!installedVersion.endsWith(siblingVersion) && !installedVersion.includes('%3A' + siblingVersion + '#')) {
         errorMessages.push("You tried to install " + installedVersion + ", but the current version of  @sentry/capacitor is only compatible with version " + siblingVersion + ". Please install the dependency with the correct version.");
       }
     }
@@ -137,7 +137,7 @@ function CheckSiblings() {
 
   for (const lineData of packageJson) {
     let sentryRef = lineData.match(jsonFilter);
-    if (sentryRef && sentryRef[2] !== siblingVersion) {
+    if (sentryRef && sentryRef[2] !== siblingVersion && !sentryRef[2].includes('%3A' + siblingVersion + '#')) {
       incompatiblePackages.push(['@sentry/' + sentryRef[1], sentryRef[2]]);
     }
   }
diff --git a/src/utils/normalize.ts b/src/utils/normalize.ts
index fb3245f..7dc501d 100644
--- a/src/utils/normalize.ts
+++ b/src/utils/normalize.ts
@@ -1,3 +1,4 @@
+import { getClient } from '@sentry/core';
 import { normalize } from '@sentry/utils';
 
 const KEY = 'value';
@@ -7,7 +8,8 @@ const KEY = 'value';
  */
 // eslint-disable-next-line @typescript-eslint/no-explicit-any
 export function convertToNormalizedObject(data: unknown): Record<string, any> {
-  const normalized: unknown = normalize(data);
+  const options = getClient()?.getOptions();
+  const normalized: unknown = normalize(data, options?.normalizeDepth, options?.normalizeMaxBreadth);
   if (normalized === null || typeof normalized !== 'object') {
     return {
       [KEY]: normalized,


Test patch:
diff --git a/.github/workflows/buildandtest.yml b/.github/workflows/buildandtest.yml
index 17662c4..9b93f9c 100644
--- a/.github/workflows/buildandtest.yml
+++ b/.github/workflows/buildandtest.yml
@@ -22,9 +22,9 @@ jobs:
     timeout-minutes: 15
     steps:
       - name: Check out current commit (${{ github.sha }})
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Set up Node
-        uses: actions/setup-node@v3
+        uses: actions/setup-node@v4
         # we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
         # so no need to reinstall them
       - name: Compute dependency cache key
@@ -38,7 +38,7 @@ jobs:
           key: ${{ steps.compute_lockfile_hash.outputs.hash }}
 
       - name: Install dependencies
-        if: steps.cache_dependencies.outputs.cache-hit == ''
+        if: steps.cache_dependencies.outputs.cache-hit != 'true'
         run: yarn install
     outputs:
       dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
@@ -50,9 +50,9 @@ jobs:
     timeout-minutes: 15
     steps:
       - name: Check out current commit (${{ github.sha }})
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Set up Node
-        uses: actions/setup-node@v3
+        uses: actions/setup-node@v4
       - name: Check dependency cache
         uses: actions/cache@v4.1.0
         with:
@@ -69,11 +69,11 @@ jobs:
         # packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
         # where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of
         # this file) to a constant and skip rebuilding all of the packages each time CI runs.
-        if: steps.cache_built_packages.outputs.cache-hit == ''
+        if: steps.cache_built_packages.outputs.cache-hit != 'true'
         run: yarn build
         # yarn.lock cannot be dirty when releasing a new version.
       - name: Check if yarn.lock is dirty
-        if: steps.cache_built_packages.outputs.cache-hit == ''
+        if: steps.cache_built_packages.outputs.cache-hit != 'true'
         run: yarn install --frozen-lockfile
       - name: Publish package locally
         run: |
@@ -107,9 +107,9 @@ jobs:
           - bump: 'sample-vue'
     steps:
       - name: Check out current commit (${{ github.sha }})
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Set up Node
-        uses: actions/setup-node@v3
+        uses: actions/setup-node@v4
       - name: Check dependency cache
         uses: actions/cache@v4.1.0
         with:
@@ -149,9 +149,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Check out current commit (${{ github.sha }})
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Set up Node
-        uses: actions/setup-node@v3
+        uses: actions/setup-node@v4
       - name: Check dependency cache
         uses: actions/cache@v4.1.0
         with:
@@ -171,9 +171,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Check out current commit (${{ github.sha }})
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Set up Node
-        uses: actions/setup-node@v3
+        uses: actions/setup-node@v4
       - name: Check dependency cache
         uses: actions/cache@v4.1.0
         with:
diff --git a/test/utils/normalize.test.ts b/test/utils/normalize.test.ts
index 6e72042..19bbf3c 100644
--- a/test/utils/normalize.test.ts
+++ b/test/utils/normalize.test.ts
@@ -1,7 +1,21 @@
+import { getClient } from '@sentry/core';
+
+jest.mock('@sentry/core', () => ({
+  getClient: jest.fn(),
+}));
 import { convertToNormalizedObject } from '../../src/utils/normalize';
 
 describe('normalize', () => {
   describe('convertToNormalizedObject', () => {
+    beforeEach(() => {
+      (getClient as jest.Mock).mockReturnValue({
+          getOptions: jest.fn().mockReturnValue({
+              normalizeDepth: undefined,
+              normalizeMaxBreadth: undefined,
+          }),
+      });
+    });
+
     test('output equals input for normalized objects', () => {
       const actualResult = convertToNormalizedObject({ foo: 'bar' });
       expect(actualResult).toEqual({ foo: 'bar' });
@@ -21,5 +35,41 @@ describe('normalize', () => {
       const actualResult = convertToNormalizedObject(null);
       expect(actualResult).toEqual({ value: null });
     });
+
+    test('respect normalizeDepth and normalizeMaxBreadth when set', () => {
+      (getClient as jest.Mock).mockReturnValue({
+        getOptions: jest.fn().mockReturnValue({
+          normalizeDepth: 2,
+          normalizeMaxBreadth: 3,
+        })
+      });
+      const obj = {
+        key1: '1',
+        keyparent: {
+          child1: '1',
+          childparent2: {
+            child1: '1'
+          },
+          child2: '2',
+          child3: '3'
+        },
+        key2: '2',
+        key3: '3',
+      };
+      const expectedObj = {
+        key1: '1',
+        keyparent: {
+          child1: '1',
+          childparent2: '[Object]',
+          child2: '2',
+          child3: '[MaxProperties ~]'
+        },
+        key2: '2',
+        key3: '[MaxProperties ~]',
+      }
+
+      const actualResult = convertToNormalizedObject(obj);
+      expect((actualResult)).toStrictEqual(expectedObj);
+    });
   });
 });