@sentry/wizard 3.34.3 → 3.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/e2e-tests/tests/nuxt-3.test.d.ts +1 -0
  3. package/dist/e2e-tests/tests/nuxt-3.test.js +231 -0
  4. package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -0
  5. package/dist/e2e-tests/tests/nuxt-4.test.d.ts +1 -0
  6. package/dist/e2e-tests/tests/nuxt-4.test.js +232 -0
  7. package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -0
  8. package/dist/e2e-tests/tests/remix.test.js +92 -27
  9. package/dist/e2e-tests/tests/remix.test.js.map +1 -1
  10. package/dist/e2e-tests/tests/sveltekit.test.js +102 -42
  11. package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
  12. package/dist/e2e-tests/utils/index.d.ts +18 -1
  13. package/dist/e2e-tests/utils/index.js +31 -2
  14. package/dist/e2e-tests/utils/index.js.map +1 -1
  15. package/dist/lib/Constants.d.ts +1 -0
  16. package/dist/lib/Constants.js +1 -0
  17. package/dist/lib/Constants.js.map +1 -1
  18. package/dist/package.json +3 -3
  19. package/dist/src/apple/templates.js +2 -2
  20. package/dist/src/apple/templates.js.map +1 -1
  21. package/dist/src/nextjs/nextjs-wizard.js +1 -0
  22. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  23. package/dist/src/nuxt/nuxt-wizard.d.ts +3 -0
  24. package/dist/src/nuxt/nuxt-wizard.js +220 -0
  25. package/dist/src/nuxt/nuxt-wizard.js.map +1 -0
  26. package/dist/src/nuxt/sdk-example.d.ts +8 -0
  27. package/dist/src/nuxt/sdk-example.js +179 -0
  28. package/dist/src/nuxt/sdk-example.js.map +1 -0
  29. package/dist/src/nuxt/sdk-setup.d.ts +8 -0
  30. package/dist/src/nuxt/sdk-setup.js +275 -0
  31. package/dist/src/nuxt/sdk-setup.js.map +1 -0
  32. package/dist/src/nuxt/templates.d.ts +22 -0
  33. package/dist/src/nuxt/templates.js +84 -0
  34. package/dist/src/nuxt/templates.js.map +1 -0
  35. package/dist/src/nuxt/utils.d.ts +1 -0
  36. package/dist/src/nuxt/utils.js +71 -0
  37. package/dist/src/nuxt/utils.js.map +1 -0
  38. package/dist/src/remix/remix-wizard.js +2 -1
  39. package/dist/src/remix/remix-wizard.js.map +1 -1
  40. package/dist/src/run.d.ts +1 -1
  41. package/dist/src/run.js +30 -23
  42. package/dist/src/run.js.map +1 -1
  43. package/dist/src/sourcemaps/tools/rollup.js +1 -1
  44. package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
  45. package/dist/src/sveltekit/sveltekit-wizard.js +2 -1
  46. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  47. package/dist/src/utils/clack-utils.d.ts +6 -2
  48. package/dist/src/utils/clack-utils.js +30 -10
  49. package/dist/src/utils/clack-utils.js.map +1 -1
  50. package/dist/test/nuxt/templates.test.d.ts +1 -0
  51. package/dist/test/nuxt/templates.test.js +70 -0
  52. package/dist/test/nuxt/templates.test.js.map +1 -0
  53. package/e2e-tests/README.md +59 -0
  54. package/e2e-tests/test-applications/nuxt-3-test-app/README.md +75 -0
  55. package/e2e-tests/test-applications/nuxt-3-test-app/nuxt.config.ts +5 -0
  56. package/e2e-tests/test-applications/nuxt-3-test-app/package.json +18 -0
  57. package/e2e-tests/test-applications/nuxt-3-test-app/public/favicon.ico +0 -0
  58. package/e2e-tests/test-applications/nuxt-3-test-app/public/robots.txt +1 -0
  59. package/e2e-tests/tests/nuxt-3.test.ts +169 -0
  60. package/e2e-tests/tests/nuxt-4.test.ts +168 -0
  61. package/e2e-tests/tests/remix.test.ts +163 -50
  62. package/e2e-tests/tests/sveltekit.test.ts +180 -79
  63. package/e2e-tests/utils/index.ts +31 -1
  64. package/lib/Constants.ts +1 -0
  65. package/package.json +3 -3
  66. package/src/apple/templates.ts +14 -2
  67. package/src/nextjs/nextjs-wizard.ts +1 -0
  68. package/src/nuxt/nuxt-wizard.ts +166 -0
  69. package/src/nuxt/sdk-example.ts +135 -0
  70. package/src/nuxt/sdk-setup.ts +209 -0
  71. package/src/nuxt/templates.ts +296 -0
  72. package/src/nuxt/utils.ts +32 -0
  73. package/src/remix/remix-wizard.ts +2 -1
  74. package/src/run.ts +7 -0
  75. package/src/sourcemaps/tools/rollup.ts +1 -1
  76. package/src/sveltekit/sveltekit-wizard.ts +2 -1
  77. package/src/utils/clack-utils.ts +32 -8
  78. package/test/nuxt/templates.test.ts +228 -0
