From 210ab08b45243a62c099c24e6aadfea745cbef5f Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 2 Dec 2024 09:56:43 +0100 Subject: [PATCH 1/4] feat(nuxt): Add import-in-the-middle install step when using pnpm --- src/nuxt/nuxt-wizard.ts | 2 +- src/nuxt/sdk-setup.ts | 42 +++++++++++++++++++++++++++++++++++++--- src/utils/clack-utils.ts | 12 ++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/nuxt/nuxt-wizard.ts b/src/nuxt/nuxt-wizard.ts index 8823535d5..e81b2a756 100644 --- a/src/nuxt/nuxt-wizard.ts +++ b/src/nuxt/nuxt-wizard.ts @@ -93,7 +93,7 @@ export async function runNuxtWizardWithTelemetry( const packageManager = await getPackageManager(); - await addNuxtOverrides(packageManager, minVer); + await addNuxtOverrides(packageJson, packageManager, minVer); const sdkAlreadyInstalled = hasPackageInstalled('@sentry/nuxt', packageJson); Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled); diff --git a/src/nuxt/sdk-setup.ts b/src/nuxt/sdk-setup.ts index c8df09d9b..c878311da 100644 --- a/src/nuxt/sdk-setup.ts +++ b/src/nuxt/sdk-setup.ts @@ -18,12 +18,15 @@ import { abort, abortIfCancelled, askShouldAddPackageOverride, + askShouldInstallPackage, featureSelectionPrompt, + installPackage, isUsingTypeScript, } from '../utils/clack-utils'; import { traceStep } from '../telemetry'; import { lt, SemVer } from 'semver'; -import { PackageManager } from '../utils/package-manager'; +import { PackageManager, PNPM } from '../utils/package-manager'; +import { hasPackageInstalled, PackageDotJson } from '../utils/package-json'; const possibleNuxtConfig = [ 'nuxt.config.js', @@ -212,9 +215,12 @@ export async function createConfigFiles(dsn: string) { } export async function addNuxtOverrides( + packageJson: PackageDotJson, packageManager: PackageManager, nuxtMinVer: SemVer | null, ) { + const isPNPM = PNPM.detect(); + const overrides = [ { pkgName: 'nitropack', @@ -230,9 +236,17 @@ export async function addNuxtOverrides( ]; clack.log.warn( - `To ensure Sentry can properly instrument your code it needs to add version overrides for some Nuxt dependencies.\n\nFor more info see: ${chalk.cyan( + `To ensure Sentry can properly instrument your code it needs to add version overrides for some Nuxt dependencies${ + isPNPM ? ` and install ${chalk.cyan('import-in-the-middle')}.` : '.' + }\n\nFor more info see: ${chalk.cyan( 'https://github.com/getsentry/sentry-javascript/issues/14514', - )}`, + )}${ + isPNPM + ? `\n\nand ${chalk.cyan( + 'https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-resolving-import-in-the-middle-external-package-errors', + )}` + : '' + }`, ); for (const { pkgName, pkgVersion } of overrides) { @@ -245,4 +259,26 @@ export async function addNuxtOverrides( await packageManager.addOverride(pkgName, pkgVersion); } } + + if (PNPM.detect()) { + // For pnpm, we probably want to install iitm + // See: https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-resolving-import-in-the-middle-external-package-errors + const iitmAlreadyInstalled = hasPackageInstalled( + 'import-in-the-middle', + packageJson, + ); + Sentry.setTag('iitm-already-installed', iitmAlreadyInstalled); + + const shouldInstallIitm = await askShouldInstallPackage( + 'import-in-the-middle', + ); + + if (shouldInstallIitm) { + await installPackage({ + packageName: 'import-in-the-middle', + alreadyInstalled: iitmAlreadyInstalled, + packageManager, + }); + } + } } diff --git a/src/utils/clack-utils.ts b/src/utils/clack-utils.ts index 94b5cf5b8..b31fcae3f 100644 --- a/src/utils/clack-utils.ts +++ b/src/utils/clack-utils.ts @@ -1492,6 +1492,18 @@ export async function featureSelectionPrompt>( }); } +export async function askShouldInstallPackage( + pkgName: string, +): Promise { + return traceStep(`ask-install-package`, () => + abortIfCancelled( + clack.confirm({ + message: `Do you want to install ${chalk.cyan(pkgName)}?`, + }), + ), + ); +} + export async function askShouldAddPackageOverride( pkgName: string, pkgVersion: string, From 4adf74cf671842b715394a6eaba4a955426962b3 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 6 Dec 2024 10:11:35 +0100 Subject: [PATCH 2/4] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd4dc5ed7..47f30f8ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- feat(nuxt): Add `import-in-the-middle` install step when using pnpm ([#727](https://github.com/getsentry/sentry-wizard/pull/727)) - fix(nuxt): Remove unused parameter in sentry-example-api template ([#734](https://github.com/getsentry/sentry-wizard/pull/734)) ## 3.36.0 From 9917f2f0fe49713dc86b72187a21492fe86ca2c2 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 6 Dec 2024 10:10:21 +0100 Subject: [PATCH 3/4] Update pnpm docs link --- src/nuxt/sdk-setup.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nuxt/sdk-setup.ts b/src/nuxt/sdk-setup.ts index c878311da..5a67356b0 100644 --- a/src/nuxt/sdk-setup.ts +++ b/src/nuxt/sdk-setup.ts @@ -243,7 +243,7 @@ export async function addNuxtOverrides( )}${ isPNPM ? `\n\nand ${chalk.cyan( - 'https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-resolving-import-in-the-middle-external-package-errors', + 'https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle', )}` : '' }`, @@ -262,7 +262,7 @@ export async function addNuxtOverrides( if (PNPM.detect()) { // For pnpm, we probably want to install iitm - // See: https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-resolving-import-in-the-middle-external-package-errors + // See: https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle const iitmAlreadyInstalled = hasPackageInstalled( 'import-in-the-middle', packageJson, From 5db6ce288bfa30a7c7c4bcd1baf2a1f45eca863f Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 6 Dec 2024 10:54:11 +0100 Subject: [PATCH 4/4] Update pnpm comment --- src/nuxt/sdk-setup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nuxt/sdk-setup.ts b/src/nuxt/sdk-setup.ts index 5a67356b0..6e2a2b0a8 100644 --- a/src/nuxt/sdk-setup.ts +++ b/src/nuxt/sdk-setup.ts @@ -261,7 +261,7 @@ export async function addNuxtOverrides( } if (PNPM.detect()) { - // For pnpm, we probably want to install iitm + // For pnpm, we want to install iitm // See: https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle const iitmAlreadyInstalled = hasPackageInstalled( 'import-in-the-middle',