Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prompt to automatically update dependencies #796

Open
lucas-zimerman opened this issue Nov 26, 2024 · 2 comments
Open

feat: prompt to automatically update dependencies #796

lucas-zimerman opened this issue Nov 26, 2024 · 2 comments

Comments

@lucas-zimerman
Copy link
Collaborator

lucas-zimerman commented Nov 26, 2024

TIP: Siblings are other Sentry SDKs other than @sentry/capacitor, like @sentry/browser, @sentry/angular, @sentry/react,...

Since it is possible to invoke yarn from a node script, we can actually offer to the users to automatically update their siblings to the correct version.
If we implement the snippet below, we will be able to ask users if they want to patch their package.json and fix the correct sibling version of the Sibling SDK automatically.

Impact

This is not ideal when running CI since it doesn't have any input, we would need to add some safeguards to not run this code on CI.

On the other hand, it will be way easier for users to update their dependencies and issues with wrong versions should be a thing in the past.

CONSOLE:
⚠️   This version of Sentry Capacitor is incompatible with the following installed packages:  
@sentry/angular version 8.0.0
Please install the mentioned packages exactly with version 8.37.1 and with the argument --update-sentry-capacitor.
Your project will build with the wrong package but you may face Runtime errors.
You can use the below command to fix your package.json:
  yarn add --exact @sentry/[email protected]  --update-sentry-capacitor

Sample snippet on postinstall

    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    rl.question('Would you like to apply the patch above? ', (answer) => {
      if (answer === 'y') {

        const yarnAdd = spawn('yarn', ["add", "--exact", "@sentry/[email protected]", "--update-sentry-capacitor"],
          {
            cwd: rootPath,
            stdio: 'inherit'
          });
        yarnAdd.on('close', (code) => {
          if (code === 0) {
            console.log(`Successfully updated`);
            exit(0);
          } else {
            console.error(`Failed to update. Exit code: ${code}`);
            exit(1);

          }
        });
      }
      else {
        exit(0);
      }
      rl.close();
    });

Sample after accepting:

c:/ yarn install
yarn install v1.22.22
[1/4] Resolving packages...
success Already up-to-date.
$ node node_modules/@sentry/capacitor/scripts/check-siblings.js
⚠️   This version of Sentry Capacitor is incompatible with the following installed packages:  
@sentry/angular version 8.0.0
Please install the mentioned packages exactly with version 8.37.1 and with the argument --update-sentry-capacitor.
Your project will build with the wrong package but you may face Runtime errors.
You can use the below command to fix your package.json:
  yarn add --exact @sentry/[email protected]  --update-sentry-capacitor
Would you like to apply the patch above? y
yarn add v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ @sentry/[email protected]
info All dependencies
└─ @sentry/[email protected]
Done in 0.78s.
Successfully updated
Done in 6.66s.
@lucas-zimerman lucas-zimerman changed the title feat: feat: prompt to automatically update dependencies Nov 26, 2024
@lucas-zimerman
Copy link
Collaborator Author

What do you think @kahest @krystofwoldrich ?

@kahest
Copy link
Member

kahest commented Nov 27, 2024

seems like a good improvement to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Discussion
Development

No branches or pull requests

2 participants