Skip to content

Commit a81fe51

Browse files
authored
feat(nuxt): Add import-in-the-middle install step when using pnpm (#727)
* feat(nuxt): Add import-in-the-middle install step when using pnpm * Add changelog * Update pnpm docs link * Update pnpm comment
1 parent 1a3be9f commit a81fe51

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- feat(nuxt): Add `import-in-the-middle` install step when using pnpm ([#727](https://github.com/getsentry/sentry-wizard/pull/727))
56
- fix(nuxt): Remove unused parameter in sentry-example-api template ([#734](https://github.com/getsentry/sentry-wizard/pull/734))
67

78
## 3.36.0

src/nuxt/nuxt-wizard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function runNuxtWizardWithTelemetry(
9393

9494
const packageManager = await getPackageManager();
9595

96-
await addNuxtOverrides(packageManager, minVer);
96+
await addNuxtOverrides(packageJson, packageManager, minVer);
9797

9898
const sdkAlreadyInstalled = hasPackageInstalled('@sentry/nuxt', packageJson);
9999
Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled);

src/nuxt/sdk-setup.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ import {
1818
abort,
1919
abortIfCancelled,
2020
askShouldAddPackageOverride,
21+
askShouldInstallPackage,
2122
featureSelectionPrompt,
23+
installPackage,
2224
isUsingTypeScript,
2325
} from '../utils/clack-utils';
2426
import { traceStep } from '../telemetry';
2527
import { lt, SemVer } from 'semver';
26-
import { PackageManager } from '../utils/package-manager';
28+
import { PackageManager, PNPM } from '../utils/package-manager';
29+
import { hasPackageInstalled, PackageDotJson } from '../utils/package-json';
2730

2831
const possibleNuxtConfig = [
2932
'nuxt.config.js',
@@ -212,9 +215,12 @@ export async function createConfigFiles(dsn: string) {
212215
}
213216

214217
export async function addNuxtOverrides(
218+
packageJson: PackageDotJson,
215219
packageManager: PackageManager,
216220
nuxtMinVer: SemVer | null,
217221
) {
222+
const isPNPM = PNPM.detect();
223+
218224
const overrides = [
219225
{
220226
pkgName: 'nitropack',
@@ -230,9 +236,17 @@ export async function addNuxtOverrides(
230236
];
231237

232238
clack.log.warn(
233-
`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(
239+
`To ensure Sentry can properly instrument your code it needs to add version overrides for some Nuxt dependencies${
240+
isPNPM ? ` and install ${chalk.cyan('import-in-the-middle')}.` : '.'
241+
}\n\nFor more info see: ${chalk.cyan(
234242
'https://github.com/getsentry/sentry-javascript/issues/14514',
235-
)}`,
243+
)}${
244+
isPNPM
245+
? `\n\nand ${chalk.cyan(
246+
'https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle',
247+
)}`
248+
: ''
249+
}`,
236250
);
237251

238252
for (const { pkgName, pkgVersion } of overrides) {
@@ -245,4 +259,26 @@ export async function addNuxtOverrides(
245259
await packageManager.addOverride(pkgName, pkgVersion);
246260
}
247261
}
262+
263+
if (PNPM.detect()) {
264+
// For pnpm, we want to install iitm
265+
// See: https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle
266+
const iitmAlreadyInstalled = hasPackageInstalled(
267+
'import-in-the-middle',
268+
packageJson,
269+
);
270+
Sentry.setTag('iitm-already-installed', iitmAlreadyInstalled);
271+
272+
const shouldInstallIitm = await askShouldInstallPackage(
273+
'import-in-the-middle',
274+
);
275+
276+
if (shouldInstallIitm) {
277+
await installPackage({
278+
packageName: 'import-in-the-middle',
279+
alreadyInstalled: iitmAlreadyInstalled,
280+
packageManager,
281+
});
282+
}
283+
}
248284
}

src/utils/clack-utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,18 @@ export async function featureSelectionPrompt<F extends ReadonlyArray<Feature>>(
14921492
});
14931493
}
14941494

1495+
export async function askShouldInstallPackage(
1496+
pkgName: string,
1497+
): Promise<boolean> {
1498+
return traceStep(`ask-install-package`, () =>
1499+
abortIfCancelled(
1500+
clack.confirm({
1501+
message: `Do you want to install ${chalk.cyan(pkgName)}?`,
1502+
}),
1503+
),
1504+
);
1505+
}
1506+
14951507
export async function askShouldAddPackageOverride(
14961508
pkgName: string,
14971509
pkgVersion: string,

0 commit comments

Comments
 (0)