@sentry/wizard 3.12.0 → 3.14.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 (86) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/lib/Steps/ChooseIntegration.js +1 -0
  3. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  4. package/dist/package.json +2 -2
  5. package/dist/src/android/android-wizard.js +8 -8
  6. package/dist/src/android/android-wizard.js.map +1 -1
  7. package/dist/src/apple/apple-wizard.js +1 -1
  8. package/dist/src/apple/apple-wizard.js.map +1 -1
  9. package/dist/src/nextjs/nextjs-wizard.d.ts +1 -0
  10. package/dist/src/nextjs/nextjs-wizard.js +257 -163
  11. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  12. package/dist/src/nextjs/templates.d.ts +1 -1
  13. package/dist/src/nextjs/templates.js +2 -2
  14. package/dist/src/nextjs/templates.js.map +1 -1
  15. package/dist/src/nextjs/utils.d.ts +1 -0
  16. package/dist/src/nextjs/utils.js +25 -0
  17. package/dist/src/nextjs/utils.js.map +1 -0
  18. package/dist/src/remix/remix-wizard.js +13 -11
  19. package/dist/src/remix/remix-wizard.js.map +1 -1
  20. package/dist/src/remix/sdk-setup.d.ts +5 -1
  21. package/dist/src/remix/sdk-setup.js +13 -6
  22. package/dist/src/remix/sdk-setup.js.map +1 -1
  23. package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
  24. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  25. package/dist/src/sourcemaps/tools/sentry-cli.d.ts +9 -0
  26. package/dist/src/sourcemaps/tools/sentry-cli.js +26 -22
  27. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  28. package/dist/src/sourcemaps/tools/tsc.d.ts +6 -0
  29. package/dist/src/sourcemaps/tools/tsc.js +98 -17
  30. package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
  31. package/dist/src/sourcemaps/tools/vite.js +3 -13
  32. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  33. package/dist/src/sourcemaps/tools/webpack.js +3 -13
  34. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  35. package/dist/src/sveltekit/sdk-setup.js +122 -48
  36. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  37. package/dist/src/sveltekit/sveltekit-wizard.d.ts +1 -0
  38. package/dist/src/sveltekit/sveltekit-wizard.js +113 -42
  39. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  40. package/dist/src/sveltekit/utils.d.ts +2 -0
  41. package/dist/src/sveltekit/utils.js +48 -0
  42. package/dist/src/sveltekit/utils.js.map +1 -0
  43. package/dist/src/telemetry.d.ts +1 -0
  44. package/dist/src/telemetry.js +27 -12
  45. package/dist/src/telemetry.js.map +1 -1
  46. package/dist/src/utils/ast-utils.d.ts +70 -0
  47. package/dist/src/utils/ast-utils.js +152 -1
  48. package/dist/src/utils/ast-utils.js.map +1 -1
  49. package/dist/src/utils/clack-utils.d.ts +49 -7
  50. package/dist/src/utils/clack-utils.js +238 -168
  51. package/dist/src/utils/clack-utils.js.map +1 -1
  52. package/dist/src/utils/package-manager.d.ts +5 -0
  53. package/dist/src/utils/package-manager.js +23 -14
  54. package/dist/src/utils/package-manager.js.map +1 -1
  55. package/dist/test/sourcemaps/tools/sentry-cli.test.d.ts +1 -0
  56. package/dist/test/sourcemaps/tools/sentry-cli.test.js +112 -0
  57. package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -0
  58. package/dist/test/sourcemaps/tools/tsc.test.d.ts +1 -0
  59. package/dist/test/sourcemaps/tools/tsc.test.js +121 -0
  60. package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -0
  61. package/dist/test/utils/ast-utils.test.js +157 -26
  62. package/dist/test/utils/ast-utils.test.js.map +1 -1
  63. package/lib/Steps/ChooseIntegration.ts +1 -0
  64. package/package.json +2 -2
  65. package/src/android/android-wizard.ts +12 -10
  66. package/src/apple/apple-wizard.ts +2 -2
  67. package/src/nextjs/nextjs-wizard.ts +277 -198
  68. package/src/nextjs/templates.ts +3 -2
  69. package/src/nextjs/utils.ts +21 -0
  70. package/src/remix/remix-wizard.ts +15 -20
  71. package/src/remix/sdk-setup.ts +20 -5
  72. package/src/sourcemaps/sourcemaps-wizard.ts +2 -2
  73. package/src/sourcemaps/tools/sentry-cli.ts +16 -9
  74. package/src/sourcemaps/tools/tsc.ts +133 -28
  75. package/src/sourcemaps/tools/vite.ts +15 -39
  76. package/src/sourcemaps/tools/webpack.ts +16 -39
  77. package/src/sveltekit/sdk-setup.ts +109 -37
  78. package/src/sveltekit/sveltekit-wizard.ts +86 -21
  79. package/src/sveltekit/utils.ts +50 -0
  80. package/src/telemetry.ts +22 -11
  81. package/src/utils/ast-utils.ts +180 -0
  82. package/src/utils/clack-utils.ts +238 -149
  83. package/src/utils/package-manager.ts +24 -12
  84. package/test/sourcemaps/tools/sentry-cli.test.ts +51 -0
  85. package/test/sourcemaps/tools/tsc.test.ts +181 -0
  86. package/test/utils/ast-utils.test.ts +233 -32
