@sentry/wizard 3.11.0 → 3.13.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 (91) hide show
  1. package/CHANGELOG.md +20 -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 +1 -1
  5. package/dist/src/android/android-wizard.js +14 -4
  6. package/dist/src/android/android-wizard.js.map +1 -1
  7. package/dist/src/android/code-tools.d.ts +8 -0
  8. package/dist/src/android/code-tools.js +20 -8
  9. package/dist/src/android/code-tools.js.map +1 -1
  10. package/dist/src/android/gradle.js +6 -1
  11. package/dist/src/android/gradle.js.map +1 -1
  12. package/dist/src/nextjs/nextjs-wizard.js +5 -2
  13. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  14. package/dist/src/nextjs/templates.d.ts +1 -1
  15. package/dist/src/nextjs/templates.js +2 -2
  16. package/dist/src/nextjs/templates.js.map +1 -1
  17. package/dist/src/remix/remix-wizard.js +8 -4
  18. package/dist/src/remix/remix-wizard.js.map +1 -1
  19. package/dist/src/remix/sdk-setup.d.ts +5 -1
  20. package/dist/src/remix/sdk-setup.js +3 -2
  21. package/dist/src/remix/sdk-setup.js.map +1 -1
  22. package/dist/src/sourcemaps/tools/sentry-cli.d.ts +9 -0
  23. package/dist/src/sourcemaps/tools/sentry-cli.js +26 -22
  24. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  25. package/dist/src/sourcemaps/tools/tsc.d.ts +6 -0
  26. package/dist/src/sourcemaps/tools/tsc.js +98 -17
  27. package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
  28. package/dist/src/sourcemaps/tools/vite.js +39 -124
  29. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  30. package/dist/src/sourcemaps/tools/webpack.d.ts +6 -1
  31. package/dist/src/sourcemaps/tools/webpack.js +280 -25
  32. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  33. package/dist/src/sveltekit/sdk-setup.js +123 -49
  34. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  35. package/dist/src/sveltekit/sveltekit-wizard.d.ts +1 -0
  36. package/dist/src/sveltekit/sveltekit-wizard.js +119 -44
  37. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  38. package/dist/src/sveltekit/utils.d.ts +2 -0
  39. package/dist/src/sveltekit/utils.js +48 -0
  40. package/dist/src/sveltekit/utils.js.map +1 -0
  41. package/dist/src/utils/ast-utils.d.ts +77 -3
  42. package/dist/src/utils/ast-utils.js +172 -6
  43. package/dist/src/utils/ast-utils.js.map +1 -1
  44. package/dist/src/utils/clack-utils.d.ts +85 -1
  45. package/dist/src/utils/clack-utils.js +214 -51
  46. package/dist/src/utils/clack-utils.js.map +1 -1
  47. package/dist/src/utils/package-manager.d.ts +5 -0
  48. package/dist/src/utils/package-manager.js +11 -7
  49. package/dist/src/utils/package-manager.js.map +1 -1
  50. package/dist/test/android/code-tools.test.d.ts +1 -0
  51. package/dist/test/android/code-tools.test.js +34 -0
  52. package/dist/test/android/code-tools.test.js.map +1 -0
  53. package/dist/test/sourcemaps/tools/sentry-cli.test.d.ts +1 -0
  54. package/dist/test/sourcemaps/tools/sentry-cli.test.js +112 -0
  55. package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -0
  56. package/dist/test/sourcemaps/tools/tsc.test.d.ts +1 -0
  57. package/dist/test/sourcemaps/tools/tsc.test.js +121 -0
  58. package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -0
  59. package/dist/test/sourcemaps/tools/webpack.test.d.ts +1 -0
  60. package/dist/test/sourcemaps/tools/webpack.test.js +179 -0
  61. package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -0
  62. package/dist/test/utils/ast-utils.test.js +181 -15
  63. package/dist/test/utils/ast-utils.test.js.map +1 -1
  64. package/dist/test/utils/clack-utils.test.d.ts +1 -0
  65. package/dist/test/utils/clack-utils.test.js +200 -0
  66. package/dist/test/utils/clack-utils.test.js.map +1 -0
  67. package/lib/Steps/ChooseIntegration.ts +1 -0
  68. package/package.json +1 -1
  69. package/src/android/android-wizard.ts +16 -5
  70. package/src/android/code-tools.ts +21 -7
  71. package/src/android/gradle.ts +6 -1
  72. package/src/nextjs/nextjs-wizard.ts +15 -3
  73. package/src/nextjs/templates.ts +3 -2
  74. package/src/remix/remix-wizard.ts +8 -11
  75. package/src/remix/sdk-setup.ts +8 -2
  76. package/src/sourcemaps/tools/sentry-cli.ts +16 -9
  77. package/src/sourcemaps/tools/tsc.ts +133 -28
  78. package/src/sourcemaps/tools/vite.ts +37 -127
  79. package/src/sourcemaps/tools/webpack.ts +343 -27
  80. package/src/sveltekit/sdk-setup.ts +115 -39
  81. package/src/sveltekit/sveltekit-wizard.ts +93 -25
  82. package/src/sveltekit/utils.ts +50 -0
  83. package/src/utils/ast-utils.ts +203 -7
  84. package/src/utils/clack-utils.ts +211 -44
  85. package/src/utils/package-manager.ts +12 -6
  86. package/test/android/code-tools.test.ts +49 -0
  87. package/test/sourcemaps/tools/sentry-cli.test.ts +51 -0
  88. package/test/sourcemaps/tools/tsc.test.ts +181 -0
  89. package/test/sourcemaps/tools/webpack.test.ts +303 -0
  90. package/test/utils/ast-utils.test.ts +240 -20
  91. package/test/utils/clack-utils.test.ts +142 -0
