@sentry/wizard 3.13.0 → 3.14.1
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 +11 -1
- package/dist/package.json +2 -2
- package/dist/src/android/android-wizard.js +2 -4
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/apple/apple-wizard.js +1 -1
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.d.ts +1 -0
- package/dist/src/nextjs/nextjs-wizard.js +252 -161
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/utils.d.ts +1 -0
- package/dist/src/nextjs/utils.js +25 -0
- package/dist/src/nextjs/utils.js.map +1 -0
- package/dist/src/remix/remix-wizard.js +5 -7
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.js +10 -4
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +7 -3
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +6 -10
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/telemetry.d.ts +1 -0
- package/dist/src/telemetry.js +27 -12
- package/dist/src/telemetry.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +11 -1
- package/dist/src/utils/clack-utils.js +190 -126
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-manager.js +12 -7
- package/dist/src/utils/package-manager.js.map +1 -1
- package/package.json +2 -2
- package/src/android/android-wizard.ts +4 -5
- package/src/apple/apple-wizard.ts +2 -2
- package/src/nextjs/nextjs-wizard.ts +262 -195
- package/src/nextjs/utils.ts +21 -0
- package/src/remix/remix-wizard.ts +7 -9
- package/src/remix/sdk-setup.ts +12 -3
- package/src/sourcemaps/sourcemaps-wizard.ts +2 -2
- package/src/sveltekit/sdk-setup.ts +6 -3
- package/src/sveltekit/sveltekit-wizard.ts +9 -12
- package/src/telemetry.ts +22 -11
- package/src/utils/clack-utils.ts +177 -107
- package/src/utils/package-manager.ts +12 -6
|
@@ -71,7 +71,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
71
71
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
72
72
|
};
|
|
73
73
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
74
|
-
exports.runNextjsWizard = void 0;
|
|
74
|
+
exports.runNextjsWizardWithTelemetry = exports.runNextjsWizard = void 0;
|
|
75
75
|
/* eslint-disable max-lines */
|
|
76
76
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
77
77
|
var prompts_1 = __importDefault(require("@clack/prompts"));
|
|
@@ -80,175 +80,273 @@ var fs = __importStar(require("fs"));
|
|
|
80
80
|
// @ts-ignore - magicast is ESM and TS complains about that. It works though
|
|
81
81
|
var magicast_1 = require("magicast");
|
|
82
82
|
var path = __importStar(require("path"));
|
|
83
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
83
84
|
var clack_utils_1 = require("../utils/clack-utils");
|
|
84
85
|
var templates_1 = require("./templates");
|
|
85
|
-
|
|
86
|
+
var telemetry_1 = require("../telemetry");
|
|
87
|
+
var package_json_1 = require("../utils/package-json");
|
|
88
|
+
var utils_1 = require("./utils");
|
|
86
89
|
function runNextjsWizard(options) {
|
|
90
|
+
return (0, telemetry_1.withTelemetry)({
|
|
91
|
+
enabled: options.telemetryEnabled,
|
|
92
|
+
integration: 'nextjs',
|
|
93
|
+
}, function () { return runNextjsWizardWithTelemetry(options); });
|
|
94
|
+
}
|
|
95
|
+
exports.runNextjsWizard = runNextjsWizard;
|
|
96
|
+
function runNextjsWizardWithTelemetry(options) {
|
|
87
97
|
var _a;
|
|
88
98
|
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
-
var packageJson, _b, selectedProject, authToken, selfHosted, sentryUrl,
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
var packageJson, nextVersion, _b, selectedProject, authToken, selfHosted, sentryUrl, sdkAlreadyInstalled, mightBeUsingVercel;
|
|
100
|
+
var _this = this;
|
|
101
|
+
return __generator(this, function (_c) {
|
|
102
|
+
switch (_c.label) {
|
|
92
103
|
case 0:
|
|
93
104
|
(0, clack_utils_1.printWelcome)({
|
|
94
105
|
wizardName: 'Sentry Next.js Wizard',
|
|
95
106
|
promoCode: options.promoCode,
|
|
107
|
+
telemetryEnabled: options.telemetryEnabled,
|
|
96
108
|
});
|
|
97
|
-
return [4 /*yield*/, (0, clack_utils_1.
|
|
109
|
+
return [4 /*yield*/, (0, clack_utils_1.confirmContinueIfNoOrDirtyGitRepo)()];
|
|
98
110
|
case 1:
|
|
99
|
-
|
|
111
|
+
_c.sent();
|
|
100
112
|
return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
|
|
101
113
|
case 2:
|
|
102
|
-
packageJson =
|
|
114
|
+
packageJson = _c.sent();
|
|
103
115
|
return [4 /*yield*/, (0, clack_utils_1.ensurePackageIsInstalled)(packageJson, 'next', 'Next.js')];
|
|
104
116
|
case 3:
|
|
105
|
-
|
|
117
|
+
_c.sent();
|
|
118
|
+
nextVersion = (0, package_json_1.getPackageVersion)('next', packageJson);
|
|
119
|
+
Sentry.setTag('nextjs-version', (0, utils_1.getNextJsVersionBucket)(nextVersion));
|
|
106
120
|
return [4 /*yield*/, (0, clack_utils_1.getOrAskForProjectData)(options, 'javascript-nextjs')];
|
|
107
121
|
case 4:
|
|
108
|
-
_b =
|
|
122
|
+
_b = _c.sent(), selectedProject = _b.selectedProject, authToken = _b.authToken, selfHosted = _b.selfHosted, sentryUrl = _b.sentryUrl;
|
|
123
|
+
sdkAlreadyInstalled = (0, package_json_1.hasPackageInstalled)('@sentry/nextjs', packageJson);
|
|
124
|
+
Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled);
|
|
109
125
|
return [4 /*yield*/, (0, clack_utils_1.installPackage)({
|
|
110
126
|
packageName: '@sentry/nextjs',
|
|
111
127
|
alreadyInstalled: !!((_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['@sentry/nextjs']),
|
|
112
128
|
})];
|
|
113
129
|
case 5:
|
|
114
|
-
|
|
130
|
+
_c.sent();
|
|
131
|
+
return [4 /*yield*/, (0, telemetry_1.traceStep)('configure-sdk', function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
132
|
+
return [2 /*return*/, createOrMergeNextJsFiles(selectedProject, selfHosted, sentryUrl)];
|
|
133
|
+
}); }); })];
|
|
134
|
+
case 6:
|
|
135
|
+
_c.sent();
|
|
136
|
+
return [4 /*yield*/, (0, telemetry_1.traceStep)('create-example-page', function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
137
|
+
return [2 /*return*/, createExamplePage(selfHosted, selectedProject, sentryUrl)];
|
|
138
|
+
}); }); })];
|
|
139
|
+
case 7:
|
|
140
|
+
_c.sent();
|
|
141
|
+
return [4 /*yield*/, (0, clack_utils_1.addSentryCliConfig)(authToken)];
|
|
142
|
+
case 8:
|
|
143
|
+
_c.sent();
|
|
144
|
+
mightBeUsingVercel = fs.existsSync(path.join(process.cwd(), 'vercel.json'));
|
|
145
|
+
prompts_1.default.outro("".concat(chalk_1.default.green('Everything is set up!'), "\n\n ").concat(chalk_1.default.cyan('You can validate your setup by starting your dev environment (`next dev`) and visiting "/sentry-example-page".'), "\n").concat(mightBeUsingVercel
|
|
146
|
+
? "\n \u25B2 It seems like you're using Vercel. We recommend using the Sentry Vercel integration: https://vercel.com/integrations/sentry\n"
|
|
147
|
+
: '', "\n ").concat(chalk_1.default.dim('If you encounter any issues, let us know here: https://github.com/getsentry/sentry-javascript/issues')));
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.runNextjsWizardWithTelemetry = runNextjsWizardWithTelemetry;
|
|
154
|
+
function createOrMergeNextJsFiles(selectedProject, selfHosted, sentryUrl) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var typeScriptDetected, configVariants, _loop_1, _i, configVariants_1, configVariant, sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate, nextConfigJs, nextConfigMjs;
|
|
157
|
+
var _this = this;
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
switch (_a.label) {
|
|
160
|
+
case 0:
|
|
115
161
|
typeScriptDetected = (0, clack_utils_1.isUsingTypeScript)();
|
|
116
162
|
configVariants = ['server', 'client', 'edge'];
|
|
163
|
+
_loop_1 = function (configVariant) {
|
|
164
|
+
return __generator(this, function (_b) {
|
|
165
|
+
switch (_b.label) {
|
|
166
|
+
case 0: return [4 /*yield*/, (0, telemetry_1.traceStep)("create-sentry-".concat(configVariant, "-config"), function () { return __awaiter(_this, void 0, void 0, function () {
|
|
167
|
+
var jsConfig, tsConfig, jsConfigExists, tsConfigExists, shouldWriteFile, existingConfigs, overwriteExistingConfigs;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
jsConfig = "sentry.".concat(configVariant, ".config.js");
|
|
172
|
+
tsConfig = "sentry.".concat(configVariant, ".config.ts");
|
|
173
|
+
jsConfigExists = fs.existsSync(path.join(process.cwd(), jsConfig));
|
|
174
|
+
tsConfigExists = fs.existsSync(path.join(process.cwd(), tsConfig));
|
|
175
|
+
shouldWriteFile = true;
|
|
176
|
+
if (!(jsConfigExists || tsConfigExists)) return [3 /*break*/, 2];
|
|
177
|
+
existingConfigs = [];
|
|
178
|
+
if (jsConfigExists) {
|
|
179
|
+
existingConfigs.push(jsConfig);
|
|
180
|
+
}
|
|
181
|
+
if (tsConfigExists) {
|
|
182
|
+
existingConfigs.push(tsConfig);
|
|
183
|
+
}
|
|
184
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
|
|
185
|
+
message: "Found existing Sentry ".concat(configVariant, " config (").concat(existingConfigs.join(', '), "). Overwrite ").concat(existingConfigs.length > 1 ? 'them' : 'it', "?"),
|
|
186
|
+
}))];
|
|
187
|
+
case 1:
|
|
188
|
+
overwriteExistingConfigs = _a.sent();
|
|
189
|
+
Sentry.setTag("overwrite-".concat(configVariant, "-config"), overwriteExistingConfigs);
|
|
190
|
+
shouldWriteFile = overwriteExistingConfigs;
|
|
191
|
+
if (overwriteExistingConfigs) {
|
|
192
|
+
if (jsConfigExists) {
|
|
193
|
+
fs.unlinkSync(path.join(process.cwd(), jsConfig));
|
|
194
|
+
prompts_1.default.log.warn("Removed existing ".concat(chalk_1.default.bold(jsConfig), "."));
|
|
195
|
+
}
|
|
196
|
+
if (tsConfigExists) {
|
|
197
|
+
fs.unlinkSync(path.join(process.cwd(), tsConfig));
|
|
198
|
+
prompts_1.default.log.warn("Removed existing ".concat(chalk_1.default.bold(tsConfig), "."));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_a.label = 2;
|
|
202
|
+
case 2:
|
|
203
|
+
if (!shouldWriteFile) return [3 /*break*/, 4];
|
|
204
|
+
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), typeScriptDetected ? tsConfig : jsConfig), (0, templates_1.getSentryConfigContents)(selectedProject.keys[0].dsn.public, configVariant), { encoding: 'utf8', flag: 'w' })];
|
|
205
|
+
case 3:
|
|
206
|
+
_a.sent();
|
|
207
|
+
prompts_1.default.log.success("Created fresh ".concat(chalk_1.default.bold(typeScriptDetected ? tsConfig : jsConfig), "."));
|
|
208
|
+
Sentry.setTag("created-".concat(configVariant, "-config"), true);
|
|
209
|
+
_a.label = 4;
|
|
210
|
+
case 4: return [2 /*return*/];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}); })];
|
|
214
|
+
case 1:
|
|
215
|
+
_b.sent();
|
|
216
|
+
return [2 /*return*/];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
};
|
|
117
220
|
_i = 0, configVariants_1 = configVariants;
|
|
118
|
-
|
|
119
|
-
case
|
|
120
|
-
if (!(_i < configVariants_1.length)) return [3 /*break*/,
|
|
221
|
+
_a.label = 1;
|
|
222
|
+
case 1:
|
|
223
|
+
if (!(_i < configVariants_1.length)) return [3 /*break*/, 4];
|
|
121
224
|
configVariant = configVariants_1[_i];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!(jsConfigExists || tsConfigExists)) return [3 /*break*/, 8];
|
|
128
|
-
existingConfigs = [];
|
|
129
|
-
if (jsConfigExists) {
|
|
130
|
-
existingConfigs.push(jsConfig);
|
|
131
|
-
}
|
|
132
|
-
if (tsConfigExists) {
|
|
133
|
-
existingConfigs.push(tsConfig);
|
|
134
|
-
}
|
|
135
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
|
|
136
|
-
message: "Found existing Sentry ".concat(configVariant, " config (").concat(existingConfigs.join(', '), "). Overwrite ").concat(existingConfigs.length > 1 ? 'them' : 'it', "?"),
|
|
137
|
-
}))];
|
|
138
|
-
case 7:
|
|
139
|
-
overwriteExistingConfigs = _d.sent();
|
|
140
|
-
shouldWriteFile = overwriteExistingConfigs;
|
|
141
|
-
if (overwriteExistingConfigs) {
|
|
142
|
-
if (jsConfigExists) {
|
|
143
|
-
fs.unlinkSync(path.join(process.cwd(), jsConfig));
|
|
144
|
-
prompts_1.default.log.warn("Removed existing ".concat(chalk_1.default.bold(jsConfig), "."));
|
|
145
|
-
}
|
|
146
|
-
if (tsConfigExists) {
|
|
147
|
-
fs.unlinkSync(path.join(process.cwd(), tsConfig));
|
|
148
|
-
prompts_1.default.log.warn("Removed existing ".concat(chalk_1.default.bold(tsConfig), "."));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
_d.label = 8;
|
|
152
|
-
case 8:
|
|
153
|
-
if (!shouldWriteFile) return [3 /*break*/, 10];
|
|
154
|
-
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), typeScriptDetected ? tsConfig : jsConfig), (0, templates_1.getSentryConfigContents)(selectedProject.keys[0].dsn.public, configVariant), { encoding: 'utf8', flag: 'w' })];
|
|
155
|
-
case 9:
|
|
156
|
-
_d.sent();
|
|
157
|
-
prompts_1.default.log.success("Created fresh ".concat(chalk_1.default.bold(typeScriptDetected ? tsConfig : jsConfig), "."));
|
|
158
|
-
_d.label = 10;
|
|
159
|
-
case 10:
|
|
225
|
+
return [5 /*yield**/, _loop_1(configVariant)];
|
|
226
|
+
case 2:
|
|
227
|
+
_a.sent();
|
|
228
|
+
_a.label = 3;
|
|
229
|
+
case 3:
|
|
160
230
|
_i++;
|
|
161
|
-
return [3 /*break*/,
|
|
162
|
-
case
|
|
231
|
+
return [3 /*break*/, 1];
|
|
232
|
+
case 4:
|
|
163
233
|
sentryWebpackOptionsTemplate = (0, templates_1.getNextjsWebpackPluginOptionsTemplate)(selectedProject.organization.slug, selectedProject.slug, selfHosted, sentryUrl);
|
|
164
234
|
sentryBuildOptionsTemplate = (0, templates_1.getNextjsSentryBuildOptionsTemplate)();
|
|
165
235
|
nextConfigJs = 'next.config.js';
|
|
166
236
|
nextConfigMjs = 'next.config.mjs';
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
237
|
+
return [4 /*yield*/, (0, telemetry_1.traceStep)('setup-next-config', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
238
|
+
var nextConfigJsExists, nextConfigMjsExists, nextConfgiJsContent, probablyIncludesSdk, shouldInject, injectAnyhow, nextConfgiMjsContent, probablyIncludesSdk, shouldInject, injectAnyhow, mod, expressionToWrap, newCode, _a, shouldContinue;
|
|
239
|
+
return __generator(this, function (_b) {
|
|
240
|
+
switch (_b.label) {
|
|
241
|
+
case 0:
|
|
242
|
+
nextConfigJsExists = fs.existsSync(path.join(process.cwd(), nextConfigJs));
|
|
243
|
+
nextConfigMjsExists = fs.existsSync(path.join(process.cwd(), nextConfigMjs));
|
|
244
|
+
if (!(!nextConfigJsExists && !nextConfigMjsExists)) return [3 /*break*/, 2];
|
|
245
|
+
Sentry.setTag('next-config-strategy', 'create');
|
|
246
|
+
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), nextConfigJs), (0, templates_1.getNextjsConfigCjsTemplate)(sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate), { encoding: 'utf8', flag: 'w' })];
|
|
247
|
+
case 1:
|
|
248
|
+
_b.sent();
|
|
249
|
+
prompts_1.default.log.success("Created ".concat(chalk_1.default.bold('next.config.js'), " with Sentry configuration."));
|
|
250
|
+
_b.label = 2;
|
|
251
|
+
case 2:
|
|
252
|
+
if (!nextConfigJsExists) return [3 /*break*/, 7];
|
|
253
|
+
Sentry.setTag('next-config-strategy', 'modify');
|
|
254
|
+
nextConfgiJsContent = fs.readFileSync(path.join(process.cwd(), nextConfigJs), 'utf8');
|
|
255
|
+
probablyIncludesSdk = nextConfgiJsContent.includes('@sentry/nextjs') &&
|
|
256
|
+
nextConfgiJsContent.includes('withSentryConfig');
|
|
257
|
+
shouldInject = true;
|
|
258
|
+
if (!probablyIncludesSdk) return [3 /*break*/, 4];
|
|
259
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
|
|
260
|
+
message: "".concat(chalk_1.default.bold(nextConfigJs), " already contains Sentry SDK configuration. Should the wizard modify it anyways?"),
|
|
261
|
+
}))];
|
|
262
|
+
case 3:
|
|
263
|
+
injectAnyhow = _b.sent();
|
|
264
|
+
shouldInject = injectAnyhow;
|
|
265
|
+
_b.label = 4;
|
|
266
|
+
case 4:
|
|
267
|
+
if (!shouldInject) return [3 /*break*/, 6];
|
|
268
|
+
return [4 /*yield*/, fs.promises.appendFile(path.join(process.cwd(), nextConfigJs), (0, templates_1.getNextjsConfigCjsAppendix)(sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate), 'utf8')];
|
|
269
|
+
case 5:
|
|
270
|
+
_b.sent();
|
|
271
|
+
prompts_1.default.log.success("Added Sentry configuration to ".concat(chalk_1.default.bold(nextConfigJs), ". ").concat(chalk_1.default.dim('(you probably want to clean this up a bit!)')));
|
|
272
|
+
_b.label = 6;
|
|
273
|
+
case 6:
|
|
274
|
+
Sentry.setTag('next-config-mod-result', 'success');
|
|
275
|
+
_b.label = 7;
|
|
276
|
+
case 7:
|
|
277
|
+
if (!nextConfigMjsExists) return [3 /*break*/, 16];
|
|
278
|
+
nextConfgiMjsContent = fs.readFileSync(path.join(process.cwd(), nextConfigMjs), 'utf8');
|
|
279
|
+
probablyIncludesSdk = nextConfgiMjsContent.includes('@sentry/nextjs') &&
|
|
280
|
+
nextConfgiMjsContent.includes('withSentryConfig');
|
|
281
|
+
shouldInject = true;
|
|
282
|
+
if (!probablyIncludesSdk) return [3 /*break*/, 9];
|
|
283
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
|
|
284
|
+
message: "".concat(chalk_1.default.bold(nextConfigMjs), " already contains Sentry SDK configuration. Should the wizard modify it anyways?"),
|
|
285
|
+
}))];
|
|
286
|
+
case 8:
|
|
287
|
+
injectAnyhow = _b.sent();
|
|
288
|
+
shouldInject = injectAnyhow;
|
|
289
|
+
_b.label = 9;
|
|
290
|
+
case 9:
|
|
291
|
+
_b.trys.push([9, 12, , 16]);
|
|
292
|
+
if (!shouldInject) return [3 /*break*/, 11];
|
|
293
|
+
mod = (0, magicast_1.parseModule)(nextConfgiMjsContent);
|
|
294
|
+
mod.imports.$add({
|
|
295
|
+
from: '@sentry/nextjs',
|
|
296
|
+
imported: 'withSentryConfig',
|
|
297
|
+
local: 'withSentryConfig',
|
|
298
|
+
});
|
|
299
|
+
expressionToWrap = (0, magicast_1.generateCode)(mod.exports.default.$ast).code;
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
301
|
+
mod.exports.default = magicast_1.builders.raw("withSentryConfig(\n ".concat(expressionToWrap, ",\n ").concat(sentryWebpackOptionsTemplate, ",\n ").concat(sentryBuildOptionsTemplate, "\n)"));
|
|
302
|
+
newCode = mod.generate().code;
|
|
303
|
+
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), nextConfigMjs), newCode, {
|
|
304
|
+
encoding: 'utf8',
|
|
305
|
+
flag: 'w',
|
|
306
|
+
})];
|
|
307
|
+
case 10:
|
|
308
|
+
_b.sent();
|
|
309
|
+
prompts_1.default.log.success("Added Sentry configuration to ".concat(chalk_1.default.bold(nextConfigMjs), ". ").concat(chalk_1.default.dim('(you probably want to clean this up a bit!)')));
|
|
310
|
+
Sentry.setTag('next-config-mod-result', 'success');
|
|
311
|
+
_b.label = 11;
|
|
312
|
+
case 11: return [3 /*break*/, 16];
|
|
313
|
+
case 12:
|
|
314
|
+
_a = _b.sent();
|
|
315
|
+
Sentry.setTag('next-config-mod-result', 'fail');
|
|
316
|
+
prompts_1.default.log.warn(chalk_1.default.yellow("Something went wrong writing to ".concat(chalk_1.default.bold(nextConfigMjs))));
|
|
317
|
+
prompts_1.default.log.info("Please put the following code snippet into ".concat(chalk_1.default.bold(nextConfigMjs), ": ").concat(chalk_1.default.dim('You probably have to clean it up a bit.'), "\n"));
|
|
318
|
+
// eslint-disable-next-line no-console
|
|
319
|
+
console.log((0, templates_1.getNextjsConfigEsmCopyPasteSnippet)(sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate));
|
|
320
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
|
|
321
|
+
message: "Are you done putting the snippet above into ".concat(chalk_1.default.bold(nextConfigMjs), "?"),
|
|
322
|
+
active: 'Yes',
|
|
323
|
+
inactive: 'No, get me out of here',
|
|
324
|
+
}))];
|
|
325
|
+
case 13:
|
|
326
|
+
shouldContinue = _b.sent();
|
|
327
|
+
if (!!shouldContinue) return [3 /*break*/, 15];
|
|
328
|
+
return [4 /*yield*/, (0, clack_utils_1.abort)()];
|
|
329
|
+
case 14:
|
|
330
|
+
_b.sent();
|
|
331
|
+
_b.label = 15;
|
|
332
|
+
case 15: return [3 /*break*/, 16];
|
|
333
|
+
case 16: return [2 /*return*/];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}); })];
|
|
337
|
+
case 5:
|
|
338
|
+
_a.sent();
|
|
339
|
+
return [2 /*return*/];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
function createExamplePage(selfHosted, selectedProject, sentryUrl) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
+
var srcDir, maybePagesDirPath, maybeSrcPagesDirPath, maybeAppDirPath, maybeSrcAppDirPath, pagesLocation, appLocation, examplePageContents, examplePageContents;
|
|
347
|
+
return __generator(this, function (_a) {
|
|
348
|
+
switch (_a.label) {
|
|
349
|
+
case 0:
|
|
252
350
|
srcDir = path.join(process.cwd(), 'src');
|
|
253
351
|
maybePagesDirPath = path.join(process.cwd(), 'pages');
|
|
254
352
|
maybeSrcPagesDirPath = path.join(srcDir, 'pages');
|
|
@@ -277,7 +375,8 @@ function runNextjsWizard(options) {
|
|
|
277
375
|
recursive: true,
|
|
278
376
|
});
|
|
279
377
|
}
|
|
280
|
-
|
|
378
|
+
Sentry.setTag('nextjs-app-dir', !!appLocation);
|
|
379
|
+
if (!appLocation) return [3 /*break*/, 3];
|
|
281
380
|
examplePageContents = (0, templates_1.getSentryExamplePageContents)({
|
|
282
381
|
selfHosted: selfHosted,
|
|
283
382
|
orgSlug: selectedProject.organization.slug,
|
|
@@ -290,8 +389,8 @@ function runNextjsWizard(options) {
|
|
|
290
389
|
});
|
|
291
390
|
return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['sentry-example-page',
|
|
292
391
|
'page.jsx'], false)), examplePageContents, { encoding: 'utf8', flag: 'w' })];
|
|
293
|
-
case
|
|
294
|
-
|
|
392
|
+
case 1:
|
|
393
|
+
_a.sent();
|
|
295
394
|
prompts_1.default.log.success("Created ".concat(chalk_1.default.bold(path.join.apply(path, __spreadArray(__spreadArray([], appLocation, false), ['sentry-example-page', 'page.jsx'], false))), "."));
|
|
296
395
|
fs.mkdirSync(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['api', 'sentry-example-api'], false)), {
|
|
297
396
|
recursive: true,
|
|
@@ -299,12 +398,12 @@ function runNextjsWizard(options) {
|
|
|
299
398
|
return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['api',
|
|
300
399
|
'sentry-example-api',
|
|
301
400
|
'route.js'], false)), (0, templates_1.getSentryExampleAppDirApiRoute)(), { encoding: 'utf8', flag: 'w' })];
|
|
302
|
-
case
|
|
303
|
-
|
|
401
|
+
case 2:
|
|
402
|
+
_a.sent();
|
|
304
403
|
prompts_1.default.log.success("Created ".concat(chalk_1.default.bold(path.join.apply(path, __spreadArray(__spreadArray([], appLocation, false), ['api', 'sentry-example-api', 'route.js'], false))), "."));
|
|
305
|
-
return [3 /*break*/,
|
|
306
|
-
case
|
|
307
|
-
if (!pagesLocation) return [3 /*break*/,
|
|
404
|
+
return [3 /*break*/, 6];
|
|
405
|
+
case 3:
|
|
406
|
+
if (!pagesLocation) return [3 /*break*/, 6];
|
|
308
407
|
examplePageContents = (0, templates_1.getSentryExamplePageContents)({
|
|
309
408
|
selfHosted: selfHosted,
|
|
310
409
|
orgSlug: selectedProject.organization.slug,
|
|
@@ -313,29 +412,21 @@ function runNextjsWizard(options) {
|
|
|
313
412
|
useClient: false,
|
|
314
413
|
});
|
|
315
414
|
return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], pagesLocation, false), ['sentry-example-page.jsx'], false)), examplePageContents, { encoding: 'utf8', flag: 'w' })];
|
|
316
|
-
case
|
|
317
|
-
|
|
415
|
+
case 4:
|
|
416
|
+
_a.sent();
|
|
318
417
|
prompts_1.default.log.success("Created ".concat(chalk_1.default.bold(path.join.apply(path, __spreadArray(__spreadArray([], pagesLocation, false), ['sentry-example-page.js'], false))), "."));
|
|
319
418
|
fs.mkdirSync(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], pagesLocation, false), ['api'], false)), {
|
|
320
419
|
recursive: true,
|
|
321
420
|
});
|
|
322
421
|
return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], pagesLocation, false), ['api',
|
|
323
422
|
'sentry-example-api.js'], false)), (0, templates_1.getSentryExampleApiRoute)(), { encoding: 'utf8', flag: 'w' })];
|
|
324
|
-
case
|
|
325
|
-
|
|
423
|
+
case 5:
|
|
424
|
+
_a.sent();
|
|
326
425
|
prompts_1.default.log.success("Created ".concat(chalk_1.default.bold(path.join.apply(path, __spreadArray(__spreadArray([], pagesLocation, false), ['api', 'sentry-example-api.js'], false))), "."));
|
|
327
|
-
|
|
328
|
-
case
|
|
329
|
-
case 33:
|
|
330
|
-
_d.sent();
|
|
331
|
-
mightBeUsingVercel = fs.existsSync(path.join(process.cwd(), 'vercel.json'));
|
|
332
|
-
prompts_1.default.outro("".concat(chalk_1.default.green('Everything is set up!'), "\n\n ").concat(chalk_1.default.cyan('You can validate your setup by starting your dev environment (`next dev`) and visiting "/sentry-example-page".'), "\n").concat(mightBeUsingVercel
|
|
333
|
-
? "\n \u25B2 It seems like you're using Vercel. We recommend using the Sentry Vercel integration: https://vercel.com/integrations/sentry\n"
|
|
334
|
-
: '', "\n ").concat(chalk_1.default.dim('If you encounter any issues, let us know here: https://github.com/getsentry/sentry-javascript/issues')));
|
|
335
|
-
return [2 /*return*/];
|
|
426
|
+
_a.label = 6;
|
|
427
|
+
case 6: return [2 /*return*/];
|
|
336
428
|
}
|
|
337
429
|
});
|
|
338
430
|
});
|
|
339
431
|
}
|
|
340
|
-
exports.runNextjsWizard = runNextjsWizard;
|
|
341
432
|
//# sourceMappingURL=nextjs-wizard.js.map
|