@@ -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
- // eslint-disable-next-line complexity
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, typeScriptDetected, configVariants, _i, configVariants_1, configVariant, jsConfig, tsConfig, jsConfigExists, tsConfigExists, shouldWriteFile, existingConfigs, overwriteExistingConfigs, sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate, nextConfigJs, nextConfigMjs, nextConfigJsExists, nextConfigMjsExists, nextConfgiJsContent, probablyIncludesSdk, shouldInject, injectAnyhow, nextConfgiMjsContent, probablyIncludesSdk, shouldInject, injectAnyhow, mod, expressionToWrap, newCode, _c, shouldContinue, srcDir, maybePagesDirPath, maybeSrcPagesDirPath, maybeAppDirPath, maybeSrcAppDirPath, pagesLocation, appLocation, examplePageContents, examplePageContents, mightBeUsingVercel;
90
- return __generator(this, function (_d) {
91
- switch (_d.label) {
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.confirmContinueEvenThoughNoGitRepo)()];
109
+ return [4 /*yield*/, (0, clack_utils_1.confirmContinueIfNoOrDirtyGitRepo)()];
98
110
  case 1:
99
- _d.sent();
111
+ _c.sent();
100
112
  return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
101
113
  case 2:
102
- packageJson = _d.sent();
114
+ packageJson = _c.sent();
103
115
  return [4 /*yield*/, (0, clack_utils_1.ensurePackageIsInstalled)(packageJson, 'next', 'Next.js')];
104
116
  case 3:
105
- _d.sent();
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 = _d.sent(), selectedProject = _b.selectedProject, authToken = _b.authToken, selfHosted = _b.selfHosted, sentryUrl = _b.sentryUrl;
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
- _d.sent();
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
- _d.label = 6;
119
- case 6:
120
- if (!(_i < configVariants_1.length)) return [3 /*break*/, 11];
221
+ _a.label = 1;
222
+ case 1:
223
+ if (!(_i < configVariants_1.length)) return [3 /*break*/, 4];
121
224
  configVariant = configVariants_1[_i];
122
- jsConfig = "sentry.".concat(configVariant, ".config.js");
123
- tsConfig = "sentry.".concat(configVariant, ".config.ts");
124
- jsConfigExists = fs.existsSync(path.join(process.cwd(), jsConfig));
125
- tsConfigExists = fs.existsSync(path.join(process.cwd(), tsConfig));
126
- shouldWriteFile = true;
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*/, 6];
162
- case 11:
163
- sentryWebpackOptionsTemplate = (0, templates_1.getNextjsWebpackPluginOptionsTemplate)(selectedProject.organization.slug, selectedProject.slug);
231
+ return [3 /*break*/, 1];
232
+ case 4:
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
- nextConfigJsExists = fs.existsSync(path.join(process.cwd(), nextConfigJs));
168
- nextConfigMjsExists = fs.existsSync(path.join(process.cwd(), nextConfigMjs));
169
- if (!(!nextConfigJsExists && !nextConfigMjsExists)) return [3 /*break*/, 13];
170
- return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), nextConfigJs), (0, templates_1.getNextjsConfigCjsTemplate)(sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate), { encoding: 'utf8', flag: 'w' })];
171
- case 12:
172
- _d.sent();
173
- prompts_1.default.log.success("Created ".concat(chalk_1.default.bold('next.config.js'), " with Sentry configuration."));
174
- _d.label = 13;
175
- case 13:
176
- if (!nextConfigJsExists) return [3 /*break*/, 17];
177
- nextConfgiJsContent = fs.readFileSync(path.join(process.cwd(), nextConfigJs), 'utf8');
178
- probablyIncludesSdk = nextConfgiJsContent.includes('@sentry/nextjs') &&
179
- nextConfgiJsContent.includes('withSentryConfig');
180
- shouldInject = true;
181
- if (!probablyIncludesSdk) return [3 /*break*/, 15];
182
- return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
183
- message: "".concat(chalk_1.default.bold(nextConfigJs), " already contains Sentry SDK configuration. Should the wizard modify it anyways?"),
184
- }))];
185
- case 14:
186
- injectAnyhow = _d.sent();
187
- shouldInject = injectAnyhow;
188
- _d.label = 15;
189
- case 15:
190
- if (!shouldInject) return [3 /*break*/, 17];
191
- return [4 /*yield*/, fs.promises.appendFile(path.join(process.cwd(), nextConfigJs), (0, templates_1.getNextjsConfigCjsAppendix)(sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate), 'utf8')];
192
- case 16:
193
- _d.sent();
194
- 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!)')));
195
- _d.label = 17;
196
- case 17:
197
- if (!nextConfigMjsExists) return [3 /*break*/, 26];
198
- nextConfgiMjsContent = fs.readFileSync(path.join(process.cwd(), nextConfigMjs), 'utf8');
199
- probablyIncludesSdk = nextConfgiMjsContent.includes('@sentry/nextjs') &&
200
- nextConfgiMjsContent.includes('withSentryConfig');
201
- shouldInject = true;
202
- if (!probablyIncludesSdk) return [3 /*break*/, 19];
203
- return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
204
- message: "".concat(chalk_1.default.bold(nextConfigMjs), " already contains Sentry SDK configuration. Should the wizard modify it anyways?"),
205
- }))];
206
- case 18:
207
- injectAnyhow = _d.sent();
208
- shouldInject = injectAnyhow;
209
- _d.label = 19;
210
- case 19:
211
- _d.trys.push([19, 22, , 26]);
212
- if (!shouldInject) return [3 /*break*/, 21];
213
- mod = (0, magicast_1.parseModule)(nextConfgiMjsContent);
214
- mod.imports.$add({
215
- from: '@sentry/nextjs',
216
- imported: 'withSentryConfig',
217
- local: 'withSentryConfig',
218
- });
219
- expressionToWrap = (0, magicast_1.generateCode)(mod.exports.default.$ast).code;
220
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
221
- mod.exports.default = magicast_1.builders.raw("withSentryConfig(\n ".concat(expressionToWrap, ",\n ").concat(sentryWebpackOptionsTemplate, ",\n ").concat(sentryBuildOptionsTemplate, "\n)"));
222
- newCode = mod.generate().code;
223
- return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), nextConfigMjs), newCode, {
224
- encoding: 'utf8',
225
- flag: 'w',
226
- })];
227
- case 20:
228
- _d.sent();
229
- 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!)')));
230
- _d.label = 21;
231
- case 21: return [3 /*break*/, 26];
232
- case 22:
233
- _c = _d.sent();
234
- prompts_1.default.log.warn(chalk_1.default.yellow("Something went wrong writing to ".concat(chalk_1.default.bold(nextConfigMjs))));
235
- 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"));
236
- // eslint-disable-next-line no-console
237
- console.log((0, templates_1.getNextjsConfigEsmCopyPasteSnippet)(sentryWebpackOptionsTemplate, sentryBuildOptionsTemplate));
238
- return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
239
- message: "Are you done putting the snippet above into ".concat(chalk_1.default.bold(nextConfigMjs), "?"),
240
- active: 'Yes',
241
- inactive: 'No, get me out of here',
242
- }))];
243
- case 23:
244
- shouldContinue = _d.sent();
245
- if (!!shouldContinue) return [3 /*break*/, 25];
246
- return [4 /*yield*/, (0, clack_utils_1.abort)()];
247
- case 24:
248
- _d.sent();
249
- _d.label = 25;
250
- case 25: return [3 /*break*/, 26];
251
- case 26:
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
- if (!appLocation) return [3 /*break*/, 29];
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,
@@ -285,23 +384,26 @@ function runNextjsWizard(options) {
285
384
  url: sentryUrl,
286
385
  useClient: true,
287
386
  });
