Skip to content

Commit 31fa5d9

Browse files
committed
Add confirm step for import docs
1 parent 86ccc64 commit 31fa5d9

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

src/nuxt/nuxt-wizard.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import {
2727
createConfigFiles,
2828
addNuxtOverrides,
2929
askDeploymentPlatform,
30+
confirmReadImportDocs,
3031
} from './sdk-setup';
3132
import {
3233
createExampleComponent,
3334
createExamplePage,
3435
supportsExamplePage,
3536
} from './sdk-example';
3637
import { isNuxtV4 } from './utils';
37-
import { DeploymentPlatform } from './types';
3838

3939
export function runNuxtWizard(options: WizardOptions) {
4040
return withTelemetry(
@@ -152,33 +152,19 @@ export async function runNuxtWizardWithTelemetry(
152152

153153
await runPrettierIfInstalled();
154154

155+
await confirmReadImportDocs(deploymentPlatform);
156+
155157
clack.outro(
156-
buildOutroMessage(
157-
shouldCreateExamplePage,
158-
shouldCreateExampleButton,
159-
deploymentPlatform,
160-
),
158+
buildOutroMessage(shouldCreateExamplePage, shouldCreateExampleButton),
161159
);
162160
}
163161

164162
function buildOutroMessage(
165163
shouldCreateExamplePage: boolean,
166164
shouldCreateExampleButton: boolean,
167-
deploymentPlatform: DeploymentPlatform | symbol,
168165
): string {
169-
const canImportSentryServerConfigFile =
170-
deploymentPlatform !== 'vercel' && deploymentPlatform !== 'netlify';
171-
172166
let msg = chalk.green('\nSuccessfully installed the Sentry Nuxt SDK!');
173167

174-
if (canImportSentryServerConfigFile) {
175-
msg += `\n\nAfter building your Nuxt app, you need to ${chalk.cyan(
176-
'--import',
177-
)} the Sentry server config file when running your app.\n\nFor more info see: ${chalk.cyan(
178-
'https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cli-import/#initializing-sentry-with---import',
179-
)}`;
180-
}
181-
182168
if (shouldCreateExamplePage) {
183169
msg += `\n\nYou can validate your setup by visiting ${chalk.cyan(
184170
'"/sentry-example-page"',
@@ -190,7 +176,7 @@ function buildOutroMessage(
190176
)} component to a page and triggering it.`;
191177
}
192178

193-
msg += `\n\nCheck out the SDK documentation for further configuration: ${chalk.cyan(
179+
msg += `\n\nCheck out the SDK documentation for further configuration: ${chalk.underline(
194180
'https://docs.sentry.io/platforms/javascript/guides/nuxt/',
195181
)}`;
196182

src/nuxt/sdk-setup.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
featureSelectionPrompt,
2222
installPackage,
2323
isUsingTypeScript,
24+
opn,
2425
} from '../utils/clack-utils';
2526
import { traceStep } from '../telemetry';
2627
import { lt, SemVer } from 'semver';
@@ -88,7 +89,7 @@ export async function addSDKModule(
8889
`${deploymentPlatform
8990
.charAt(0)
9091
.toUpperCase()}${deploymentPlatform.slice(1)}`,
91-
)} does not support this yet.\n\nWe will inject the Sentry server-side config at the top of your Nuxt server entry file instead.\n\nThis comes with some restrictions, for more info see:\n\n${chalk.cyan(
92+
)} does not support this yet.\n\nWe will inject the Sentry server-side config at the top of your Nuxt server entry file instead.\n\nThis comes with some restrictions, for more info see:\n\n${chalk.underline(
9293
'https://docs.sentry.io/platforms/javascript/guides/nuxt/install/top-level-import/',
9394
)} `,
9495
);
@@ -265,11 +266,11 @@ export async function addNuxtOverrides(
265266
clack.log.warn(
266267
`To ensure Sentry can properly instrument your code it needs to add version overrides for some Nuxt dependencies${
267268
isPNPM ? ` and install ${chalk.cyan('import-in-the-middle')}.` : '.'
268-
}\n\nFor more info see: ${chalk.cyan(
269+
}\n\nFor more info see: ${chalk.underline(
269270
'https://github.com/getsentry/sentry-javascript/issues/14514',
270271
)}${
271272
isPNPM
272-
? `\n\nand ${chalk.cyan(
273+
? `\n\nand ${chalk.underline(
273274
'https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle',
274275
)}`
275276
: ''
@@ -309,3 +310,36 @@ export async function addNuxtOverrides(
309310
}
310311
}
311312
}
313+
314+
export async function confirmReadImportDocs(
315+
deploymentPlatform: DeploymentPlatform | symbol,
316+
) {
317+
const canImportSentryServerConfigFile =
318+
deploymentPlatform !== 'vercel' && deploymentPlatform !== 'netlify';
319+
320+
if (!canImportSentryServerConfigFile) {
321+
// Nothing to do, users have been set up with automatic top-level-import instead
322+
return;
323+
}
324+
325+
const docsUrl =
326+
'https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cli-import/#initializing-sentry-with---import';
327+
328+
clack.log.info(
329+
`After building your Nuxt app, you need to ${chalk.bold(
330+
'--import',
331+
)} the Sentry server config file when running your app.\n\nFor more info, see:\n\n${chalk.underline(
332+
docsUrl,
333+
)}`,
334+
);
335+
336+
const shouldOpenDocs = await abortIfCancelled(
337+
clack.confirm({ message: 'Do you want to open the docs?' }),
338+
);
339+
340+
if (shouldOpenDocs) {
341+
opn(docsUrl, { wait: false }).catch(() => {
342+
// opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
343+
});
344+
}
345+
}

src/utils/clack-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { debug } from './debug';
2121
import { fulfillsVersionRange } from './semver';
2222

23-
const opn = require('opn') as (
23+
export const opn = require('opn') as (
2424
url: string,
2525
options?: {
2626
wait?: boolean;

0 commit comments

Comments
 (0)