@sentry/wizard 3.34.4 → 3.36.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.
- package/CHANGELOG.md +18 -1
- package/dist/e2e-tests/tests/nuxt-3.test.d.ts +1 -0
- package/dist/e2e-tests/tests/nuxt-3.test.js +257 -0
- package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -0
- package/dist/e2e-tests/tests/nuxt-4.test.d.ts +1 -0
- package/dist/e2e-tests/tests/nuxt-4.test.js +258 -0
- package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -0
- package/dist/e2e-tests/tests/remix.test.js +92 -27
- package/dist/e2e-tests/tests/remix.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit.test.js +102 -42
- package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
- package/dist/e2e-tests/utils/index.d.ts +18 -1
- package/dist/e2e-tests/utils/index.js +31 -2
- package/dist/e2e-tests/utils/index.js.map +1 -1
- package/dist/lib/Constants.d.ts +1 -0
- package/dist/lib/Constants.js +1 -0
- package/dist/lib/Constants.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/android/templates.js +1 -1
- package/dist/src/android/templates.js.map +1 -1
- package/dist/src/apple/templates.js +2 -2
- package/dist/src/apple/templates.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +1 -0
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nuxt/nuxt-wizard.d.ts +3 -0
- package/dist/src/nuxt/nuxt-wizard.js +227 -0
- package/dist/src/nuxt/nuxt-wizard.js.map +1 -0
- package/dist/src/nuxt/sdk-example.d.ts +8 -0
- package/dist/src/nuxt/sdk-example.js +179 -0
- package/dist/src/nuxt/sdk-example.js.map +1 -0
- package/dist/src/nuxt/sdk-setup.d.ts +11 -0
- package/dist/src/nuxt/sdk-setup.js +326 -0
- package/dist/src/nuxt/sdk-setup.js.map +1 -0
- package/dist/src/nuxt/templates.d.ts +22 -0
- package/dist/src/nuxt/templates.js +84 -0
- package/dist/src/nuxt/templates.js.map +1 -0
- package/dist/src/nuxt/utils.d.ts +1 -0
- package/dist/src/nuxt/utils.js +71 -0
- package/dist/src/nuxt/utils.js.map +1 -0
- package/dist/src/remix/remix-wizard.js +2 -1
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/run.d.ts +1 -1
- package/dist/src/run.js +30 -23
- package/dist/src/run.js.map +1 -1
- package/dist/src/sourcemaps/tools/rollup.js +1 -1
- package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +2 -1
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +9 -2
- package/dist/src/utils/clack-utils.js +93 -27
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-json.d.ts +5 -0
- package/dist/src/utils/package-json.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +1 -0
- package/dist/src/utils/package-manager.js +129 -0
- package/dist/src/utils/package-manager.js.map +1 -1
- package/dist/test/nuxt/templates.test.d.ts +1 -0
- package/dist/test/nuxt/templates.test.js +70 -0
- package/dist/test/nuxt/templates.test.js.map +1 -0
- package/e2e-tests/README.md +59 -0
- package/e2e-tests/test-applications/nuxt-3-test-app/README.md +75 -0
- package/e2e-tests/test-applications/nuxt-3-test-app/nuxt.config.ts +5 -0
- package/e2e-tests/test-applications/nuxt-3-test-app/package.json +18 -0
- package/e2e-tests/test-applications/nuxt-3-test-app/public/favicon.ico +0 -0
- package/e2e-tests/test-applications/nuxt-3-test-app/public/robots.txt +1 -0
- package/e2e-tests/tests/nuxt-3.test.ts +192 -0
- package/e2e-tests/tests/nuxt-4.test.ts +191 -0
- package/e2e-tests/tests/remix.test.ts +163 -50
- package/e2e-tests/tests/sveltekit.test.ts +180 -79
- package/e2e-tests/utils/index.ts +34 -1
- package/lib/Constants.ts +1 -0
- package/package.json +1 -1
- package/src/android/templates.ts +0 -2
- package/src/apple/templates.ts +14 -2
- package/src/nextjs/nextjs-wizard.ts +1 -0
- package/src/nuxt/nuxt-wizard.ts +177 -0
- package/src/nuxt/sdk-example.ts +135 -0
- package/src/nuxt/sdk-setup.ts +248 -0
- package/src/nuxt/templates.ts +296 -0
- package/src/nuxt/utils.ts +32 -0
- package/src/remix/remix-wizard.ts +2 -1
- package/src/run.ts +7 -0
- package/src/sourcemaps/tools/rollup.ts +1 -1
- package/src/sveltekit/sveltekit-wizard.ts +2 -1
- package/src/utils/clack-utils.ts +74 -13
- package/src/utils/package-json.ts +5 -0
- package/src/utils/package-manager.ts +66 -0
- package/test/nuxt/templates.test.ts +228 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
2
|
+
import * as clack from '@clack/prompts';
|
|
3
|
+
import * as Sentry from '@sentry/node';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { lt, minVersion } from 'semver';
|
|
6
|
+
import type { WizardOptions } from '../utils/types';
|
|
7
|
+
import { traceStep, withTelemetry } from '../telemetry';
|
|
8
|
+
import {
|
|
9
|
+
abort,
|
|
10
|
+
abortIfCancelled,
|
|
11
|
+
addDotEnvSentryBuildPluginFile,
|
|
12
|
+
askShouldCreateExampleComponent,
|
|
13
|
+
askShouldCreateExamplePage,
|
|
14
|
+
confirmContinueIfNoOrDirtyGitRepo,
|
|
15
|
+
ensurePackageIsInstalled,
|
|
16
|
+
getOrAskForProjectData,
|
|
17
|
+
getPackageDotJson,
|
|
18
|
+
getPackageManager,
|
|
19
|
+
installPackage,
|
|
20
|
+
printWelcome,
|
|
21
|
+
runPrettierIfInstalled,
|
|
22
|
+
} from '../utils/clack-utils';
|
|
23
|
+
import { getPackageVersion, hasPackageInstalled } from '../utils/package-json';
|
|
24
|
+
import {
|
|
25
|
+
addSDKModule,
|
|
26
|
+
getNuxtConfig,
|
|
27
|
+
createConfigFiles,
|
|
28
|
+
addNuxtOverrides,
|
|
29
|
+
} from './sdk-setup';
|
|
30
|
+
import {
|
|
31
|
+
createExampleComponent,
|
|
32
|
+
createExamplePage,
|
|
33
|
+
supportsExamplePage,
|
|
34
|
+
} from './sdk-example';
|
|
35
|
+
import { isNuxtV4 } from './utils';
|
|
36
|
+
|
|
37
|
+
export function runNuxtWizard(options: WizardOptions) {
|
|
38
|
+
return withTelemetry(
|
|
39
|
+
{
|
|
40
|
+
enabled: options.telemetryEnabled,
|
|
41
|
+
integration: 'nuxt',
|
|
42
|
+
wizardOptions: options,
|
|
43
|
+
},
|
|
44
|
+
() => runNuxtWizardWithTelemetry(options),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function runNuxtWizardWithTelemetry(
|
|
49
|
+
options: WizardOptions,
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
printWelcome({
|
|
52
|
+
wizardName: 'Sentry Nuxt Wizard',
|
|
53
|
+
promoCode: options.promoCode,
|
|
54
|
+
telemetryEnabled: options.telemetryEnabled,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await confirmContinueIfNoOrDirtyGitRepo();
|
|
58
|
+
|
|
59
|
+
const packageJson = await getPackageDotJson();
|
|
60
|
+
|
|
61
|
+
await ensurePackageIsInstalled(packageJson, 'nuxt', 'Nuxt');
|
|
62
|
+
|
|
63
|
+
const nuxtVersion = getPackageVersion('nuxt', packageJson);
|
|
64
|
+
Sentry.setTag('nuxt-version', nuxtVersion);
|
|
65
|
+
|
|
66
|
+
const minVer = minVersion(nuxtVersion || '0.0.0');
|
|
67
|
+
|
|
68
|
+
if (!nuxtVersion || !minVer || lt(minVer, '3.7.0')) {
|
|
69
|
+
clack.log.warn(
|
|
70
|
+
"It seems you're using a Nuxt version <3.7.0 which is not supported by Sentry.\nWe recommend upgrading to the latest version before you continue.",
|
|
71
|
+
);
|
|
72
|
+
const shouldContinue = await abortIfCancelled(
|
|
73
|
+
clack.select({
|
|
74
|
+
message: 'Do you want to continue anyway?',
|
|
75
|
+
options: [
|
|
76
|
+
{
|
|
77
|
+
label: 'Yes, continue',
|
|
78
|
+
hint: 'The SDK might not work correctly',
|
|
79
|
+
value: true,
|
|
80
|
+
},
|
|
81
|
+
{ label: "No, I'll upgrade first", value: false },
|
|
82
|
+
],
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
if (!shouldContinue) {
|
|
86
|
+
await abort('Exiting Wizard', 0);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { authToken, selectedProject, selfHosted, sentryUrl } =
|
|
92
|
+
await getOrAskForProjectData(options, 'javascript-nuxt');
|
|
93
|
+
|
|
94
|
+
const packageManager = await getPackageManager();
|
|
95
|
+
|
|
96
|
+
await addNuxtOverrides(packageManager, minVer);
|
|
97
|
+
|
|
98
|
+
const sdkAlreadyInstalled = hasPackageInstalled('@sentry/nuxt', packageJson);
|
|
99
|
+
Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled);
|
|
100
|
+
|
|
101
|
+
await installPackage({
|
|
102
|
+
packageName: '@sentry/nuxt',
|
|
103
|
+
alreadyInstalled: sdkAlreadyInstalled,
|
|
104
|
+
packageManager,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
await addDotEnvSentryBuildPluginFile(authToken);
|
|
108
|
+
|
|
109
|
+
const nuxtConfig = await traceStep('load-nuxt-config', getNuxtConfig);
|
|
110
|
+
|
|
111
|
+
const projectData = {
|
|
112
|
+
org: selectedProject.organization.slug,
|
|
113
|
+
project: selectedProject.slug,
|
|
114
|
+
projectId: selectedProject.id,
|
|
115
|
+
url: sentryUrl,
|
|
116
|
+
selfHosted,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
await traceStep('configure-sdk', async () => {
|
|
120
|
+
await addSDKModule(nuxtConfig, projectData);
|
|
121
|
+
await createConfigFiles(selectedProject.keys[0].dsn.public);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
let shouldCreateExamplePage = false;
|
|
125
|
+
let shouldCreateExampleButton = false;
|
|
126
|
+
|
|
127
|
+
const isV4 = await isNuxtV4(nuxtConfig, nuxtVersion);
|
|
128
|
+
const canCreateExamplePage = await supportsExamplePage(isV4);
|
|
129
|
+
Sentry.setTag('supports-example-page-creation', canCreateExamplePage);
|
|
130
|
+
|
|
131
|
+
if (canCreateExamplePage) {
|
|
132
|
+
shouldCreateExamplePage = await askShouldCreateExamplePage();
|
|
133
|
+
|
|
134
|
+
if (shouldCreateExamplePage) {
|
|
135
|
+
await traceStep('create-example-page', async () =>
|
|
136
|
+
createExamplePage(isV4, projectData),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
shouldCreateExampleButton = await askShouldCreateExampleComponent();
|
|
141
|
+
|
|
142
|
+
if (shouldCreateExampleButton) {
|
|
143
|
+
await traceStep('create-example-component', async () =>
|
|
144
|
+
createExampleComponent(isV4),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
await runPrettierIfInstalled();
|
|
150
|
+
|
|
151
|
+
clack.outro(
|
|
152
|
+
buildOutroMessage(shouldCreateExamplePage, shouldCreateExampleButton),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function buildOutroMessage(
|
|
157
|
+
shouldCreateExamplePage: boolean,
|
|
158
|
+
shouldCreateExampleButton: boolean,
|
|
159
|
+
): string {
|
|
160
|
+
let msg = chalk.green('\nSuccessfully installed the Sentry Nuxt SDK!');
|
|
161
|
+
|
|
162
|
+
if (shouldCreateExamplePage) {
|
|
163
|
+
msg += `\n\nYou can validate your setup by visiting ${chalk.cyan(
|
|
164
|
+
'"/sentry-example-page"',
|
|
165
|
+
)}.`;
|
|
166
|
+
}
|
|
167
|
+
if (shouldCreateExampleButton) {
|
|
168
|
+
msg += `\n\nYou can validate your setup by adding the ${chalk.cyan(
|
|
169
|
+
'`SentryExampleButton`',
|
|
170
|
+
)} component to a page and triggering it.`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
msg += `\n\nCheck out the SDK documentation for further configuration:
|
|
174
|
+
https://docs.sentry.io/platforms/javascript/guides/nuxt/`;
|
|
175
|
+
|
|
176
|
+
return msg;
|
|
177
|
+
}
|
|
@@ -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,248 @@
|
|
|
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
|
+
askShouldAddPackageOverride,
|
|
21
|
+
featureSelectionPrompt,
|
|
22
|
+
isUsingTypeScript,
|
|
23
|
+
} from '../utils/clack-utils';
|
|
24
|
+
import { traceStep } from '../telemetry';
|
|
25
|
+
import { lt, SemVer } from 'semver';
|
|
26
|
+
import { PackageManager } from '../utils/package-manager';
|
|
27
|
+
|
|
28
|
+
const possibleNuxtConfig = [
|
|
29
|
+
'nuxt.config.js',
|
|
30
|
+
'nuxt.config.mjs',
|
|
31
|
+
'nuxt.config.cjs',
|
|
32
|
+
'nuxt.config.ts',
|
|
33
|
+
'nuxt.config.mts',
|
|
34
|
+
'nuxt.config.cts',
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export async function getNuxtConfig(): Promise<string> {
|
|
38
|
+
let configFile = possibleNuxtConfig.find((fileName) =>
|
|
39
|
+
fs.existsSync(path.join(process.cwd(), fileName)),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!configFile) {
|
|
43
|
+
clack.log.info('No Nuxt config file found, creating a new one.');
|
|
44
|
+
Sentry.setTag('nuxt-config-strategy', 'create');
|
|
45
|
+
// nuxt recommends its config to be .ts by default
|
|
46
|
+
configFile = 'nuxt.config.ts';
|
|
47
|
+
|
|
48
|
+
await fs.promises.writeFile(
|
|
49
|
+
path.join(process.cwd(), configFile),
|
|
50
|
+
getDefaultNuxtConfig(),
|
|
51
|
+
{ encoding: 'utf-8', flag: 'w' },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
clack.log.success(`Created ${chalk.cyan('nuxt.config.ts')}.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return path.join(process.cwd(), configFile);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function addSDKModule(
|
|
61
|
+
config: string,
|
|
62
|
+
options: { org: string; project: string; url: string; selfHosted: boolean },
|
|
63
|
+
): Promise<void> {
|
|
64
|
+
try {
|
|
65
|
+
const mod = await loadFile(config);
|
|
66
|
+
|
|
67
|
+
addNuxtModule(mod, '@sentry/nuxt/module', 'sentry', {
|
|
68
|
+
sourceMapsUploadOptions: {
|
|
69
|
+
org: options.org,
|
|
70
|
+
project: options.project,
|
|
71
|
+
...(options.selfHosted && { url: options.url }),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
addNuxtModule(mod, '@sentry/nuxt/module', 'sourcemap', {
|
|
75
|
+
client: 'hidden',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const { code } = generateCode(mod);
|
|
79
|
+
|
|
80
|
+
await fs.promises.writeFile(config, code, { encoding: 'utf-8', flag: 'w' });
|
|
81
|
+
|
|
82
|
+
clack.log.success(
|
|
83
|
+
`Added Sentry Nuxt Module to ${chalk.cyan(path.basename(config))}.`,
|
|
84
|
+
);
|
|
85
|
+
} catch (e: unknown) {
|
|
86
|
+
// Cases where users spread options are not covered by magicast,
|
|
87
|
+
// so we fall back to showing how to configure the nuxt config
|
|
88
|
+
// manually.
|
|
89
|
+
if (e instanceof MagicastError) {
|
|
90
|
+
clack.log.warn(
|
|
91
|
+
`Automatic configuration of ${chalk.cyan(
|
|
92
|
+
path.basename(config),
|
|
93
|
+
)} failed, please add the following settings:`,
|
|
94
|
+
);
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.log(`\n\n${getNuxtModuleFallbackTemplate(options)}\n\n`);
|
|
97
|
+
} else {
|
|
98
|
+
clack.log.error(
|
|
99
|
+
'Error while adding the Sentry Nuxt Module to the Nuxt config.',
|
|
100
|
+
);
|
|
101
|
+
clack.log.info(
|
|
102
|
+
chalk.dim(
|
|
103
|
+
typeof e === 'object' && e != null && 'toString' in e
|
|
104
|
+
? e.toString()
|
|
105
|
+
: typeof e === 'string'
|
|
106
|
+
? e
|
|
107
|
+
: 'Unknown error',
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
Sentry.captureException('Error while setting up the Nuxt SDK');
|
|
111
|
+
await abort('Exiting Wizard');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function createConfigFiles(dsn: string) {
|
|
117
|
+
const selectedFeatures = await featureSelectionPrompt([
|
|
118
|
+
{
|
|
119
|
+
id: 'performance',
|
|
120
|
+
prompt: `Do you want to enable ${chalk.bold(
|
|
121
|
+
'Tracing',
|
|
122
|
+
)} to track the performance of your application?`,
|
|
123
|
+
enabledHint: 'recommended',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: 'replay',
|
|
127
|
+
prompt: `Do you want to enable ${chalk.bold(
|
|
128
|
+
'Sentry Session Replay',
|
|
129
|
+
)} to get a video-like reproduction of errors during a user session?`,
|
|
130
|
+
enabledHint: 'recommended, but increases bundle size',
|
|
131
|
+
},
|
|
132
|
+
] as const);
|
|
133
|
+
|
|
134
|
+
const typeScriptDetected = isUsingTypeScript();
|
|
135
|
+
|
|
136
|
+
const configVariants = ['server', 'client'] as const;
|
|
137
|
+
|
|
138
|
+
for (const configVariant of configVariants) {
|
|
139
|
+
await traceStep(`create-sentry-${configVariant}-config`, async () => {
|
|
140
|
+
const jsConfig = `sentry.${configVariant}.config.js`;
|
|
141
|
+
const tsConfig = `sentry.${configVariant}.config.ts`;
|
|
142
|
+
|
|
143
|
+
const jsConfigExists = fs.existsSync(path.join(process.cwd(), jsConfig));
|
|
144
|
+
const tsConfigExists = fs.existsSync(path.join(process.cwd(), tsConfig));
|
|
145
|
+
|
|
146
|
+
let shouldWriteFile = true;
|
|
147
|
+
|
|
148
|
+
if (jsConfigExists || tsConfigExists) {
|
|
149
|
+
const existingConfigs = [];
|
|
150
|
+
|
|
151
|
+
if (jsConfigExists) {
|
|
152
|
+
existingConfigs.push(jsConfig);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (tsConfigExists) {
|
|
156
|
+
existingConfigs.push(tsConfig);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const overwriteExistingConfigs = await abortIfCancelled(
|
|
160
|
+
clack.confirm({
|
|
161
|
+
message: `Found existing Sentry ${configVariant} config (${existingConfigs.join(
|
|
162
|
+
', ',
|
|
163
|
+
)}). Overwrite ${existingConfigs.length > 1 ? 'them' : 'it'}?`,
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
Sentry.setTag(
|
|
167
|
+
`overwrite-${configVariant}-config`,
|
|
168
|
+
overwriteExistingConfigs,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
shouldWriteFile = overwriteExistingConfigs;
|
|
172
|
+
|
|
173
|
+
if (overwriteExistingConfigs) {
|
|
174
|
+
if (jsConfigExists) {
|
|
175
|
+
fs.unlinkSync(path.join(process.cwd(), jsConfig));
|
|
176
|
+
clack.log.warn(`Removed existing ${chalk.cyan(jsConfig)}.`);
|
|
177
|
+
}
|
|
178
|
+
if (tsConfigExists) {
|
|
179
|
+
fs.unlinkSync(path.join(process.cwd(), tsConfig));
|
|
180
|
+
clack.log.warn(`Removed existing ${chalk.cyan(tsConfig)}.`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (shouldWriteFile) {
|
|
186
|
+
await fs.promises.writeFile(
|
|
187
|
+
path.join(process.cwd(), typeScriptDetected ? tsConfig : jsConfig),
|
|
188
|
+
getSentryConfigContents(dsn, configVariant, selectedFeatures),
|
|
189
|
+
{ encoding: 'utf8', flag: 'w' },
|
|
190
|
+
);
|
|
191
|
+
clack.log.success(
|
|
192
|
+
`Created new ${chalk.cyan(
|
|
193
|
+
typeScriptDetected ? tsConfig : jsConfig,
|
|
194
|
+
)}.`,
|
|
195
|
+
);
|
|
196
|
+
Sentry.setTag(`created-${configVariant}-config`, true);
|
|
197
|
+
} else {
|
|
198
|
+
clack.log.info(
|
|
199
|
+
`Okay, here are the changes your ${chalk.cyan(
|
|
200
|
+
typeScriptDetected ? tsConfig : jsConfig,
|
|
201
|
+
)} should contain:`,
|
|
202
|
+
);
|
|
203
|
+
// eslint-disable-next-line no-console
|
|
204
|
+
console.log(
|
|
205
|
+
'\n\n ' +
|
|
206
|
+
getConfigBody(dsn, configVariant, selectedFeatures) +
|
|
207
|
+
'\n\n',
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function addNuxtOverrides(
|
|
215
|
+
packageManager: PackageManager,
|
|
216
|
+
nuxtMinVer: SemVer | null,
|
|
217
|
+
) {
|
|
218
|
+
const overrides = [
|
|
219
|
+
{
|
|
220
|
+
pkgName: 'nitropack',
|
|
221
|
+
pkgVersion: '~2.9.7',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
pkgName: '@vercel/nft',
|
|
225
|
+
pkgVersion: '^0.27.4',
|
|
226
|
+
},
|
|
227
|
+
...(nuxtMinVer && lt(nuxtMinVer, '3.14.0')
|
|
228
|
+
? [{ pkgName: 'ofetch', pkgVersion: '^1.4.0' }]
|
|
229
|
+
: []),
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
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(
|
|
234
|
+
'https://github.com/getsentry/sentry-javascript/issues/14514',
|
|
235
|
+
)}`,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
for (const { pkgName, pkgVersion } of overrides) {
|
|
239
|
+
const shouldAddOverride = await askShouldAddPackageOverride(
|
|
240
|
+
pkgName,
|
|
241
|
+
pkgVersion,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
if (shouldAddOverride) {
|
|
245
|
+
await packageManager.addOverride(pkgName, pkgVersion);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|