387
+ fs.mkdirSync(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['sentry-example-page'], false)), {
388
+ recursive: true,
389
+ });
288
390
  return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['sentry-example-page',
289
391
  'page.jsx'], false)), examplePageContents, { encoding: 'utf8', flag: 'w' })];
290
- case 27:
291
- _d.sent();
392
+ case 1:
393
+ _a.sent();
292
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))), "."));
293
- fs.mkdirSync(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['api'], false)), {
395
+ fs.mkdirSync(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['api', 'sentry-example-api'], false)), {
294
396
  recursive: true,
295
397
  });
296
398
  return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], appLocation, false), ['api',
297
399
  'sentry-example-api',
298
400
  'route.js'], false)), (0, templates_1.getSentryExampleAppDirApiRoute)(), { encoding: 'utf8', flag: 'w' })];
299
- case 28:
300
- _d.sent();
401
+ case 2:
402
+ _a.sent();
301
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))), "."));
302
- return [3 /*break*/, 32];
303
- case 29:
304
- if (!pagesLocation) return [3 /*break*/, 32];
404
+ return [3 /*break*/, 6];
405
+ case 3:
406
+ if (!pagesLocation) return [3 /*break*/, 6];
305
407
  examplePageContents = (0, templates_1.getSentryExamplePageContents)({
306
408
  selfHosted: selfHosted,
307
409
  orgSlug: selectedProject.organization.slug,
@@ -310,29 +412,21 @@ function runNextjsWizard(options) {
310
412
  useClient: false,
311
413
  });
312
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' })];
313
- case 30:
314
- _d.sent();
415
+ case 4:
416
+ _a.sent();
315
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))), "."));
316
418
  fs.mkdirSync(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], pagesLocation, false), ['api'], false)), {
317
419
  recursive: true,
318
420
  });