@@ -0,0 +1,135 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
4
+ import clack from '@clack/prompts';
5
+ import {
6
+ getIndexRouteTemplate,
7
+ getSentryExampleApiTemplate,
8
+ getSentryExamplePageTemplate,
9
+ getSentryErrorButtonTemplate,
10
+ } from './templates';
11
+ import { abort, isUsingTypeScript } from '../utils/clack-utils';
12
+ import chalk from 'chalk';
13
+ import * as Sentry from '@sentry/node';
14
+
15
+ function getSrcDirectory(isNuxtV4: boolean) {
16
+ // In nuxt v4, the src directory is `app/` unless
17
+ // users already had a `pages` directory
18
+ return isNuxtV4 && !fs.existsSync(path.resolve('pages')) ? 'app' : '.';
19
+ }
20
+
21
+ export async function supportsExamplePage(isNuxtV4: boolean) {
22
+ // We currently only support creating an example page
23
+ // if users can reliably access it without having to
24
+ // add code changes themselves.
25
+ //
26
+ // If users have an `app.vue` layout without the
27
+ // needed component to render routes (<NuxtPage/>),
28
+ // we bail out of creating an example page altogether.
29
+ const src = getSrcDirectory(isNuxtV4);
30
+ const app = path.join(src, 'app.vue');
31
+
32
+ // If there's no `app.vue` layout, nuxt automatically renders
33
+ // the routes.
34
+ if (!fs.existsSync(path.resolve(app))) {
35
+ return true;
36
+ }
37
+
38
+ const content = await fs.promises.readFile(path.resolve(app), 'utf8');
39
+ return !!content.match(/<NuxtPage/g);
40
+ }
41
+
42
+ export async function createExamplePage(
43
+ isNuxtV4: boolean,
44
+ options: {
45
+ org: string;
46
+ project: string;
47
+ projectId: string;
48
+ url: string;
49
+ },
50
+ ) {
51
+ try {
52
+ const src = getSrcDirectory(isNuxtV4);
53
+ const pages = path.join(src, 'pages');
54
+
55
+ if (!fs.existsSync(path.resolve(pages))) {
56
+ fs.mkdirSync(path.resolve(pages), { recursive: true });
57
+
58
+ const indexPage = path.join(pages, 'index.vue');
59
+
60
+ await fs.promises.writeFile(
61
+ path.resolve(indexPage),
62
+ getIndexRouteTemplate(),
63
+ );
64
+
65
+ clack.log.success(`Created ${chalk.cyan(indexPage)}.`);
66
+ }
67
+
68
+ const examplePage = path.join(pages, 'sentry-example-page.vue');
69
+
70
+ if (fs.existsSync(path.resolve(examplePage))) {
71
+ clack.log.warn(
72
+ `It seems like a sentry example page already exists. Skipping creation of example page.`,
73
+ );
74
+ return;
75
+ }
76
+
77
+ await fs.promises.writeFile(
78
+ path.resolve(examplePage),
79
+ getSentryExamplePageTemplate(options),
80
+ );
81
+
82
+ clack.log.success(`Created ${chalk.cyan(examplePage)}.`);
83
+
84
+ const api = path.join('server', 'api');
85
+
86
+ if (!fs.existsSync(path.resolve(api))) {
87
+ fs.mkdirSync(path.resolve(api), { recursive: true });
88
+ }
89
+
90
+ const exampleApi = path.join(
91
+ api,
92
+ isUsingTypeScript() ? 'sentry-example-api.ts' : 'sentry-example-api.js',
93
+ );
94
+
95
+ await fs.promises.writeFile(
96
+ path.resolve(exampleApi),
97
+ getSentryExampleApiTemplate(),
98
+ );
99
+
100
+ clack.log.success(`Created ${chalk.cyan(exampleApi)}.`);
101
+ } catch (e: unknown) {
102
+ clack.log.error('Error while creating an example page to test Sentry:');
103
+ clack.log.info(
104
+ chalk.dim(
105
+ typeof e === 'object' && e != null && 'toString' in e
106
+ ? e.toString()
107
+ : typeof e === 'string'
108
+ ? e
109
+ : 'Unknown error',
110
+ ),
111
+ );
112
+ Sentry.captureException(
113
+ 'Error while creating an example Nuxt page to test Sentry',
114
+ );
115
+ await abort('Exiting Wizard');
116
+ }
117
+ }
118
+
119
+ export async function createExampleComponent(isNuxtV4: boolean) {
120
+ const src = getSrcDirectory(isNuxtV4);
121
+ const components = path.join(src, 'components');
122
+
123
+ if (!fs.existsSync(path.resolve(components))) {
124
+ fs.mkdirSync(path.resolve(components), { recursive: true });
125
+ }
126
+
127
+ const exampleComponent = path.join(components, 'SentryErrorButton.vue');
128
+
129
+ await fs.promises.writeFile(
130
+ path.resolve(exampleComponent),
131
+ getSentryErrorButtonTemplate(),
132
+ );
133
+
134
+ clack.log.success(`Created ${chalk.cyan(exampleComponent)}.`);
135
+ }
@@ -0,0 +1,209 @@
1
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
2
+ import clack from '@clack/prompts';
3
+ import * as Sentry from '@sentry/node';
4
+ import chalk from 'chalk';
5
+ import fs from 'fs';
6
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
7
+ import { loadFile, generateCode, MagicastError } from 'magicast';
8
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
9
+ import { addNuxtModule } from 'magicast/helpers';
10
+ import path from 'path';
11
+ import {
12
+ getConfigBody,
13
+ getDefaultNuxtConfig,
14
+ getNuxtModuleFallbackTemplate,
15
+ getSentryConfigContents,
16
+ } from './templates';
17
+ import {
18
+ abort,
19
+ abortIfCancelled,
20
+ featureSelectionPrompt,
21
+ isUsingTypeScript,
22
+ } from '../utils/clack-utils';
23
+ import { traceStep } from '../telemetry';
24
+
25
+ const possibleNuxtConfig = [
26
+ 'nuxt.config.js',
27
+ 'nuxt.config.mjs',
28
+ 'nuxt.config.cjs',
29
+ 'nuxt.config.ts',
30
+ 'nuxt.config.mts',
31
+ 'nuxt.config.cts',
32
+ ];
33
+
34
+ export async function getNuxtConfig(): Promise<string> {
35
+ let configFile = possibleNuxtConfig.find((fileName) =>
36
+ fs.existsSync(path.join(process.cwd(), fileName)),
37
+ );
38
+
39
+ if (!configFile) {
40
+ clack.log.info('No Nuxt config file found, creating a new one.');
41
+ Sentry.setTag('nuxt-config-strategy', 'create');
42
+ // nuxt recommends its config to be .ts by default
43
+ configFile = 'nuxt.config.ts';
44
+
45
+ await fs.promises.writeFile(
46
+ path.join(process.cwd(), configFile),
47
+ getDefaultNuxtConfig(),
48
+ { encoding: 'utf-8', flag: 'w' },
49
+ );
50
+
51
+ clack.log.success(`Created ${chalk.cyan('nuxt.config.ts')}.`);
52
+ }
53
+
54
+ return path.join(process.cwd(), configFile);
55
+ }
56
+
57
+ export async function addSDKModule(
58
+ config: string,
59
+ options: { org: string; project: string; url: string; selfHosted: boolean },
60
+ ): Promise<void> {
61
+ try {
62
+ const mod = await loadFile(config);
63
+
64
+ addNuxtModule(mod, '@sentry/nuxt/module', 'sentry', {
65
+ sourceMapsUploadOptions: {
66
+ org: options.org,
67
+ project: options.project,
68
+ ...(options.selfHosted && { url: options.url }),
69
+ },
70
+ });
71
+ addNuxtModule(mod, '@sentry/nuxt/module', 'sourcemap', {
72
+ client: 'hidden',
73
+ });
74
+
75
+ const { code } = generateCode(mod);
76
+
77
+ await fs.promises.writeFile(config, code, { encoding: 'utf-8', flag: 'w' });
78
+
79
+ clack.log.success(
80
+ `Added Sentry Nuxt Module to ${chalk.cyan(path.basename(config))}.`,
81
+ );
82
+ } catch (e: unknown) {
83
+ // Cases where users spread options are not covered by magicast,
84
+ // so we fall back to showing how to configure the nuxt config
85
+ // manually.
86
+ if (e instanceof MagicastError) {
87
+ clack.log.warn(
88
+ `Automatic configuration of ${chalk.cyan(
89
+ path.basename(config),
90
+ )} failed, please add the following settings:`,
91
+ );
92
+ // eslint-disable-next-line no-console
93
+ console.log(`\n\n${getNuxtModuleFallbackTemplate(options)}\n\n`);
94
+ } else {
95
+ clack.log.error(
96
+ 'Error while adding the Sentry Nuxt Module to the Nuxt config.',
97
+ );
98
+ clack.log.info(
99
+ chalk.dim(
100
+ typeof e === 'object' && e != null && 'toString' in e
101
+ ? e.toString()
102
+ : typeof e === 'string'
103
+ ? e
104
+ : 'Unknown error',
105
+ ),
106
+ );
107
+ Sentry.captureException('Error while setting up the Nuxt SDK');
108
+ await abort('Exiting Wizard');
109
+ }
110
+ }
111
+ }
112
+
113
+ export async function createConfigFiles(dsn: string) {
114
+ const selectedFeatures = await featureSelectionPrompt([
115
+ {
116
+ id: 'performance',
117
+ prompt: `Do you want to enable ${chalk.bold(
118
+ 'Tracing',
119
+ )} to track the performance of your application?`,
120
+ enabledHint: 'recommended',
121
+ },
122
+ {
123
+ id: 'replay',
124
+ prompt: `Do you want to enable ${chalk.bold(
125
+ 'Sentry Session Replay',
126
+ )} to get a video-like reproduction of errors during a user session?`,
127
+ enabledHint: 'recommended, but increases bundle size',
128
+ },
129
+ ] as const);
130
+
131
+ const typeScriptDetected = isUsingTypeScript();
132
+
133
+ const configVariants = ['server', 'client'] as const;
134
+
135
+ for (const configVariant of configVariants) {
136
+ await traceStep(`create-sentry-${configVariant}-config`, async () => {
137
+ const jsConfig = `sentry.${configVariant}.config.js`;
138
+ const tsConfig = `sentry.${configVariant}.config.ts`;
139
+
140
+ const jsConfigExists = fs.existsSync(path.join(process.cwd(), jsConfig));
141
+ const tsConfigExists = fs.existsSync(path.join(process.cwd(), tsConfig));
142
+
143
+ let shouldWriteFile = true;
144
+
145
+ if (jsConfigExists || tsConfigExists) {
146
+ const existingConfigs = [];
147
+
148
+ if (jsConfigExists) {
149
+ existingConfigs.push(jsConfig);
150
+ }
151
+
152
+ if (tsConfigExists) {
153
+ existingConfigs.push(tsConfig);
154
+ }
155
+
156
+ const overwriteExistingConfigs = await abortIfCancelled(
157
+ clack.confirm({
158
+ message: `Found existing Sentry ${configVariant} config (${existingConfigs.join(
159
+ ', ',
160
+ )}). Overwrite ${existingConfigs.length > 1 ? 'them' : 'it'}?`,
161
+ }),
162
+ );
163
+ Sentry.setTag(
164
+ `overwrite-${configVariant}-config`,
165
+ overwriteExistingConfigs,
166
+ );
167
+
168
+ shouldWriteFile = overwriteExistingConfigs;
169
+
170
+ if (overwriteExistingConfigs) {
171
+ if (jsConfigExists) {
172
+ fs.unlinkSync(path.join(process.cwd(), jsConfig));
173
+ clack.log.warn(`Removed existing ${chalk.cyan(jsConfig)}.`);
174
+ }
175
+ if (tsConfigExists) {
176
+ fs.unlinkSync(path.join(process.cwd(), tsConfig));
177
+ clack.log.warn(`Removed existing ${chalk.cyan(tsConfig)}.`);
178
+ }
179
+ }
180
+ }
181
+
182
+ if (shouldWriteFile) {
183
+ await fs.promises.writeFile(
184
+ path.join(process.cwd(), typeScriptDetected ? tsConfig : jsConfig),
185
+ getSentryConfigContents(dsn, configVariant, selectedFeatures),
186
+ { encoding: 'utf8', flag: 'w' },
187
+ );
188
+ clack.log.success(
189
+ `Created new ${chalk.cyan(
190
+ typeScriptDetected ? tsConfig : jsConfig,
191
+ )}.`,
192
+ );
193
+ Sentry.setTag(`created-${configVariant}-config`, true);
194
+ } else {
195
+ clack.log.info(
196
+ `Okay, here are the changes your ${chalk.cyan(
197
+ typeScriptDetected ? tsConfig : jsConfig,
198
+ )} should contain:`,
199
+ );
200
+ // eslint-disable-next-line no-console
201
+ console.log(
202
+ '\n\n ' +
203
+ getConfigBody(dsn, configVariant, selectedFeatures) +
204
+ '\n\n',
205
+ );
206
+ }
207
+ });
208
+ }
209
+ }
@@ -0,0 +1,296 @@
1
+ import { getIssueStreamUrl } from '../utils/url';
2
+
3
+ type SelectedSentryFeatures = {
4
+ performance: boolean;
5
+ replay: boolean;
6
+ };
7
+
8
+ export function getDefaultNuxtConfig(): string {
9
+ return `// https://nuxt.com/docs/api/configuration/nuxt-config
10
+ export default defineNuxtConfig({
11
+ compatibilityDate: '2024-04-03',
12
+ devtools: { enabled: true }
13
+ })
14
+ `;
15
+ }
16
+
17
+ export function getNuxtModuleFallbackTemplate(options: {
18
+ org: string;
19
+ project: string;
20
+ url: string;
21
+ selfHosted: boolean;
22
+ }): string {
23
+ return ` modules: ["@sentry/nuxt/module"],
24
+ sentry: {
25
+ sourceMapsUploadOptions: {
26
+ org: "${options.org}",
27
+ project: "${options.project}",${
28
+ options.selfHosted ? `\n url: "${options.url}",` : ''
29
+ }
30
+ },
31
+ },
32
+ sourcemap: { client: "hidden" },`;
33
+ }
34
+
35
+ export function getSentryConfigContents(
36
+ dsn: string,
37
+ config: 'client' | 'server',
38
+ selectedFeatures: SelectedSentryFeatures,
39
+ ): string {
40
+ if (config === 'client') {
41
+ return getSentryClientConfigContents(dsn, selectedFeatures);
42
+ }
43
+
44
+ return getSentryServerConfigContents(dsn, selectedFeatures);
45
+ }
46
+
47
+ const featuresConfigMap: Record<keyof SelectedSentryFeatures, string> = {
48
+ performance: [
49
+ ' // We recommend adjusting this value in production, or using tracesSampler',
50
+ ' // for finer control',
51
+ ' tracesSampleRate: 1.0,',
52
+ ].join('\n'),
53
+ replay: [
54
+ ' // This sets the sample rate to be 10%. You may want this to be 100% while',
55
+ ' // in development and sample at a lower rate in production',
56
+ ' replaysSessionSampleRate: 0.1,',
57
+ ' ',
58
+ ' // If the entire session is not sampled, use the below sample rate to sample',
59
+ ' // sessions when an error occurs.',
60
+ ' replaysOnErrorSampleRate: 1.0,',
61
+ ' ',
62
+ " // If you don't want to use Session Replay, just remove the line below:",
63
+ ' integrations: [Sentry.replayIntegration()],',
64
+ ].join('\n'),
65
+ };
66
+
67
+ const featuresMap: Record<
68
+ 'client' | 'server',
69
+ Array<keyof SelectedSentryFeatures>
70
+ > = {
71
+ client: ['performance', 'replay'],
72
+ server: ['performance'],
73
+ };
74
+
75
+ export function getConfigBody(
76
+ dsn: string,
77
+ variant: 'client' | 'server',
78
+ selectedFeatures: SelectedSentryFeatures,
79
+ ) {
80
+ return [
81
+ `dsn: "${dsn}",`,
82
+ Object.entries(selectedFeatures)
83
+ .map(([feature, activated]: [keyof SelectedSentryFeatures, boolean]) => {
84
+ return featuresMap[variant].includes(feature) && activated
85
+ ? featuresConfigMap[feature]
86
+ : null;
87
+ })
88
+ .filter(Boolean)
89
+ .join('\n\n'),
90
+ ]
91
+ .filter(Boolean)
92
+ .join('\n\n');
93
+ }
94
+
95
+ function getSentryClientConfigContents(
96
+ dsn: string,
97
+ selectedFeatures: SelectedSentryFeatures,
98
+ ): string {
99
+ return `import * as Sentry from "@sentry/nuxt";
100
+
101
+ Sentry.init({
102
+ // If set up, you can use your runtime config here
103
+ // dsn: useRuntimeConfig().public.sentry.dsn,
104
+ ${getConfigBody(dsn, 'client', selectedFeatures)}
105
+
106
+ // Setting this option to true will print useful information to the console while you're setting up Sentry.
107
+ debug: false,
108
+ });
109
+ `;
110
+ }
111
+
112
+ function getSentryServerConfigContents(
113
+ dsn: string,
114
+ selectedFeatures: SelectedSentryFeatures,
115
+ ): string {
116
+ return `import * as Sentry from "@sentry/nuxt";
117
+
118
+ Sentry.init({
119
+ ${getConfigBody(dsn, 'server', selectedFeatures)}
120
+
121
+ // Setting this option to true will print useful information to the console while you're setting up Sentry.
122
+ debug: false,
123
+ });
124
+ `;
125
+ }
126
+
127
+ export function getIndexRouteTemplate(): string {
128
+ return `<!--
129
+ This is just to verify the sentry-example-page.
130
+ Feel free to delete this file.
131
+ -->
132
+
133
+ <template></template>`;
134
+ }
135
+
136
+ export function getSentryExamplePageTemplate(options: {
137
+ url: string;
138
+ org: string;
139
+ projectId: string;
140
+ }): string {
141
+ const { url, org, projectId } = options;
142
+ const issuesPageLink = getIssueStreamUrl({ url, orgSlug: org, projectId });
143
+
144
+ return `<!--
145
+ This is just a very simple page with a button to throw an example error.
146
+ Feel free to delete this file.
147
+ -->
148
+
149
+ <script setup>
150
+ import * as Sentry from '@sentry/nuxt';
151
+ import { useFetch} from '#imports'
152
+
153
+ function getSentryData() {
154
+ Sentry.startSpan(
155
+ {
156
+ name: 'Example Frontend Span',
157
+ op: 'test'
158
+ },
159
+ async () => {
160
+ const { error } = await useFetch('/api/sentry-example-api');
161
+ if (error.value) {
162
+ throw new Error('Sentry Example Frontend Error');
163
+ }
164
+ }
165
+ )
166
+ }
167
+ </script>
168
+
169
+ <template>
170
+ <title>Sentry Onboarding</title>
171
+ <div>
172
+ <main>
173
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 44">
174
+ <path
175
+ fill="currentColor"
176
+ d="M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z"
177
+ />
178
+ </svg>
179
+ <p>
180
+ Get Started with this <strong>simple Example:</strong>
181
+ </p>
182
+
183
+ <p>1. Send us a sample error:</p>
184
+ <button type="button" @click="getSentryData"> Throw error! </button>
185
+
186
+ <p>
187
+ 2. Look for the error on the
188
+ <a href="${issuesPageLink}">Issues Page</a>.
189
+ </p>
190
+ <p style="margin-top: 24px;">
191
+ For more information, take a look at the
192
+ <a href="https://docs.sentry.io/platforms/javascript/guides/nuxt/">
193
+ Sentry Nuxt Documentation
194
+ </a>
195
+ </p>
196
+ </main>
197
+ </div>
198
+ </template>
199
+
200
+ <style scoped>
201
+ main {
202
+ display: flex;
203
+ flex-direction: column;
204
+ justify-content: center;
205
+ align-items: center;
206
+ }
207
+
208
+ svg {
209
+ font-size: 4rem;
210
+ margin: 14px 0;
211
+ height: 1em;
212
+ }
213
+
214
+ button {
215
+ padding: 12px;
216
+ cursor: pointer;
217
+ background-color: rgb(54, 45, 89);
218
+ border-radius: 4px;
219
+ border: none;
220
+ color: white;
221
+ font-size: 1em;
222
+ margin: 1em;
223
+ transition: all 0.25s ease-in-out;
224
+ }
225
+ button:hover {
226
+ background-color: #8c5393;
227
+ box-shadow: 4px;
228
+ box-shadow: 0px 0px 15px 2px rgba(140, 83, 147, 0.5);
229
+ }
230
+ button:active {
231
+ background-color: #c73852;
232
+ }
233
+ </style>
234
+ `;
235
+ }
236
+
237
+ export function getSentryExampleApiTemplate() {
238
+ return `// This is just a very simple API route that throws an example error.
239
+ // Feel free to delete this file.
240
+ import { defineEventHandler } from '#imports';
241
+
242
+ export default defineEventHandler(event => {
243
+ throw new Error("Sentry Example API Route Error");
244
+ });
245
+ `;
246
+ }
247
+
248
+ export function getSentryErrorButtonTemplate() {
249
+ return `<!--
250
+ This is just a very simple component that throws an example error.
251
+ Feel free to delete this file.
252
+ -->
253
+
254
+ <script setup>
255
+ import * as Sentry from '@sentry/nuxt';
256
+
257
+ const throwError = () => {
258
+ Sentry.startSpan(
259
+ {
260
+ name: 'Example Frontend Span',
261
+ op: 'test'
262
+ },
263
+ () => {
264
+ throw new Error('Sentry Example Error');
265
+ }
266
+ )
267
+ };
268
+ </script>
269
+
270
+ <template>
271
+ <button id="errorBtn" @click="throwError"> Throw Error! </button>
272
+ </template>
273
+
274
+ <style scoped>
275
+ button {
276
+ padding: 12px;
277
+ cursor: pointer;
278
+ background-color: rgb(54, 45, 89);
279
+ border-radius: 4px;
280
+ border: none;
281
+ color: white;
282
+ font-size: 1em;
283
+ margin: 1em;
284
+ transition: all 0.25s ease-in-out;
285
+ }
286
+ button:hover {
287
+ background-color: #8c5393;
288
+ box-shadow: 4px;
289
+ box-shadow: 0px 0px 15px 2px rgba(140, 83, 147, 0.5);
290
+ }
291
+ button:active {
292
+ background-color: #c73852;
293
+ }
294
+ </style>
295
+ `;
296
+ }
@@ -0,0 +1,32 @@
1
+ import { gte, minVersion } from 'semver';
2
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
3
+ import { loadFile } from 'magicast';
4
+
5
+ export async function isNuxtV4(
6
+ nuxtConfig: string,
7
+ packageVersion: string | undefined,
8
+ ) {
9
+ if (!packageVersion) {
10
+ return false;
11
+ }
12
+
13
+ const minVer = minVersion(packageVersion);
14
+ if (minVer && gte(minVer, '4.0.0')) {
15
+ return true;
16
+ }
17
+
18
+ // At the time of writing, nuxt 4 is not on its own
19
+ // major yet. We must read the `compatibilityVersion`
20
+ // from the nuxt config.
21
+ const mod = await loadFile(nuxtConfig);
22
+ const config =
23
+ mod.exports.default.$type === 'function-call'
24
+ ? mod.exports.default.$args[0]
25
+ : mod.exports.default;
26
+
27
+ if (config && config.future && config.future.compatibilityVersion === 4) {
28
+ return true;
29
+ }
30
+
31
+ return false;
32
+ }
@@ -70,7 +70,8 @@ async function runRemixWizardWithTelemetry(
70
70
  await getOrAskForProjectData(options, 'javascript-remix');
71
71
 
72
72
  await installPackage({
73
- packageName: '@sentry/remix',
73
+ packageName: '@sentry/remix@^8',
74
+ packageNameDisplayLabel: '@sentry/remix',
74
75
  alreadyInstalled: hasPackageInstalled('@sentry/remix', packageJson),
75
76
  });
76
77