@@ -58,53 +58,308 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
58
58
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
59
  }
60
60
  };
61
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
62
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
63
+ if (ar || !(i in from)) {
64
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
65
+ ar[i] = from[i];
66
+ }
67
+ }
68
+ return to.concat(ar || Array.prototype.slice.call(from));
69
+ };
61
70
  var __importDefault = (this && this.__importDefault) || function (mod) {
62
71
  return (mod && mod.__esModule) ? mod : { "default": mod };
63
72
  };
64
73
  Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.configureWebPackPlugin = void 0;
74
+ exports.modifyWebpackConfig = exports.configureWebPackPlugin = void 0;
75
+ var path = __importStar(require("path"));
76
+ var fs = __importStar(require("fs"));
66
77
  // @ts-ignore - clack is ESM and TS complains about that. It works though
67
- var prompts_1 = __importStar(require("@clack/prompts"));
78
+ var clack = __importStar(require("@clack/prompts"));
68
79
  var chalk_1 = __importDefault(require("chalk"));
80
+ var recast = __importStar(require("recast"));
81
+ var Sentry = __importStar(require("@sentry/node"));
69
82
  var clack_utils_1 = require("../../utils/clack-utils");
70
83
  var package_json_1 = require("../../utils/package-json");
71
- var getCodeSnippet = function (options) {
72
- return chalk_1.default.gray("\n".concat(chalk_1.default.greenBright('const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");'), "\n\nmodule.exports = {\n // ... other config options\n ").concat(chalk_1.default.greenBright('devtool: "source-map", // Source map generation must be turned on'), "\n plugins: [\n ").concat(chalk_1.default.greenBright("sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"".concat(options.orgSlug, "\",\n project: \"").concat(options.projectSlug, "\",").concat(options.selfHosted ? "\n url: \"".concat(options.url, "\",") : '', " \n })")), ",\n ],\n};\n"));
84
+ var ast_utils_1 = require("../../utils/ast-utils");
85
+ var debug_1 = require("../../utils/debug");
86
+ var getCodeSnippet = function (options, colors) {
87
+ return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus) {
88
+ return unchanged("".concat(plus('const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");'), "\n\nmodule.exports = {\n // ... other options\n ").concat(plus('devtool: "source-map", // Source map generation must be turned on'), "\n plugins: [\n // Put the Sentry Webpack plugin after all other plugins\n ").concat(plus("sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"".concat(options.orgSlug, "\",\n project: \"").concat(options.projectSlug, "\",").concat(options.selfHosted ? "\n url: \"".concat(options.url, "\",") : '', "\n }),")), "\n ],\n}"));
89
+ });
73
90
  };
74
91
  var configureWebPackPlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