319
421
  return [4 /*yield*/, fs.promises.writeFile(path.join.apply(path, __spreadArray(__spreadArray([process.cwd()], pagesLocation, false), ['api',
320
422
  'sentry-example-api.js'], false)), (0, templates_1.getSentryExampleApiRoute)(), { encoding: 'utf8', flag: 'w' })];
321
- case 31:
322
- _d.sent();
423
+ case 5:
424
+ _a.sent();
323
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))), "."));
324
- _d.label = 32;
325
- case 32: return [4 /*yield*/, (0, clack_utils_1.addSentryCliConfig)(authToken)];
326
- case 33:
327
- _d.sent();
328
- mightBeUsingVercel = fs.existsSync(path.join(process.cwd(), 'vercel.json'));
329
- 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
330
- ? "\n \u25B2 It seems like you're using Vercel. We recommend using the Sentry Vercel integration: https://vercel.com/integrations/sentry\n"
331
- : '', "\n ").concat(chalk_1.default.dim('If you encounter any issues, let us know here: https://github.com/getsentry/sentry-javascript/issues')));
332
- return [2 /*return*/];
426
+ _a.label = 6;
427
+ case 6: return [2 /*return*/];
333
428
  }
334
429
  });
335
430
  });
336
431
  }
337
- exports.runNextjsWizard = runNextjsWizard;
338
432
  //# sourceMappingURL=nextjs-wizard.js.map