@sentry/wizard 1.2.11 → 1.2.15

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.
@@ -48,8 +48,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
49
49
  }
50
50
  };
51
+ var __rest = (this && this.__rest) || function (s, e) {
52
+ var t = {};
53
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
54
+ t[p] = s[p];
55
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
56
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
57
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
58
+ t[p[i]] = s[p[i]];
59
+ }
60
+ return t;
61
+ };
62
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
63
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
64
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
65
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
66
+ r[k] = a[j];
67
+ return r;
68
+ };
51
69
  Object.defineProperty(exports, "__esModule", { value: true });
52
70
  exports.NextJs = void 0;
71
+ /* eslint-disable max-lines */
53
72
  var fs = require("fs");
54
73
  var inquirer_1 = require("inquirer");
55
74
  var _ = require("lodash");
@@ -58,10 +77,20 @@ var semver_1 = require("semver");
58
77
  var Logging_1 = require("../../Helper/Logging");
59
78
  var SentryCli_1 = require("../../Helper/SentryCli");
60
79
  var BaseIntegration_1 = require("./BaseIntegration");
61
- var MIN_NEXTJS_VERSION = '10.0.8'; // Must be a fixed version: `X.Y.Z`
80
+ var COMPATIBLE_NEXTJS_VERSIONS = '>=10.0.8 <12.0.0';
62
81
  var PROPERTIES_FILENAME = 'sentry.properties';
82
+ var SENTRYCLIRC_FILENAME = '.sentryclirc';
83
+ var GITIGNORE_FILENAME = '.gitignore';
63
84
  var CONFIG_DIR = 'configs/';
64
- var MERGEABLE_CONFIG_PREFIX = '_';
85
+ var MERGEABLE_CONFIG_INFIX = 'wizardcopy';
86
+ // for those files which can go in more than one place, the list of places they
87
+ // could go (the first one which works will be used)
88
+ var TEMPLATE_DESTINATIONS = {
89
+ '_error.js': ['pages', 'src/pages'],
90
+ 'next.config.js': ['.'],
91
+ 'sentry.server.config.js': ['.'],
92
+ 'sentry.client.config.js': ['.'],
93
+ };
65
94
  var appPackage = {};