75
- var _a, _b, _c;
76
- var _d;
77
- return __generator(this, function (_e) {
78
- switch (_e.label) {
92
+ var _a, _b, _c, webpackConfigPath, _d, successfullyAdded;
93
+ var _e;
94
+ var _f;
95
+ return __generator(this, function (_g) {
96
+ switch (_g.label) {
79
97
  case 0:
80
98
  _a = clack_utils_1.installPackage;
81
- _d = {
99
+ _e = {
82
100
  packageName: '@sentry/webpack-plugin'
83
101
  };
84
102
  _b = package_json_1.hasPackageInstalled;
85
103
  _c = ['@sentry/webpack-plugin'];
86
104
  return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
87
- case 1: return [4 /*yield*/, _a.apply(void 0, [(_d.alreadyInstalled = _b.apply(void 0, _c.concat([_e.sent()])),
88
- _d)])];
105
+ case 1: return [4 /*yield*/, _a.apply(void 0, [(_e.alreadyInstalled = _b.apply(void 0, _c.concat([_g.sent()])),
106
+ _e)])];
89
107
  case 2:
90
- _e.sent();
91
- prompts_1.default.log.step("Add the following code to your ".concat(chalk_1.default.bold('webpack.config.js'), " file:"));
92
- // Intentially logging directly to console here so that the code can be copied/pasted directly
93
- // eslint-disable-next-line no-console
94
- console.log(getCodeSnippet(options));
95
- return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)((0, prompts_1.select)({
96
- message: 'Did you copy the snippet above?',
97
- options: [{ label: 'Yes, continue!', value: true }],
98
- initialValue: true,
99
- }))];
100
- case 3:
101
- _e.sent();
102
- return [4 /*yield*/, (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken)];
108
+ _g.sent();
109
+ if (!((_f = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'webpack.config'))) !== null && _f !== void 0)) return [3 /*break*/, 3];
110
+ _d = _f;
111
+ return [3 /*break*/, 5];
112
+ case 3: return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('Webpack', 'webpack.config.js')];
103
113
  case 4:
104
- _e.sent();
114
+ _d = (_g.sent());
115
+ _g.label = 5;
116
+ case 5:
117
+ webpackConfigPath = _d;
118
+ successfullyAdded = false;
119
+ if (!webpackConfigPath) return [3 /*break*/, 7];
120
+ return [4 /*yield*/, modifyWebpackConfig(webpackConfigPath, options)];
121
+ case 6:
122
+ successfullyAdded = _g.sent();
123
+ return [3 /*break*/, 9];
124
+ case 7: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'webpack.config.js'), getCodeSnippet(options, false), 'More information about Webpack configs: https://vitejs.dev/config/')];
125
+ case 8:
126
+ successfullyAdded = _g.sent();
127
+ Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
128
+ _g.label = 9;
129
+ case 9:
130
+ if (!successfullyAdded) return [3 /*break*/, 10];
131
+ clack.log.info("We recommend checking the ".concat(webpackConfigPath ? 'modified' : 'added', " file after the wizard finished to ensure it works with your build setup."));
132
+ Sentry.setTag('ast-mod', 'success');
133
+ return [3 /*break*/, 12];
134
+ case 10:
135
+ Sentry.setTag('ast-mod', 'fail');
136
+ return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)(path.basename(webpackConfigPath || 'webpack.config.js'), getCodeSnippet(options, true))];
137
+ case 11:
138
+ _g.sent();
139
+ _g.label = 12;
140
+ case 12: return [4 /*yield*/, (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken)];
141
+ case 13:
142
+ _g.sent();
105
143
  return [2 /*return*/];
106
144
  }
107
145
  });
108
146
  }); };
109
147
  exports.configureWebPackPlugin = configureWebPackPlugin;
