sentry-capacitor icon indicating copy to clipboard operation
sentry-capacitor copied to clipboard

Add sibling check

Open lucas-zimerman opened this issue 1 year ago • 1 comments

The goal is to better inform the user that Sentry/Capacitor requires the exact version on the Sibling SDKs as defined on the peerDependency.

This code will look for any @sentry/package references on the packages.json file from the user's project, if those references doesn't match the required one by the script, the script will warn the user about it when a dependency gets installed or updated.

Some questions in regard to this feature:

  • Should it feature just warn the user or throw an error when installing/updating the dependency?

If we throw an error, the user will only be able to update the project if he/she updates all sibling dependencies in one command (ie yarn add @sentry/[email protected] @sentry/[email protected] @sentry/[email protected] --exact)

Fixes #45, #218

lucas-zimerman avatar Oct 20 '22 12:10 lucas-zimerman

Fails
:no_entry_sign: Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number. Example:

## Unreleased

### Fixes/Features

- Add sibling check ([#248](https://github.com/getsentry/sentry-capacitor/pull/248))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by :no_entry_sign: dangerJS against 467a42fa7d2402b06d40536782645d720170088b

github-actions[bot] avatar Oct 20 '22 12:10 github-actions[bot]

Added more code after validating both yarn/npm. When using yarn, we can validate the packages in two places

  1. The console arguments (yarn install @sentry/[email protected] In this case we can simply validate if the sentry version requested is compatible with the current capacitor version (avoiding the parse of the package.json from the user). This feature is only available on Yarn so when using NPM it'll be skipped.

  2. Parsing the packages.json This path works with both NPM and Yarn (used when user simply types yarn install), it'll look for any sibling reference that doesn't match the desired version or uses the ^ symbol on the sibling version.

This is a tricky code since it postinstall gets called before the package manager decides to update the packages.json .

Furthermore, this option will list all the required changes and also the required command in order to update the libraries (We could update the user's package.json but I think that's too evasive/extra effort by the script).

Ther's also a flag --update-sentry-capacitor to ignore the postinstall check since when updating a library using method 2, postinstall will only read the previous version prior the update, avoiding the user to be stuck on the update process).

Sample from what the user will see when installing the wrong sibling, where @sentry/vue and @sentry/angular were installed with the wrong version when installed.

NPM

npm ERR!       throw IncompatibilityError;
npm ERR!       ^
npm ERR! This version of Sentry Capacitor is incompatible with the following installed packages:
npm ERR! @sentry/angular version ^7.13.0
npm ERR! @sentry/vue version ^7.13.0
npm ERR! Please install the mentioned packages with exactly with version 7.15.0 and with the argument --update-sentry-capacitor
npm ERR! npm install --save-exact @sentry/[email protected] @sentry/[email protected]  --update-sentry-capacitor

Yarn

      throw IncompatibilityError;
      ^
This version of Sentry Capacitor is incompatible with the following installed packages:
@sentry/angular version 7.13.0
@sentry/vue version 7.13.0
Please install the mentioned packages with exactly with version 7.15.0 and with the argument --update-sentry-capacitor
yarn add --exact @sentry/[email protected] @sentry/[email protected]  --update-sentry-capacitor

lucas-zimerman avatar Oct 23 '22 15:10 lucas-zimerman

Hey @lucas-zimerman sorry for the late review.

Want to see if we can maybe pivot on this strategy a little - can we try doing something like we do here? getsentry/sentry-electron#584

This way we don't need a postinstall, we just rely on TypeScript errors.

That would be great, but here, instead of throwing an error on the SDK path, we only have duplicated errors from with @sentry/types

Error: node_modules/@sentry/angular/node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.

2     const __DEBUG_BUILD__: boolean;
            ~~~~~~~~~~~~~~~

  node_modules/@sentry/types/types/globals.d.ts:2:11
    2     const __DEBUG_BUILD__: boolean;
                ~~~~~~~~~~~~~~~
    '__DEBUG_BUILD__' was also declared here.


Error: node_modules/@sentry/types/types/globals.d.ts:2:11 - error TS2451: Cannot redeclare block-scoped variable '__DEBUG_BUILD__'.

2     const __DEBUG_BUILD__: boolean;
            ~~~~~~~~~~~~~~~

  node_modules/@sentry/angular/node_modules/@sentry/types/types/globals.d.ts:2:11
    2     const __DEBUG_BUILD__: boolean;
                ~~~~~~~~~~~~~~~
    '__DEBUG_BUILD__' was also declared here.



[ERROR] An error occurred while running subprocess ng.

        ng.cmd run app:build exited with exit code 1.

lucas-zimerman avatar Nov 06 '22 13:11 lucas-zimerman