66
95
  try {
67
96
  appPackage = require(path.join(process.cwd(), 'package.json'));
@@ -81,23 +110,26 @@ var NextJs = /** @class */ (function (_super) {
81
110
  return __awaiter(this, void 0, void 0, function () {
82
111
  var dsn, sentryCliProps, configDirectory;
83
112
  return __generator(this, function (_a) {
84
- dsn = _.get(answers, ['config', 'dsn', 'public'], null);
85
- Logging_1.nl();
86
- sentryCliProps = this._sentryCli.convertAnswersToProperties(answers);
87
- fs.writeFileSync("./" + PROPERTIES_FILENAME, this._sentryCli.dumpProperties(sentryCliProps));
88
- Logging_1.green("Successfully created sentry.properties");
89
- Logging_1.nl();
90
- configDirectory = path.join(__dirname, '..', '..', '..', 'NextJs', CONFIG_DIR);
91
- if (fs.existsSync(configDirectory)) {
92
- this._createNextConfig(configDirectory, dsn);
93
- }
94
- else {
95
- Logging_1.debug("Couldn't find " + configDirectory + ", probably because you run from src");
96
- Logging_1.nl();
113
+ switch (_a.label) {
114
+ case 0:
115
+ dsn = _.get(answers, ['config', 'dsn', 'public'], null);
116
+ Logging_1.nl();
117
+ sentryCliProps = this._sentryCli.convertAnswersToProperties(answers);
118
+ return [4 /*yield*/, this._createSentryCliConfig(sentryCliProps)];
119
+ case 1:
120
+ _a.sent();
121
+ configDirectory = path.join(__dirname, '..', '..', '..', 'NextJs', CONFIG_DIR);
122
+ if (fs.existsSync(configDirectory)) {
123
+ this._createNextConfig(configDirectory, dsn);
124
+ }
125
+ else {
126
+ Logging_1.debug("Couldn't find " + configDirectory + ", probably because you ran this from inside of `/lib` rather than `/dist`");
127
+ Logging_1.nl();
128
+ }
129
+ Logging_1.l('For more information, see https://docs.sentry.io/platforms/javascript/guides/nextjs/');
130
+ Logging_1.nl();
131
+ return [2 /*return*/, {}];
97
132
  }
98
- Logging_1.l('For more information, see https://docs.sentry.io/platforms/javascript/guides/nextjs/');
99
- Logging_1.nl();
100
- return [2 /*return*/, {}];
101
133
  });
102
134
  });
103
135
  };
@@ -112,7 +144,7 @@ var NextJs = /** @class */ (function (_super) {
112
144
  }
113
145
  Logging_1.nl();
114
146
  userAnswers = { continue: true };
115
- if (!(!this._checkDep('next', true) && !this._argv.quiet)) return [3 /*break*/, 2];
147
+ if (!(!this._checkUserNextVersion('next') && !this._argv.quiet)) return [3 /*break*/, 2];
116
148
  return [4 /*yield*/, inquirer_1.prompt({
117
149
  message: 'There were errors during your project checkup, do you still want to continue?',
118
150
  name: 'continue',
@@ -134,82 +166,170 @@ var NextJs = /** @class */ (function (_super) {
134
166
  });
135
167
  });
136
168
  };
169
+ NextJs.prototype._createSentryCliConfig = function (cliProps) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ var authToken, cliPropsToWrite, _a, _b;
172
+ return __generator(this, function (_c) {
173
+ switch (_c.label) {
174
+ case 0:
175
+ authToken = cliProps["auth/token"], cliPropsToWrite = __rest(cliProps, ['auth/token']);
176
+ if (!authToken) return [3 /*break*/, 5];
177
+ _c.label = 1;
178
+ case 1:
179
+ _c.trys.push([1, 3, , 4]);
180
+ return [4 /*yield*/, fs.promises.appendFile(SENTRYCLIRC_FILENAME, this._sentryCli.dumpConfig({ auth: { token: authToken } }))];
181
+ case 2:
182
+ _c.sent();
183
+ Logging_1.green("\u2713 Successfully added the auth token to " + SENTRYCLIRC_FILENAME);
184
+ return [3 /*break*/, 4];
185
+ case 3:
186
+ _a = _c.sent();
187
+ Logging_1.red("\u26A0 Could not add the auth token to " + SENTRYCLIRC_FILENAME + ", " +
188
+ ("please add it to identify your user account:\n" + authToken));
189
+ Logging_1.nl();
190
+ return [3 /*break*/, 4];
191
+ case 4: return [3 /*break*/, 6];
192
+ case 5:
193
+ Logging_1.red("\u26A0 Did not find an auth token, please add your token to " + SENTRYCLIRC_FILENAME);
194
+ Logging_1.l('To generate an auth token, visit https://sentry.io/settings/account/api/auth-tokens/');
195
+ Logging_1.l('To learn how to configure Sentry CLI, visit ' +
196
+ 'https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-sentry-cli');
197
+ _c.label = 6;
198
+ case 6: return [4 /*yield*/, this._addToGitignore(SENTRYCLIRC_FILENAME, "\u26A0 Could not add " + SENTRYCLIRC_FILENAME + " to " + GITIGNORE_FILENAME + ", " +
199
+ 'please add it to not commit your auth key.')];
200
+ case 7:
201
+ _c.sent();
202
+ _c.label = 8;
203
+ case 8:
204
+ _c.trys.push([8, 10, , 11]);
205
+ return [4 /*yield*/, fs.promises.writeFile("./" + PROPERTIES_FILENAME, this._sentryCli.dumpProperties(cliPropsToWrite))];
206
+ case 9:
207
+ _c.sent();
208
+ Logging_1.green("\u2713 Successfully created sentry.properties");
209
+ return [3 /*break*/, 11];
210
+ case 10:
211
+ _b = _c.sent();
212
+ Logging_1.red("\u26A0 Could not add org and project data to " + PROPERTIES_FILENAME);
213
+ Logging_1.l('See docs for a manual setup: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-sentry-cli');
214
+ return [3 /*break*/, 11];
215
+ case 11:
216
+ Logging_1.nl();
217
+ return [2 /*return*/];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ NextJs.prototype._addToGitignore = function (filepath, errorMsg) {
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ var _a;
225
+ return __generator(this, function (_b) {
226
+ switch (_b.label) {
227
+ case 0:
228
+ _b.trys.push([0, 2, , 3]);
229
+ return [4 /*yield*/, fs.promises.appendFile(GITIGNORE_FILENAME, "\n# Sentry\n" + filepath + "\n")];
230
+ case 1:
231
+ _b.sent();
232
+ Logging_1.green("\u2713 " + filepath + " added to " + GITIGNORE_FILENAME);
233
+ return [3 /*break*/, 3];
234
+ case 2:
235
+ _a = _b.sent();
236
+ Logging_1.red(errorMsg);
237
+ return [3 /*break*/, 3];
238
+ case 3: return [2 /*return*/];
239
+ }
240
+ });
241
+ });
242
+ };
137
243
  NextJs.prototype._createNextConfig = function (configDirectory, dsn) {
138
244
  var templates = fs.readdirSync(configDirectory);
139
245
  for (var _i = 0, templates_1 = templates; _i < templates_1.length; _i++) {
140
246
  var template = templates_1[_i];
141
- this._setTemplate(configDirectory, template, dsn);
247
+ this._setTemplate(configDirectory, template, TEMPLATE_DESTINATIONS[template], dsn);
142
248
  }
143
249
  Logging_1.red('⚠ Performance monitoring is enabled capturing 100% of transactions.\n' +
144
250
  ' Learn more in https://docs.sentry.io/product/performance/');
145
251
  Logging_1.nl();
146
252
  };
147
- NextJs.prototype._setTemplate = function (configDirectory, template, dsn) {
148
- var templatePath = path.join(configDirectory, template);
149
- var mergeableFile = MERGEABLE_CONFIG_PREFIX + template;
150
- if (!fs.existsSync(template)) {
151
- this._fillAndCopyTemplate(templatePath, template, dsn);
152
- }
153
- else if (!fs.existsSync(mergeableFile)) {
154
- this._fillAndCopyTemplate(templatePath, mergeableFile, dsn);
155
- Logging_1.red("File " + template + " already exists, so created " + mergeableFile + ".\n" +
156
- "Please, merge those files.");
157
- Logging_1.nl();
158
- }
159
- else {
160
- Logging_1.red("File " + template + " already exists, and " + mergeableFile + " also exists.\n" +
161
- 'Please, merge those files.');
162
- Logging_1.nl();
253
+ NextJs.prototype._setTemplate = function (configDirectory, templateFile, destinationOptions, dsn) {
254
+ var templatePath = path.join(configDirectory, templateFile);
255
+ for (var _i = 0, destinationOptions_1 = destinationOptions; _i < destinationOptions_1.length; _i++) {
256
+ var destinationDir = destinationOptions_1[_i];
257
+ if (!fs.existsSync(destinationDir)) {
258
+ continue;
259
+ }
260
+ var destinationPath = path.join(destinationDir, templateFile);
261
+ // in case the file in question already exists, we'll make a copy with
262
+ // `MERGEABLE_CONFIG_INFIX` inserted just before the extension, so as not
263
+ // to overwrite the existing file
264
+ var mergeableFilePath = path.join(destinationDir, this._spliceInPlace(templateFile.split('.'), -1, 0, MERGEABLE_CONFIG_INFIX).join('.'));
265
+ if (!fs.existsSync(destinationPath)) {
266
+ this._fillAndCopyTemplate(templatePath, destinationPath, dsn);
267
+ }
268
+ else if (!fs.existsSync(mergeableFilePath)) {
269
+ this._fillAndCopyTemplate(templatePath, mergeableFilePath, dsn);
270
+ Logging_1.red("File `" + templateFile + "` already exists, so created `" + mergeableFilePath + "`.\n" +
271
+ 'Please merge those files.');
272
+ Logging_1.nl();
273
+ }
274
+ else {
275
+ Logging_1.red("Both `" + templateFile + "` and `" + mergeableFilePath + "` already exist.\n" +
276
+ 'Please merge those files.');
277
+ Logging_1.nl();
278
+ }
279
+ return;
163
280
  }
281
+ Logging_1.red("Could not find appropriate destination for `" + templateFile + "`. Tried: " + destinationOptions + ".");
282
+ Logging_1.nl();
164
283
  };
165
284
  NextJs.prototype._fillAndCopyTemplate = function (sourcePath, targetPath, dsn) {
166
285
  var templateContent = fs.readFileSync(sourcePath).toString();
167
286
  var filledTemplate = templateContent.replace('___DSN___', dsn);
168
287
  fs.writeFileSync(targetPath, filledTemplate);
169
288
  };
170
- NextJs.prototype._checkDep = function (packageName, minVersion) {
171
- var depVersion = _.get(appPackage, ['dependencies', packageName], '0.0.0');
172
- var devDepVersion = _.get(appPackage, ['devDependencies', packageName], '0.0.0');
173
- if (!_.get(appPackage, "dependencies." + packageName, false) &&
174
- !_.get(appPackage, "devDependencies." + packageName, false)) {
175
- Logging_1.red("\u2717 " + packageName + " isn't in your dependencies");
176
- Logging_1.red(" please install it with yarn/npm");
289
+ NextJs.prototype._checkUserNextVersion = function (packageName) {
290
+ var depsVersion = _.get(appPackage, ['dependencies', packageName]);
291
+ var devDepsVersion = _.get(appPackage, ['devDependencies', packageName]);
292
+ if (!depsVersion && !devDepsVersion) {
293
+ Logging_1.red("\u2717 " + packageName + " isn't in your dependencies.");
294
+ Logging_1.red(' Please install it with yarn/npm.');
177
295
  return false;
178
296
  }
179
- else if (!this._fulfillsMinVersion(depVersion) &&
180
- !this._fulfillsMinVersion(devDepVersion)) {
181
- Logging_1.red("\u2717 Your installed version of `" + packageName + "` is not supported, >=" + MIN_NEXTJS_VERSION + " needed.");
297
+ else if (!this._fulfillsVersionRange(depsVersion) &&
298
+ !this._fulfillsVersionRange(devDepsVersion)) {
299
+ Logging_1.red("\u2717 Your `package.json` specifies a version of `" + packageName + "` outside of the compatible version range " + COMPATIBLE_NEXTJS_VERSIONS + ".\n");
182
300
  return false;
183
301
  }
184
302
  else {
185
- if (minVersion) {
186
- Logging_1.green("\u2713 " + packageName + " >= " + MIN_NEXTJS_VERSION + " is installed");
187
- }
188
- else {
189
- Logging_1.green("\u2713 " + packageName + " is installed");
190
- }
303
+ Logging_1.green("\u2713 A compatible version of `" + packageName + "` is specified in `package.json`.");
191
304
  return true;
192
305
  }
193
306
  };
194
- NextJs.prototype._fulfillsMinVersion = function (version) {
195
- // The latest version, which at the moment is greater than the minimum
196
- // version, shouldn't be a blocker in the wizard.
307
+ NextJs.prototype._fulfillsVersionRange = function (version) {
308
+ // The latest version is currently 12.x, which is not yet supported.
197
309
  if (version === 'latest') {
198
- return true;
310
+ return false;
199
311
  }
200
- var cleanedVersion = semver_1.clean(version);
201
- if (cleanedVersion) {
202
- // gte(x, y) : true if x >= y
203
- return semver_1.gte(cleanedVersion, MIN_NEXTJS_VERSION);
312
+ var cleanedUserVersion, isRange;
313
+ if (semver_1.valid(version)) {
314
+ cleanedUserVersion = semver_1.valid(version);
315
+ isRange = false;
204
316
  }
205
- var minVersionRange = ">=" + MIN_NEXTJS_VERSION;
206
- var userVersionRange = semver_1.validRange(version);
207
- var minUserVersion = semver_1.minVersion(userVersionRange);
208
- if (minUserVersion == null) {
209
- // This should never happen
210
- return false;
317
+ else if (semver_1.validRange(version)) {
318
+ cleanedUserVersion = semver_1.validRange(version);
319
+ isRange = true;
320
+ }
321
+ return (!!cleanedUserVersion &&
322
+ (isRange
323
+ ? semver_1.subset(cleanedUserVersion, COMPATIBLE_NEXTJS_VERSIONS)
324
+ : semver_1.satisfies(cleanedUserVersion, COMPATIBLE_NEXTJS_VERSIONS)));
325
+ };
326
+ NextJs.prototype._spliceInPlace = function (arr, start, deleteCount) {
327
+ var inserts = [];
328
+ for (var _i = 3; _i < arguments.length; _i++) {
329
+ inserts[_i - 3] = arguments[_i];
211
330
  }
212
- return semver_1.satisfies(minUserVersion, minVersionRange);
331
+ arr.splice.apply(arr, __spreadArrays([start, deleteCount], inserts));
332
+ return arr;
213
333
  };
214
334
  return NextJs;
215
335
  }(BaseIntegration_1.BaseIntegration));
@@ -1 +1 @@
1
- {"version":3,"file":"NextJs.js","sourceRoot":"","sources":["../../../../lib/Steps/Integrations/NextJs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,qCAA2C;AAC3C,0BAA4B;AAC5B,2BAA6B;AAC7B,iCAAuE;AAGvE,gDAAgE;AAChE,oDAAmD;AACnD,qDAAoD;AAEpD,IAAM,kBAAkB,GAAG,QAAQ,CAAC,CAAC,mCAAmC;AACxE,IAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAChD,IAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,IAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,IAAI,UAAU,GAAQ,EAAE,CAAC;AAEzB,IAAI;IACF,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC;CAChE;AAAC,WAAM;IACN,6BAA6B;CAC9B;AAED;IAA4B,0BAAe;IAGzC,gBAAsB,KAAW;QAAjC,YACE,kBAAM,KAAK,CAAC,SAEb;QAHqB,WAAK,GAAL,KAAK,CAAM;QAE/B,K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C;YACzC,OAAO,KAAK,CAAC;SACd;aAAM,IACL,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC;YACrC,CAAC,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,EACxC;YACA,aAAG,CACD,uCAAiC,WAAW,8BAA0B,kBAAkB,aAAU,CACnG,CAAC;YACF,OAAO,KAAK,CAAC;SACd;aAAM;YACL,IAAI,UAAU,EAAE;gBACd,eAAK,CAAC,YAAK,WAAW,YAAO,kBAAkB,kBAAe,CAAC,CAAC;aACjE;iBAAM;gBACL,eAAK,CAAC,YAAK,WAAW,kBAAe,CAAC,CAAC;aACxC;YACD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAEO,oCAAmB,GAA3B,UAA4B,OAAe;QACzC,sEAAsE;QACtE,iDAAiD;QACjD,IAAI,OAAO,KAAK,QAAQ,EAAE;YACxB,OAAO,IAAI,CAAC;SACb;QAED,IAAM,cAAc,GAAG,cAAK,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,cAAc,EAAE;YAClB,6BAA6B;YAC7B,OAAO,YAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;SAChD;QAED,IAAM,eAAe,GAAG,OAAK,kBAAoB,CAAC;QAClD,IAAM,gBAAgB,GAAG,mBAAU,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAM,cAAc,GAAG,mBAAU,CAAC,gBAAgB,CAAC,CAAC;QACpD,IAAI,cAAc,IAAI,IAAI,EAAE;YAC1B,2BAA2B;YAC3B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,kBAAS,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IACpD,CAAC;IACH,aAAC;AAAD,CAAC,AArLD,CAA4B,iCAAe,GAqL1C;AArLY,wBAAM","sourcesContent":["import * as fs from 'fs';\nimport { Answers, prompt } from 'inquirer';\nimport * as _ from 'lodash';\nimport * as path from 'path';\nimport { clean, gte, minVersion, satisfies, validRange } from 'semver';\n\nimport { Args } from '../../Constants';\nimport { debug, green, l, nl, red } from '../../Helper/Logging';\nimport { SentryCli } from '../../Helper/SentryCli';\nimport { BaseIntegration } from './BaseIntegration';\n\nconst MIN_NEXTJS_VERSION = '10.0.8'; // Must be a fixed version: `X.Y.Z`\nconst PROPERTIES_FILENAME = 'sentry.properties';\nconst CONFIG_DIR = 'configs/';\nconst MERGEABLE_CONFIG_PREFIX = '_';\n\nlet appPackage: any = {};\n\ntry {\n appPackage = require(path.join(process.cwd(), 'package.json'));\n} catch {\n // We don't need to have this\n}\n\nexport class NextJs extends BaseIntegration {\n protected _sentryCli: SentryCli;\n\n constructor(protected _argv: Args) {\n super(_argv);\n this._sentryCli = new SentryCli(this._argv);\n }\n\n public async emit(answers: Answers): Promise<Answers> {\n const dsn = _.get(answers, ['config', 'dsn', 'public'], null);\n nl();\n\n const sentryCliProps = this._sentryCli.convertAnswersToProperties(answers);\n fs.writeFileSync(\n `./${PROPERTIES_FILENAME}`,\n this._sentryCli.dumpProperties(sentryCliProps),\n );\n green(`Successfully created sentry.properties`);\n nl();\n\n const configDirectory = path.join(\n __dirname,\n '..',\n '..',\n '..',\n 'NextJs',\n CONFIG_DIR,\n );\n\n if (fs.existsSync(configDirectory)) {\n this._createNextConfig(configDirectory, dsn);\n } else {\n debug(\n `Couldn't find ${configDirectory}, probably because you run from src`,\n );\n nl();\n }\n\n l(\n 'For more information, see https://docs.sentry.io/platforms/javascript/guides/nextjs/',\n );\n nl();\n\n return {};\n }\n\n public async shouldConfigure(_answers: Answers): Promise<Answers> {\n if (this._shouldConfigure) {\n return this._shouldConfigure;\n }\n\n nl();\n\n let userAnswers: Answers = { continue: true };\n if (!this._checkDep('next', true) && !this._argv.quiet) {\n userAnswers = await prompt({\n message:\n 'There were errors during your project checkup, do you still want to continue?',\n name: 'continue',\n default: false,\n type: 'confirm',\n });\n }\n\n nl();\n\n if (!userAnswers['continue']) {\n throw new Error('Please install the required dependencies to continue.');\n }\n\n this._shouldConfigure = Promise.resolve({ nextjs: true });\n // eslint-disable-next-line @typescript-eslint/unbound-method\n return this.shouldConfigure;\n }\n\n private _createNextConfig(configDirectory: string, dsn: any): void {\n const templates = fs.readdirSync(configDirectory);\n for (const template of templates) {\n this._setTemplate(configDirectory, template, dsn);\n }\n red(\n '⚠ Performance monitoring is enabled capturing 100% of transactions.\\n' +\n ' Learn more in https://docs.sentry.io/product/performance/',\n );\n nl();\n }\n\n private _setTemplate(\n configDirectory: string,\n template: string,\n dsn: string,\n ): void {\n const templatePath = path.join(configDirectory, template);\n const mergeableFile = MERGEABLE_CONFIG_PREFIX + template;\n if (!fs.existsSync(template)) {\n this._fillAndCopyTemplate(templatePath, template, dsn);\n } else if (!fs.existsSync(mergeableFile)) {\n this._fillAndCopyTemplate(templatePath, mergeableFile, dsn);\n red(\n `File ${template} already exists, so created ${mergeableFile}.\\n` +\n `Please, merge those files.`,\n );\n nl();\n } else {\n red(\n `File ${template} already exists, and ${mergeableFile} also exists.\\n` +\n 'Please, merge those files.',\n );\n nl();\n }\n }\n\n private _fillAndCopyTemplate(\n sourcePath: string,\n targetPath: string,\n dsn: string,\n ): void {\n const templateContent = fs.readFileSync(sourcePath).toString();\n const filledTemplate = templateContent.replace('___DSN___', dsn);\n fs.writeFileSync(targetPath, filledTemplate);\n }\n\n private _checkDep(packageName: string, minVersion?: boolean): boolean {\n const depVersion = _.get(\n appPackage,\n ['dependencies', packageName],\n '0.0.0',\n );\n const devDepVersion = _.get(\n appPackage,\n ['devDependencies', packageName],\n '0.0.0',\n );\n\n if (\n !_.get(appPackage, `dependencies.${packageName}`, false) &&\n !_.get(appPackage, `devDependencies.${packageName}`, false)\n ) {\n red(`✗ ${packageName} isn't in your dependencies`);\n red(` please install it with yarn/npm`);\n return false;\n } else if (\n !this._fulfillsMinVersion(depVersion) &&\n !this._fulfillsMinVersion(devDepVersion)\n ) {\n red(\n `✗ Your installed version of \\`${packageName}\\` is not supported, >=${MIN_NEXTJS_VERSION} needed.`,\n );\n return false;\n } else {\n if (minVersion) {\n green(`✓ ${packageName} >= ${MIN_NEXTJS_VERSION} is installed`);\n } else {\n green(`✓ ${packageName} is installed`);\n }\n return true;\n }\n }\n\n private _fulfillsMinVersion(version: string): boolean {\n // The latest version, which at the moment is greater than the minimum\n // version, shouldn't be a blocker in the wizard.\n if (version === 'latest') {\n return true;\n }\n\n const cleanedVersion = clean(version);\n if (cleanedVersion) {\n // gte(x, y) : true if x >= y\n return gte(cleanedVersion, MIN_NEXTJS_VERSION);\n }\n\n const minVersionRange = `>=${MIN_NEXTJS_VERSION}`;\n const userVersionRange = validRange(version);\n const minUserVersion = minVersion(userVersionRange);\n if (minUserVersion == null) {\n // This should never happen\n return false;\n }\n return satisfies(minUserVersion, minVersionRange);\n }\n}\n"]}
1
+ {"version":3,"file":"NextJs.js","sourceRoot":"","sources":["../../../../lib/Steps/Integrations/NextJs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,uBAAyB;AACzB,qCAA2C;AAC3C,0BAA4B;AAC5B,2BAA6B;AAC7B,iCAA8D;AAG9D,gDAAgE;AAChE,oDAAmE;AACnE,qDAAoD;AAEpD,IAAM,0BAA0B,GAAG,kBAAkB,CAAC;AACtD,IAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAChD,IAAM,oBAAoB,GAAG,cAAc,CAAC;AAC5C,IAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,IAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,IAAM,sBAAsB,GAAG,YAAY,CAAC;AAE5C,+EAA+E;AAC/E,oDAAoD;AACpD,IAAM,qBAAqB,GAAgC;IACzD,WAAW,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC;IACnC,gBAAgB,EAAE,CAAC,GAAG,CAAC;IACvB,yBAAyB,EAAE,CAAC,GAAG,CAAC;IAChC,yBAAyB,EAAE,CAAC,GAAG,CAAC;CACjC,CAAC;AA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EAAoE;QACpE,IAAI,OAAO,KAAK,QAAQ,EAAE;YACxB,OAAO,KAAK,CAAC;SACd;QAED,IAAI,kBAAkB,EAAE,OAAO,CAAC;QAEhC,IAAI,cAAK,CAAC,OAAO,CAAC,EAAE;YAClB,kBAAkB,GAAG,cAAK,CAAC,OAAO,CAAC,CAAC;YACpC,OAAO,GAAG,KAAK,CAAC;SACjB;aAAM,IAAI,mBAAU,CAAC,OAAO,CAAC,EAAE;YAC9B,kBAAkB,GAAG,mBAAU,CAAC,OAAO,CAAC,CAAC;YACzC,OAAO,GAAG,IAAI,CAAC;SAChB;QAED,OAAO,CACL,CAAC,CAAC,kBAAkB;YACpB,CAAC,OAAO;gBACN,CAAC,CAAC,eAAM,CAAC,kBAAkB,EAAE,0BAA0B,CAAC;gBACxD,CAAC,CAAC,kBAAS,CAAC,kBAAkB,EAAE,0BAA0B,CAAC,CAAC,CAC/D,CAAC;IACJ,CAAC;IAEO,+BAAc,GAAtB,UACE,GAAe,EACf,KAAa,EACb,WAAmB;QACnB,iBAAiB;aAAjB,UAAiB,EAAjB,qBAAiB,EAAjB,IAAiB;YAAjB,gCAAiB;;QAEjB,GAAG,CAAC,MAAM,OAAV,GAAG,kBAAQ,KAAK,EAAE,WAAW,GAAK,OAAO,GAAE;QAC3C,OAAO,GAAG,CAAC;IACb,CAAC;IACH,aAAC;AAAD,CAAC,AArSD,CAA4B,iCAAe,GAqS1C;AArSY,wBAAM","sourcesContent":["/* eslint-disable max-lines */\nimport * as fs from 'fs';\nimport { Answers, prompt } from 'inquirer';\nimport * as _ from 'lodash';\nimport * as path from 'path';\nimport { satisfies, subset, valid, validRange } from 'semver';\n\nimport { Args } from '../../Constants';\nimport { debug, green, l, nl, red } from '../../Helper/Logging';\nimport { SentryCli, SentryCliProps } from '../../Helper/SentryCli';\nimport { BaseIntegration } from './BaseIntegration';\n\nconst COMPATIBLE_NEXTJS_VERSIONS = '>=10.0.8 <12.0.0';\nconst PROPERTIES_FILENAME = 'sentry.properties';\nconst SENTRYCLIRC_FILENAME = '.sentryclirc';\nconst GITIGNORE_FILENAME = '.gitignore';\nconst CONFIG_DIR = 'configs/';\nconst MERGEABLE_CONFIG_INFIX = 'wizardcopy';\n\n// for those files which can go in more than one place, the list of places they\n// could go (the first one which works will be used)\nconst TEMPLATE_DESTINATIONS: { [key: string]: string[] } = {\n '_error.js': ['pages', 'src/pages'],\n 'next.config.js': ['.'],\n 'sentry.server.config.js': ['.'],\n 'sentry.client.config.js': ['.'],\n};\n\nlet appPackage: any = {};\n\ntry {\n appPackage = require(path.join(process.cwd(), 'package.json'));\n} catch {\n // We don't need to have this\n}\n\nexport class NextJs extends BaseIntegration {\n protected _sentryCli: SentryCli;\n\n constructor(protected _argv: Args) {\n super(_argv);\n this._sentryCli = new SentryCli(this._argv);\n }\n\n public async emit(answers: Answers): Promise<Answers> {\n const dsn = _.get(answers, ['config', 'dsn', 'public'], null);\n nl();\n\n const sentryCliProps = this._sentryCli.convertAnswersToProperties(answers);\n await this._createSentryCliConfig(sentryCliProps);\n\n const configDirectory = path.join(\n __dirname,\n '..',\n '..',\n '..',\n 'NextJs',\n CONFIG_DIR,\n );\n\n if (fs.existsSync(configDirectory)) {\n this._createNextConfig(configDirectory, dsn);\n } else {\n debug(\n `Couldn't find ${configDirectory}, probably because you ran this from inside of \\`/lib\\` rather than \\`/dist\\``,\n );\n nl();\n }\n\n l(\n 'For more information, see https://docs.sentry.io/platforms/javascript/guides/nextjs/',\n );\n nl();\n\n return {};\n }\n\n public async shouldConfigure(_answers: Answers): Promise<Answers> {\n if (this._shouldConfigure) {\n return this._shouldConfigure;\n }\n\n nl();\n\n let userAnswers: Answers = { continue: true };\n if (!this._checkUserNextVersion('next') && !this._argv.quiet) {\n userAnswers = await prompt({\n message:\n 'There were errors during your project checkup, do you still want to continue?',\n name: 'continue',\n default: false,\n type: 'confirm',\n });\n }\n\n nl();\n\n if (!userAnswers['continue']) {\n throw new Error('Please install the required dependencies to continue.');\n }\n\n this._shouldConfigure = Promise.resolve({ nextjs: true });\n // eslint-disable-next-line @typescript-eslint/unbound-method\n return this.shouldConfigure;\n }\n\n private async _createSentryCliConfig(\n cliProps: SentryCliProps,\n ): Promise<void> {\n const { 'auth/token': authToken, ...cliPropsToWrite } = cliProps;\n\n /**\n * To not commit the auth token to the VCS, instead of adding it to the\n * properties file (like the rest of props), it's added to the Sentry CLI\n * config, which is added to the gitignore. This way makes the properties\n * file safe to commit without exposing any auth tokens.\n */\n if (authToken) {\n try {\n await fs.promises.appendFile(\n SENTRYCLIRC_FILENAME,\n this._sentryCli.dumpConfig({ auth: { token: authToken } }),\n );\n green(`✓ Successfully added the auth token to ${SENTRYCLIRC_FILENAME}`);\n } catch {\n red(\n `⚠ Could not add the auth token to ${SENTRYCLIRC_FILENAME}, ` +\n `please add it to identify your user account:\\n${authToken}`,\n );\n nl();\n }\n } else {\n red(\n `⚠ Did not find an auth token, please add your token to ${SENTRYCLIRC_FILENAME}`,\n );\n l(\n 'To generate an auth token, visit https://sentry.io/settings/account/api/auth-tokens/',\n );\n l(\n 'To learn how to configure Sentry CLI, visit ' +\n 'https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-sentry-cli',\n );\n }\n\n await this._addToGitignore(\n SENTRYCLIRC_FILENAME,\n `⚠ Could not add ${SENTRYCLIRC_FILENAME} to ${GITIGNORE_FILENAME}, ` +\n 'please add it to not commit your auth key.',\n );\n\n try {\n await fs.promises.writeFile(\n `./${PROPERTIES_FILENAME}`,\n this._sentryCli.dumpProperties(cliPropsToWrite),\n );\n green(`✓ Successfully created sentry.properties`);\n } catch {\n red(`⚠ Could not add org and project data to ${PROPERTIES_FILENAME}`);\n l(\n 'See docs for a manual setup: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-sentry-cli',\n );\n }\n nl();\n }\n\n private async _addToGitignore(\n filepath: string,\n errorMsg: string,\n ): Promise<void> {\n /**\n * Don't check whether the given file is ignored because:\n * 1. It's tricky to check it without git.\n * 2. Git might not be installed or accessible.\n * 3. It's convenient to use a module to interact with git, but it would\n * increase the size x2 approximately. Docs say to run the Wizard without\n * installing it, and duplicating the size would slow the set-up down.\n * 4. The Wizard is meant to be run once.\n * 5. A message is logged informing users it's been added to the gitignore.\n * 6. It will be added to the gitignore as many times as it runs - not a big\n * deal.\n * 7. It's straightforward to remove it from the gitignore.\n */\n try {\n await fs.promises.appendFile(\n GITIGNORE_FILENAME,\n `\\n# Sentry\\n${filepath}\\n`,\n );\n green(`✓ ${filepath} added to ${GITIGNORE_FILENAME}`);\n } catch {\n red(errorMsg);\n }\n }\n\n private _createNextConfig(configDirectory: string, dsn: any): void {\n const templates = fs.readdirSync(configDirectory);\n for (const template of templates) {\n this._setTemplate(\n configDirectory,\n template,\n TEMPLATE_DESTINATIONS[template],\n dsn,\n );\n }\n red(\n '⚠ Performance monitoring is enabled capturing 100% of transactions.\\n' +\n ' Learn more in https://docs.sentry.io/product/performance/',\n );\n nl();\n }\n\n private _setTemplate(\n configDirectory: string,\n templateFile: string,\n destinationOptions: string[],\n dsn: string,\n ): void {\n const templatePath = path.join(configDirectory, templateFile);\n\n for (const destinationDir of destinationOptions) {\n if (!fs.existsSync(destinationDir)) {\n continue;\n }\n\n const destinationPath = path.join(destinationDir, templateFile);\n // in case the file in question already exists, we'll make a copy with\n // `MERGEABLE_CONFIG_INFIX` inserted just before the extension, so as not\n // to overwrite the existing file\n const mergeableFilePath = path.join(\n destinationDir,\n this._spliceInPlace(\n templateFile.split('.'),\n -1,\n 0,\n MERGEABLE_CONFIG_INFIX,\n ).join('.'),\n );\n\n if (!fs.existsSync(destinationPath)) {\n this._fillAndCopyTemplate(templatePath, destinationPath, dsn);\n } else if (!fs.existsSync(mergeableFilePath)) {\n this._fillAndCopyTemplate(templatePath, mergeableFilePath, dsn);\n red(\n `File \\`${templateFile}\\` already exists, so created \\`${mergeableFilePath}\\`.\\n` +\n 'Please merge those files.',\n );\n nl();\n } else {\n red(\n `Both \\`${templateFile}\\` and \\`${mergeableFilePath}\\` already exist.\\n` +\n 'Please merge those files.',\n );\n nl();\n }\n return;\n }\n\n red(\n `Could not find appropriate destination for \\`${templateFile}\\`. Tried: ${destinationOptions}.`,\n );\n nl();\n }\n\n private _fillAndCopyTemplate(\n sourcePath: string,\n targetPath: string,\n dsn: string,\n ): void {\n const templateContent = fs.readFileSync(sourcePath).toString();\n const filledTemplate = templateContent.replace('___DSN___', dsn);\n fs.writeFileSync(targetPath, filledTemplate);\n }\n\n private _checkUserNextVersion(packageName: string): boolean {\n const depsVersion = _.get(appPackage, ['dependencies', packageName]);\n const devDepsVersion = _.get(appPackage, ['devDependencies', packageName]);\n\n if (!depsVersion && !devDepsVersion) {\n red(`✗ ${packageName} isn't in your dependencies.`);\n red(' Please install it with yarn/npm.');\n return false;\n } else if (\n !this._fulfillsVersionRange(depsVersion) &&\n !this._fulfillsVersionRange(devDepsVersion)\n ) {\n red(\n `✗ Your \\`package.json\\` specifies a version of \\`${packageName}\\` outside of the compatible version range ${COMPATIBLE_NEXTJS_VERSIONS}.\\n`,\n );\n return false;\n } else {\n green(\n `✓ A compatible version of \\`${packageName}\\` is specified in \\`package.json\\`.`,\n );\n return true;\n }\n }\n\n private _fulfillsVersionRange(version: string): boolean {\n // The latest version is currently 12.x, which is not yet supported.\n if (version === 'latest') {\n return false;\n }\n\n let cleanedUserVersion, isRange;\n\n if (valid(version)) {\n cleanedUserVersion = valid(version);\n isRange = false;\n } else if (validRange(version)) {\n cleanedUserVersion = validRange(version);\n isRange = true;\n }\n\n return (\n !!cleanedUserVersion &&\n (isRange\n ? subset(cleanedUserVersion, COMPATIBLE_NEXTJS_VERSIONS)\n : satisfies(cleanedUserVersion, COMPATIBLE_NEXTJS_VERSIONS))\n );\n }\n\n private _spliceInPlace(\n arr: Array<any>,\n start: number,\n deleteCount: number,\n ...inserts: any[]\n ): Array<any> {\n arr.splice(start, deleteCount, ...inserts);\n return arr;\n }\n}\n"]}
@@ -8,6 +8,8 @@ export interface SentryCliProps {
8
8
  [s: string]: string;
9
9
  }
10
10
 
11
+ type SentryCliConfig = Record<string, SentryCliProps>;
12
+
11
13
  export class SentryCli {
12
14
  // eslint-disable-next-line @typescript-eslint/typedef
13
15
  private _resolve = require.resolve;
@@ -35,6 +37,7 @@ export class SentryCli {
35
37
  return props;
36
38
  }
37
39
 
40
+ /** Create the contents of a `sentry.properties` file */
38
41
  public dumpProperties(props: SentryCliProps): string {
39
42
  const rv = [];
40
43
  for (let key in props) {
@@ -43,6 +46,7 @@ export class SentryCli {
43
46
  const value = props[key];
44
47
  key = key.replace(/\//g, '.');
45
48
  if (value === undefined || value === null) {
49
+ // comment that property out since it has no value
46
50
  rv.push(`#${key}=`);
47
51
  } else {
48
52
  rv.push(`${key}=${value}`);
@@ -52,4 +56,17 @@ export class SentryCli {
52
56
  // eslint-disable-next-line prefer-template
53
57
  return rv.join('\n') + '\n';
54
58
  }
59
+
60
+ public dumpConfig(config: SentryCliConfig): string {
61
+ const dumpedSections: string[] = [];
62
+ for (const sectionName in config) {
63
+ // eslint-disable-next-line no-prototype-builtins
64
+ if (config.hasOwnProperty(sectionName)) {
65
+ const props = this.dumpProperties(config[sectionName]);
66
+ const section = `[${sectionName}]\n${props}`;
67
+ dumpedSections.push(section);
68
+ }
69
+ }
70
+ return dumpedSections.join('\n');
71
+ }
55
72
  }
@@ -21,7 +21,7 @@ export abstract class BaseIntegration extends BaseStep {
21
21
  /**
22
22
  * This can be used for example for platform:boolean to determine
23
23
  * if we should configure iOS/Android.
24
- * Basically this will be merged into answers so it can be check by a later step.
24
+ * Basically this will be merged into answers so it can be checked by a later step.
25
25
  */
26
26
  public async shouldConfigure(_answers: Answers): Promise<Answers> {
27
27
  if (this._shouldConfigure) {
@@ -34,7 +34,10 @@ export abstract class BaseIntegration extends BaseStep {
34
34
  public async shouldEmit(_answers: Answers): Promise<boolean> {
35
35
  return (
36
36
  _.keys(
37
- _.pickBy(await this.shouldConfigure(_answers), (active: boolean) => active),
37
+ _.pickBy(
38
+ await this.shouldConfigure(_answers),
39
+ (active: boolean) => active,
40
+ ),
38
41
  ).length > 0
39
42
  );
40
43
  }