148
+ /**
149
+ * Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin
150
+ * exported only for testing
151
+ */
152
+ function modifyWebpackConfig(webpackConfigPath, options) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ var webpackConfig, prettyConfigFilename, program, exportStmt, configObject, enabledSourcemaps, addedPlugin, code, e_1;
155
+ return __generator(this, function (_a) {
156
+ switch (_a.label) {
157
+ case 0:
158
+ _a.trys.push([0, 4, , 5]);
159
+ return [4 /*yield*/, fs.promises.readFile(webpackConfigPath, {
160
+ encoding: 'utf-8',
161
+ })];
162
+ case 1:
163
+ webpackConfig = _a.sent();
164
+ prettyConfigFilename = chalk_1.default.cyan(path.basename(webpackConfigPath));
165
+ program = recast.parse(webpackConfig.toString()).program;
166
+ return [4 /*yield*/, shouldModifyWebpackConfig(program, prettyConfigFilename)];
167
+ case 2:
168
+ if (!(_a.sent())) {
169
+ // Sentry tag is set in shouldModifyWebpackConfig
170
+ return [2 /*return*/, false];
171
+ }
172
+ exportStmt = getCjsModuleExports(program);
173
+ if (!exportStmt) {
174
+ // We only care about CJS at the moment since it's probably the most widely used format for webpack configs.
175
+ (0, debug_1.debug)("Could not find module.exports = {...} in ".concat(webpackConfigPath, "."));
176
+ Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');
177
+ return [2 /*return*/, false];
178
+ }
179
+ configObject = getWebpackConfigObject(exportStmt, program);
180
+ if (!configObject) {
181
+ (0, debug_1.debug)("Couldn't find config object in ".concat(webpackConfigPath));
182
+ Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');
183
+ return [2 /*return*/, false];
184
+ }
185
+ enabledSourcemaps = enableSourcemapsGeneration(configObject);
186
+ if (enabledSourcemaps) {
187
+ clack.log.success("Enabled source map generation in ".concat(prettyConfigFilename, "."));
188
+ }
189
+ else {
190
+ clack.log.warn("Couldn't enable source maps generation in ".concat(prettyConfigFilename, " Please follow the instructions below."));
191
+ Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
192
+ return [2 /*return*/, false];
193
+ }
194
+ addedPlugin = addSentryWebpackPlugin(program, configObject, options);
195
+ if (addedPlugin) {
196
+ clack.log.success("Added Sentry webpack plugin to ".concat(prettyConfigFilename, "."));
197
+ }
198
+ else {
199
+ clack.log.warn("Couldn't add Sentry webpack plugin to ".concat(prettyConfigFilename, ". Please follow the instructions below."));
200
+ Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
201
+ return [2 /*return*/, false];
202
+ }
203
+ code = recast.print(program).code;
204
+ return [4 /*yield*/, fs.promises.writeFile(webpackConfigPath, code)];
205
+ case 3:
206
+ _a.sent();
207
+ return [2 /*return*/, true];
208
+ case 4:
209
+ e_1 = _a.sent();
210
+ Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
211
+ (0, debug_1.debug)(e_1);
212
+ return [2 /*return*/, false];
213
+ case 5: return [2 /*return*/];
214
+ }
215
+ });
216
+ });
217
+ }
218
+ exports.modifyWebpackConfig = modifyWebpackConfig;
219
+ function shouldModifyWebpackConfig(program, prettyConfigFilename) {
220
+ return __awaiter(this, void 0, void 0, function () {
221
+ var shouldContinue;
222
+ return __generator(this, function (_a) {
223
+ switch (_a.label) {
224
+ case 0:
225
+ if (!(0, ast_utils_1.hasSentryContent)(program)) return [3 /*break*/, 2];
226
+ return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
227
+ message: "Seems like ".concat(prettyConfigFilename, " already contains Sentry-related code. Should the wizard modify it anyway?"),
228
+ options: [
229
+ {
230
+ label: 'Yes, add the Sentry Webpack plugin',
231
+ value: true,
232
+ },
233
+ {
234
+ label: 'No, show me instructions to manually add the plugin',
235
+ value: false,
236
+ },
237
+ ],
238
+ initialValue: true,
239
+ }))];
240
+ case 1:
241
+ shouldContinue = _a.sent();
242
+ if (!shouldContinue) {
243
+ Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');
244
+ return [2 /*return*/, false];
245
+ }
246
+ _a.label = 2;
247
+ case 2: return [2 /*return*/, true];
248
+ }
249
+ });
250
+ });
251
+ }
252
+ function addSentryWebpackPlugin(program, configObj, options) {
253
+ var b = addSentryWebpackPluginImport(program);
254
+ var sentryPluginCall = b.callExpression(b.identifier('sentryWebpackPlugin'), [
255
+ b.objectExpression(__spreadArray([
256
+ b.objectProperty(b.identifier('authToken'), b.identifier('process.env.SENTRY_AUTH_TOKEN')),
257
+ b.objectProperty(b.identifier('org'), b.stringLiteral(options.orgSlug)),
258
+ b.objectProperty(b.identifier('project'), b.stringLiteral(options.projectSlug))
259
+ ], (options.selfHosted
260
+ ? [
261
+ b.objectProperty(b.identifier('url'), b.stringLiteral(options.url)),
262
+ ]
263
+ : []), true)),
264
+ ]);
265
+ var pluginsProp = configObj.properties.find(function (p) {
266
+ return p.type === 'Property' &&
267
+ p.key.type === 'Identifier' &&
268
+ p.key.name === 'plugins';
269
+ });
270
+ if (pluginsProp) {
271
+ if (pluginsProp.value.type === 'ArrayExpression') {
272
+ pluginsProp.value.elements.push(sentryPluginCall);
273
+ }
274
+ else {
275
+ pluginsProp.value = b.arrayExpression([sentryPluginCall]);
276
+ }
277
+ return true;
278
+ }
279
+ configObj.properties.push(b.objectProperty(b.identifier('plugins'), b.arrayExpression([sentryPluginCall])));
280
+ return true;
281
+ }
282
+ function addSentryWebpackPluginImport(program) {
283
+ var b = recast.types.builders;
284
+ var sentryPluginRequireStmt = b.variableDeclaration('const', [
285
+ b.variableDeclarator(b.objectPattern([
286
+ b.objectProperty.from({
287
+ key: b.identifier('sentryWebpackPlugin'),
288
+ value: b.identifier('sentryWebpackPlugin'),
289
+ shorthand: true,
290
+ }),
291
+ ]), b.callExpression(b.identifier('require'), [
292
+ b.stringLiteral('@sentry/webpack-plugin'),
293
+ ])),
294
+ ]);
295
+ program.body.unshift(sentryPluginRequireStmt);
296
+ return b;
297
+ }
298
+ function enableSourcemapsGeneration(configObj) {
299
+ var _a;
300
+ var b = recast.types.builders;
301
+ var devtoolProp = configObj.properties.find(function (p) {
302
+ return p.type === 'Property' &&
303
+ p.key.type === 'Identifier' &&
304
+ p.key.name === 'devtool';
305
+ });
306
+ if (devtoolProp) {
307
+ // devtool can have quite a lot of source maps values.
308
+ // see: https://webpack.js.org/configuration/devtool/#devtool
309
+ // For Sentry to work best, we should set it to "source-map" or "hidden-source-map"
310
+ // Heuristic:
311
+ // - all values that contain "hidden" will be set to "hidden-source-map"
312
+ // - all other values will be set to "source-map"
313
+ if ((devtoolProp.value.type === 'Literal' ||
314
+ devtoolProp.value.type === 'StringLiteral') &&
315
+ ((_a = devtoolProp.value.value) === null || _a === void 0 ? void 0 : _a.toString().startsWith('hidden-'))) {
316
+ devtoolProp.value = b.stringLiteral('hidden-source-map');
317
+ }
318
+ else {
319
+ devtoolProp.value = b.stringLiteral('source-map');
320
+ }
321
+ return true;
322
+ }
323
+ configObj.properties.push(b.objectProperty(b.identifier('devtool'), b.stringLiteral('source-map')));
324
+ return true;
325
+ }
326
+ function getWebpackConfigObject(moduleExports, program) {
327
+ var _a;
328
+ var rhs = moduleExports.right;
329
+ if (rhs.type === 'ObjectExpression') {
330
+ return rhs;
331
+ }
332
+ if (rhs.type === 'Identifier') {
333
+ var configId_1 = rhs.name;
334
+ var configDeclaration = program.body.find(function (s) {
335
+ return s.type === 'VariableDeclaration' &&
336
+ !!s.declarations.find(function (d) {
337
+ return d.type === 'VariableDeclarator' &&
338
+ d.id.type === 'Identifier' &&
339
+ d.id.name === configId_1;
340
+ });
341
+ });
342
+ var declarator = configDeclaration === null || configDeclaration === void 0 ? void 0 : configDeclaration.declarations.find(function (d) {
343
+ return d.type === 'VariableDeclarator' &&
344
+ d.id.type === 'Identifier' &&
345
+ d.id.name === configId_1;
346
+ });
347
+ return ((_a = declarator === null || declarator === void 0 ? void 0 : declarator.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression'
348
+ ? declarator.init
349
+ : undefined;
350
+ }
351
+ return undefined;
352
+ }
353
+ function getCjsModuleExports(program) {
354
+ var moduleExports = program.body.find(function (s) {
355
+ return s.type === 'ExpressionStatement' &&
356
+ s.expression.type === 'AssignmentExpression' &&
357
+ s.expression.left.type === 'MemberExpression' &&
358
+ s.expression.left.object.type === 'Identifier' &&
359
+ s.expression.left.object.name === 'module' &&
360
+ s.expression.left.property.type === 'Identifier' &&
361
+ s.expression.left.property.name === 'exports';
362
+ });
363
+ return moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression;
364
+ }
110
365
  //# sourceMappingURL=webpack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,wDAA+C;AAC/C,gDAA0B;AAC1B,uDAKiC;AACjC,yDAA+D;AAO/D,IAAM,cAAc,GAAG,UAAC,OAAgD;IACtE,OAAA,eAAK,CAAC,IAAI,CAAC,YACX,eAAK,CAAC,WAAW,CACjB,oEAAoE,CACrE,sEAIG,eAAK,CAAC,WAAW,CACjB,mEAAmE,CACpE,iCAEG,eAAK,CAAC,WAAW,CAAC,+FAEV,OAAO,CAAC,OAAO,mCACX,OAAO,CAAC,WAAW,gBAC/B,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAiB,OAAO,CAAC,GAAG,QAAI,CAAC,CAAC,CAAC,EAAE,eAEzD,CAAC,kBAGP,CAAC;AApBA,CAoBA,CAAC;AAEI,IAAM,sBAAsB,GACjC,UAAO,OAAO;;;;;;gBACN,KAAA,4BAAc,CAAA;;oBAClB,WAAW,EAAE,wBAAwB;;gBACnB,KAAA,kCAAmB,CAAA;sBACnC,wBAAwB;gBACxB,qBAAM,IAAA,+BAAiB,GAAE,EAAA;oBAJ7B,qBAAM,mBAEJ,mBAAgB,GAAE,4BAEhB,SAAyB,GAC1B;6BACD,EAAA;;gBANF,SAME,CAAC;gBAEH,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,yCAAkC,eAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,WAAQ,CAC1E,CAAC;gBAEF,8FAA8F;gBAC9F,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;gBAErC,qBAAM,IAAA,8BAAgB,EACpB,IAAA,gBAAM,EAAC;wBACL,OAAO,EAAE,iCAAiC;wBAC1C,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;wBACnD,YAAY,EAAE,IAAI;qBACnB,CAAC,CACH,EAAA;;gBAND,SAMC,CAAC;gBAEF,qBAAM,IAAA,4CAA8B,EAAC,OAAO,CAAC,SAAS,CAAC,EAAA;;gBAAvD,SAAuD,CAAC;;;;KACzD,CAAC;AA3BS,QAAA,sBAAsB,0BA2B/B","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack, { select } from '@clack/prompts';\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\n\nconst getCodeSnippet = (options: SourceMapUploadToolConfigurationOptions) =>\n chalk.gray(`\n${chalk.greenBright(\n 'const { sentryWebpackPlugin } = require(\"@sentry/webpack-plugin\");',\n)}\n\nmodule.exports = {\n // ... other config options\n ${chalk.greenBright(\n 'devtool: \"source-map\", // Source map generation must be turned on',\n )}\n plugins: [\n ${chalk.greenBright(`sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n } \n })`)},\n ],\n};\n`);\n\nexport const configureWebPackPlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/webpack-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/webpack-plugin',\n await getPackageDotJson(),\n ),\n });\n\n clack.log.step(\n `Add the following code to your ${chalk.bold('webpack.config.js')} file:`,\n );\n\n // Intentially logging directly to console here so that the code can be copied/pasted directly\n // eslint-disable-next-line no-console\n console.log(getCodeSnippet(options));\n\n await abortIfCancelled(\n select({\n message: 'Did you copy the snippet above?',\n options: [{ label: 'Yes, continue!', value: true }],\n initialValue: true,\n }),\n );\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n"]}
1
+ {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAC7B,qCAAyB;AAEzB,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAE1B,6CAAiC;AAIjC,mDAAuC;AAEvC,uDASiC;AACjC,yDAA+D;AAO/D,mDAAmE;AACnE,2CAA0C;AAE1C,IAAM,cAAc,GAAG,UACrB,OAAgD,EAChD,MAAe;IAEf,OAAA,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI;QACtC,OAAA,SAAS,CAAC,UAAG,IAAI,CACf,oEAAoE,CACrE,+DAID,IAAI,CAAC,mEAAmE,CAAC,+FAGvE,IAAI,CAAC,+FAEG,OAAO,CAAC,OAAO,mCACX,OAAO,CAAC,WAAW,gBAC/B,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAiB,OAAO,CAAC,GAAG,QAAI,CAAC,CAAC,CAAC,EAAE,cAExD,CAAC,cAEP,CAAC;IAjBC,CAiBD,CACA;AAnBD,CAmBC,CAAC;AAEG,IAAM,sBAAsB,GACjC,UAAO,OAAO;;;;;;;gBACN,KAAA,4BAAc,CAAA;;oBAClB,WAAW,EAAE,wBAAwB;;gBACnB,KAAA,kCAAmB,CAAA;sBACnC,wBAAwB;gBACxB,qBAAM,IAAA,+BAAiB,GAAE,EAAA;oBAJ7B,qBAAM,mBAEJ,mBAAgB,GAAE,4BAEhB,SAAyB,GAC1B;6BACD,EAAA;;gBANF,SAME,CAAC;4BA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A,OAAA,CAAC,CAAC,IAAI,KAAK,qBAAqB;YAChC,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,sBAAsB;YAC5C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB;YAC7C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY;YAC9C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ;YAC1C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;YAChD,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS;IAN7C,CAM6C,CAChD,CAAC;IACF,OAAO,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,UAAoC,CAAC;AAC7D,CAAC","sourcesContent":["import * as path from 'path';\nimport * as fs from 'fs';\n\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport * as Sentry from '@sentry/node';\n\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\n\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst getCodeSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus) =>\n unchanged(`${plus(\n 'const { sentryWebpackPlugin } = require(\"@sentry/webpack-plugin\");',\n )}\n\nmodule.exports = {\n // ... other options\n ${plus('devtool: \"source-map\", // Source map generation must be turned on')}\n plugins: [\n // Put the Sentry Webpack plugin after all other plugins\n ${plus(`sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`)}\n ],\n}`),\n );\n\nexport const configureWebPackPlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/webpack-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/webpack-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const webpackConfigPath =\n findFile(path.resolve(process.cwd(), 'webpack.config')) ??\n (await askForToolConfigPath('Webpack', 'webpack.config.js'));\n\n let successfullyAdded = false;\n if (webpackConfigPath) {\n successfullyAdded = await modifyWebpackConfig(webpackConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'webpack.config.js'),\n getCodeSnippet(options, false),\n 'More information about Webpack configs: https://vitejs.dev/config/',\n );\n Sentry.setTag(\n 'created-new-config',\n successfullyAdded ? 'success' : 'fail',\n );\n }\n\n if (successfullyAdded) {\n clack.log.info(\n `We recommend checking the ${\n webpackConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(webpackConfigPath || 'webpack.config.js'),\n getCodeSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\n/**\n * Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin\n * exported only for testing\n */\nexport async function modifyWebpackConfig(\n webpackConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const webpackConfig = await fs.promises.readFile(webpackConfigPath, {\n encoding: 'utf-8',\n });\n\n const prettyConfigFilename = chalk.cyan(path.basename(webpackConfigPath));\n\n // no idea why recast returns any here, this is dumb :/\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(webpackConfig.toString()).program as t.Program;\n\n if (!(await shouldModifyWebpackConfig(program, prettyConfigFilename))) {\n // Sentry tag is set in shouldModifyWebpackConfig\n return false;\n }\n\n const exportStmt = getCjsModuleExports(program);\n if (!exportStmt) {\n // We only care about CJS at the moment since it's probably the most widely used format for webpack configs.\n debug(`Could not find module.exports = {...} in ${webpackConfigPath}.`);\n Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');\n return false;\n }\n\n const configObject = getWebpackConfigObject(exportStmt, program);\n\n if (!configObject) {\n debug(`Couldn't find config object in ${webpackConfigPath}`);\n Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');\n return false;\n }\n\n const enabledSourcemaps = enableSourcemapsGeneration(configObject);\n\n if (enabledSourcemaps) {\n clack.log.success(\n `Enabled source map generation in ${prettyConfigFilename}.`,\n );\n } else {\n clack.log.warn(\n `Couldn't enable source maps generation in ${prettyConfigFilename} Please follow the instructions below.`,\n );\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const addedPlugin = addSentryWebpackPlugin(program, configObject, options);\n if (addedPlugin) {\n clack.log.success(\n `Added Sentry webpack plugin to ${prettyConfigFilename}.`,\n );\n } else {\n clack.log.warn(\n `Couldn't add Sentry webpack plugin to ${prettyConfigFilename}. Please follow the instructions below.`,\n );\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const code = recast.print(program).code;\n await fs.promises.writeFile(webpackConfigPath, code);\n\n return true;\n } catch (e) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n debug(e);\n return false;\n }\n}\n\nasync function shouldModifyWebpackConfig(\n program: t.Program,\n prettyConfigFilename: string,\n) {\n if (hasSentryContent(program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Seems like ${prettyConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Webpack plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n return false;\n }\n }\n\n return true;\n}\n\nfunction addSentryWebpackPlugin(\n program: t.Program,\n configObj: t.ObjectExpression,\n options: SourceMapUploadToolConfigurationOptions,\n) {\n const b = addSentryWebpackPluginImport(program);\n\n const sentryPluginCall = b.callExpression(\n b.identifier('sentryWebpackPlugin'),\n [\n b.objectExpression([\n b.objectProperty(\n b.identifier('authToken'),\n b.identifier('process.env.SENTRY_AUTH_TOKEN'),\n ),\n b.objectProperty(b.identifier('org'), b.stringLiteral(options.orgSlug)),\n b.objectProperty(\n b.identifier('project'),\n b.stringLiteral(options.projectSlug),\n ),\n ...(options.selfHosted\n ? [\n b.objectProperty(\n b.identifier('url'),\n b.stringLiteral(options.url),\n ),\n ]\n : []),\n ]),\n ],\n );\n\n const pluginsProp = configObj.properties.find(\n (p): p is t.Property =>\n p.type === 'Property' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'plugins',\n );\n\n if (pluginsProp) {\n if (pluginsProp.value.type === 'ArrayExpression') {\n pluginsProp.value.elements.push(sentryPluginCall);\n } else {\n pluginsProp.value = b.arrayExpression([sentryPluginCall]);\n }\n return true;\n }\n\n configObj.properties.push(\n b.objectProperty(\n b.identifier('plugins'),\n b.arrayExpression([sentryPluginCall]),\n ),\n );\n\n return true;\n}\n\nfunction addSentryWebpackPluginImport(program: t.Program) {\n const b = recast.types.builders;\n\n const sentryPluginRequireStmt = b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('sentryWebpackPlugin'),\n value: b.identifier('sentryWebpackPlugin'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.stringLiteral('@sentry/webpack-plugin'),\n ]),\n ),\n ]);\n\n program.body.unshift(sentryPluginRequireStmt);\n return b;\n}\n\nfunction enableSourcemapsGeneration(configObj: t.ObjectExpression): boolean {\n const b = recast.types.builders;\n\n const devtoolProp = configObj.properties.find(\n (p): p is t.Property =>\n p.type === 'Property' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'devtool',\n );\n\n if (devtoolProp) {\n // devtool can have quite a lot of source maps values.\n // see: https://webpack.js.org/configuration/devtool/#devtool\n // For Sentry to work best, we should set it to \"source-map\" or \"hidden-source-map\"\n // Heuristic:\n // - all values that contain \"hidden\" will be set to \"hidden-source-map\"\n // - all other values will be set to \"source-map\"\n if (\n (devtoolProp.value.type === 'Literal' ||\n devtoolProp.value.type === 'StringLiteral') &&\n devtoolProp.value.value?.toString().startsWith('hidden-')\n ) {\n devtoolProp.value = b.stringLiteral('hidden-source-map');\n } else {\n devtoolProp.value = b.stringLiteral('source-map');\n }\n return true;\n }\n\n configObj.properties.push(\n b.objectProperty(b.identifier('devtool'), b.stringLiteral('source-map')),\n );\n\n return true;\n}\n\nfunction getWebpackConfigObject(\n moduleExports: t.AssignmentExpression,\n program: t.Program,\n): t.ObjectExpression | undefined {\n const rhs = moduleExports.right;\n if (rhs.type === 'ObjectExpression') {\n return rhs;\n }\n if (rhs.type === 'Identifier') {\n const configId = rhs.name;\n\n const configDeclaration = program.body.find(\n (s): s is t.VariableDeclaration =>\n s.type === 'VariableDeclaration' &&\n !!s.declarations.find(\n (d) =>\n d.type === 'VariableDeclarator' &&\n d.id.type === 'Identifier' &&\n d.id.name === configId,\n ),\n );\n\n const declarator = configDeclaration?.declarations.find(\n (d): d is t.VariableDeclarator =>\n d.type === 'VariableDeclarator' &&\n d.id.type === 'Identifier' &&\n d.id.name === configId,\n );\n\n return declarator?.init?.type === 'ObjectExpression'\n ? declarator.init\n : undefined;\n }\n\n return undefined;\n}\n\nfunction getCjsModuleExports(\n program: t.Program,\n): t.AssignmentExpression | undefined {\n const moduleExports = program.body.find(\n (s): s is t.ExpressionStatement =>\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports',\n );\n return moduleExports?.expression as t.AssignmentExpression;\n}\n"]}