@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.
- package/CHANGELOG.md +19 -0
- package/dist/lib/Steps/ChooseIntegration.js +1 -0
- package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
- package/dist/package.json +2 -2
- package/dist/src/android/android-wizard.js +8 -8
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/apple/apple-wizard.js +1 -1
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.d.ts +1 -0
- package/dist/src/nextjs/nextjs-wizard.js +257 -163
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +1 -1
- package/dist/src/nextjs/templates.js +2 -2
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/nextjs/utils.d.ts +1 -0
- package/dist/src/nextjs/utils.js +25 -0
- package/dist/src/nextjs/utils.js.map +1 -0
- package/dist/src/remix/remix-wizard.js +13 -11
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.d.ts +5 -1
- package/dist/src/remix/sdk-setup.js +13 -6
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/sentry-cli.d.ts +9 -0
- package/dist/src/sourcemaps/tools/sentry-cli.js +26 -22
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/sourcemaps/tools/tsc.d.ts +6 -0
- package/dist/src/sourcemaps/tools/tsc.js +98 -17
- package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +3 -13
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sourcemaps/tools/webpack.js +3 -13
- package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +122 -48
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.d.ts +1 -0
- package/dist/src/sveltekit/sveltekit-wizard.js +113 -42
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/sveltekit/utils.d.ts +2 -0
- package/dist/src/sveltekit/utils.js +48 -0
- package/dist/src/sveltekit/utils.js.map +1 -0
- package/dist/src/telemetry.d.ts +1 -0
- package/dist/src/telemetry.js +27 -12
- package/dist/src/telemetry.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +70 -0
- package/dist/src/utils/ast-utils.js +152 -1
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +49 -7
- package/dist/src/utils/clack-utils.js +238 -168
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +5 -0
- package/dist/src/utils/package-manager.js +23 -14
- package/dist/src/utils/package-manager.js.map +1 -1
- package/dist/test/sourcemaps/tools/sentry-cli.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/sentry-cli.test.js +112 -0
- package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -0
- package/dist/test/sourcemaps/tools/tsc.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/tsc.test.js +121 -0
- package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -0
- package/dist/test/utils/ast-utils.test.js +157 -26
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/lib/Steps/ChooseIntegration.ts +1 -0
- package/package.json +2 -2
- package/src/android/android-wizard.ts +12 -10
- package/src/apple/apple-wizard.ts +2 -2
- package/src/nextjs/nextjs-wizard.ts +277 -198
- package/src/nextjs/templates.ts +3 -2
- package/src/nextjs/utils.ts +21 -0
- package/src/remix/remix-wizard.ts +15 -20
- package/src/remix/sdk-setup.ts +20 -5
- package/src/sourcemaps/sourcemaps-wizard.ts +2 -2
- package/src/sourcemaps/tools/sentry-cli.ts +16 -9
- package/src/sourcemaps/tools/tsc.ts +133 -28
- package/src/sourcemaps/tools/vite.ts +15 -39
- package/src/sourcemaps/tools/webpack.ts +16 -39
- package/src/sveltekit/sdk-setup.ts +109 -37
- package/src/sveltekit/sveltekit-wizard.ts +86 -21
- package/src/sveltekit/utils.ts +50 -0
- package/src/telemetry.ts +22 -11
- package/src/utils/ast-utils.ts +180 -0
- package/src/utils/clack-utils.ts +238 -149
- package/src/utils/package-manager.ts +24 -12
- package/test/sourcemaps/tools/sentry-cli.test.ts +51 -0
- package/test/sourcemaps/tools/tsc.test.ts +181 -0
- package/test/utils/ast-utils.test.ts +233 -32
|
@@ -62,9 +62,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.setupNpmScriptInCI = exports.configureSentryCLI = void 0;
|
|
65
|
+
exports.addSentryCommandToBuildCommand = exports.setupNpmScriptInCI = exports.configureSentryCLI = void 0;
|
|
66
66
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
67
|
-
var
|
|
67
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
68
68
|
var chalk_1 = __importDefault(require("chalk"));
|
|
69
69
|
var Sentry = __importStar(require("@sentry/node"));
|
|
70
70
|
var path = __importStar(require("path"));
|
|
@@ -92,7 +92,7 @@ function configureSentryCLI(options, configureSourcemapGenerationFlow) {
|
|
|
92
92
|
_b.sent();
|
|
93
93
|
validPath = false;
|
|
94
94
|
_b.label = 3;
|
|
95
|
-
case 3: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
95
|
+
case 3: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.text({
|
|
96
96
|
message: 'Where are your build artifacts located?',
|
|
97
97
|
placeholder: ".".concat(path.sep, "out"),
|
|
98
98
|
validate: function (value) {
|
|
@@ -119,7 +119,7 @@ function configureSentryCLI(options, configureSourcemapGenerationFlow) {
|
|
|
119
119
|
return [3 /*break*/, 9];
|
|
120
120
|
case 7:
|
|
121
121
|
_a = _b.sent();
|
|
122
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
122
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
123
123
|
message: "We couldn't find artifacts at ".concat(relativeArtifactPath, ". Are you sure that this is the location that contains your build artifacts?"),
|
|
124
124
|
options: [
|
|
125
125
|
{
|
|
@@ -156,7 +156,7 @@ function configureSentryCLI(options, configureSourcemapGenerationFlow) {
|
|
|
156
156
|
_b.sent();
|
|
157
157
|
return [3 /*break*/, 16];
|
|
158
158
|
case 15:
|
|
159
|
-
|
|
159
|
+
clack.log.info("No problem, just make sure to run this script ".concat(chalk_1.default.bold('after'), " building your application but ").concat(chalk_1.default.bold('before'), " deploying!"));
|
|
160
160
|
_b.label = 16;
|
|
161
161
|
case 16: return [4 /*yield*/, (0, clack_utils_1.addSentryCliConfig)(options.authToken)];
|
|
162
162
|
case 17:
|
|
@@ -178,7 +178,7 @@ function setupNpmScriptInCI() {
|
|
|
178
178
|
// if the script is already added to the build command
|
|
179
179
|
return [2 /*return*/];
|
|
180
180
|
}
|
|
181
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
181
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
182
182
|
message: "Add a step to your CI pipeline that runs the ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script ").concat(chalk_1.default.bold('right after'), " building your application."),
|
|
183
183
|
options: [
|
|
184
184
|
{ label: 'I did, continue!', value: true },
|
|
@@ -194,7 +194,7 @@ function setupNpmScriptInCI() {
|
|
|
194
194
|
addedToCI = _a.sent();
|
|
195
195
|
Sentry.setTag('added-ci-script', addedToCI);
|
|
196
196
|
if (!addedToCI) {
|
|
197
|
-
|
|
197
|
+
clack.log.info("Don't forget! :)");
|
|
198
198
|
}
|
|
199
199
|
return [2 /*return*/];
|
|
200
200
|
}
|
|
@@ -214,7 +214,7 @@ function createAndAddNpmScript(packageDotJson, options, relativePosixArtifactPat
|
|
|
214
214
|
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(packageDotJson, null, 2))];
|
|
215
215
|
case 1:
|
|
216
216
|
_a.sent();
|
|
217
|
-
|
|
217
|
+
clack.log.info("Added a ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to your ").concat(chalk_1.default.cyan('package.json'), "."));
|
|
218
218
|
return [2 /*return*/];
|
|
219
219
|
}
|
|
220
220
|
});
|
|
@@ -225,7 +225,7 @@ function askShouldAddToBuildCommand() {
|
|
|
225
225
|
var shouldAddToBuildCommand;
|
|
226
226
|
return __generator(this, function (_a) {
|
|
227
227
|
switch (_a.label) {
|
|
228
|
-
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
228
|
+
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
229
229
|
message: "Do you want to automatically run the ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script after each production build?"),
|
|
230
230
|
options: [
|
|
231
231
|
{
|
|
@@ -255,7 +255,7 @@ function askShouldAddToBuildCommand() {
|
|
|
255
255
|
function addSentryCommandToBuildCommand(packageDotJson) {
|
|
256
256
|
var _a;
|
|
257
257
|
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
-
var allNpmScripts, packageManager,
|
|
258
|
+
var allNpmScripts, packageManager, buildCommand, isProdBuildCommand, _b, oldCommand;
|
|
259
259
|
return __generator(this, function (_c) {
|
|
260
260
|
switch (_c.label) {
|
|
261
261
|
case 0:
|
|
@@ -263,15 +263,14 @@ function addSentryCommandToBuildCommand(packageDotJson) {
|
|
|
263
263
|
// SENTRY_NPM_SCRIPT_NAME script but just to be sure
|
|
264
264
|
packageDotJson.scripts = packageDotJson.scripts || {};
|
|
265
265
|
allNpmScripts = Object.keys(packageDotJson.scripts).filter(function (s) { return s !== SENTRY_NPM_SCRIPT_NAME; });
|
|
266
|
-
packageManager = (0, package_manager_1.detectPackageManger)();
|
|
267
|
-
packageManagerName = (_a = packageManager === null || packageManager === void 0 ? void 0 : packageManager.name) !== null && _a !== void 0 ? _a : 'npm';
|
|
266
|
+
packageManager = (_a = (0, package_manager_1.detectPackageManger)()) !== null && _a !== void 0 ? _a : package_manager_1.NPM;
|
|
268
267
|
buildCommand = typeof packageDotJson.scripts.build === 'string'
|
|
269
268
|
? 'build'
|
|
270
269
|
: allNpmScripts.find(function (s) { return s.toLocaleLowerCase().includes('build'); });
|
|
271
270
|
_b = !!buildCommand;
|
|
272
271
|
if (!_b) return [3 /*break*/, 2];
|
|
273
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
274
|
-
message: "Is ".concat(chalk_1.default.cyan("".concat(
|
|
272
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.confirm({
|
|
273
|
+
message: "Is ".concat(chalk_1.default.cyan("".concat(packageManager.runScriptCommand, " ").concat(buildCommand)), " your production build command?"),
|
|
275
274
|
}))];
|
|
276
275
|
case 1:
|
|
277
276
|
_b = (_c.sent());
|
|
@@ -279,8 +278,8 @@ function addSentryCommandToBuildCommand(packageDotJson) {
|
|
|
279
278
|
case 2:
|
|
280
279
|
isProdBuildCommand = _b;
|
|
281
280
|
if (!(allNpmScripts.length && (!buildCommand || !isProdBuildCommand))) return [3 /*break*/, 4];
|
|
282
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
283
|
-
message: "Which ".concat(
|
|
281
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
282
|
+
message: "Which ".concat(packageManager.name, " command in your ").concat(chalk_1.default.cyan('package.json'), " builds your application for production?"),
|
|
284
283
|
options: allNpmScripts
|
|
285
284
|
.map(function (script) { return ({
|
|
286
285
|
label: script,
|
|
@@ -293,27 +292,32 @@ function addSentryCommandToBuildCommand(packageDotJson) {
|
|
|
293
292
|
_c.label = 4;
|
|
294
293
|
case 4:
|
|
295
294
|
if (!buildCommand || buildCommand === 'none') {
|
|
296
|
-
|
|
295
|
+
clack.log.warn("We can only add the ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to another `script` in your ").concat(chalk_1.default.cyan('package.json'), ".\nPlease add it manually to your prod build command."));
|
|
297
296
|
return [2 /*return*/];
|
|
298
297
|
}
|
|
299
|
-
packageDotJson.scripts[buildCommand
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
oldCommand = packageDotJson.scripts[buildCommand];
|
|
299
|
+
if (!oldCommand) {
|
|
300
|
+
// very unlikely to happen but nevertheless
|
|
301
|
+
clack.log.warn("`".concat(buildCommand, "` doesn't seem to be part of your package.json scripts"));
|
|
302
|
+
return [2 /*return*/];
|
|
303
|
+
}
|
|
304
|
+
packageDotJson.scripts[buildCommand] = "".concat(oldCommand, " && ").concat(packageManager.runScriptCommand, " ").concat(SENTRY_NPM_SCRIPT_NAME);
|
|
302
305
|
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(packageDotJson, null, 2))];
|
|
303
306
|
case 5:
|
|
304
307
|
_c.sent();
|
|
305
308
|
addedToBuildCommand = true;
|
|
306
|
-
|
|
309
|
+
clack.log.info("Added ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to your ").concat(chalk_1.default.cyan(buildCommand), " command."));
|
|
307
310
|
return [2 /*return*/];
|
|
308
311
|
}
|
|
309
312
|
});
|
|
310
313
|
});
|
|
311
314
|
}
|
|
315
|
+
exports.addSentryCommandToBuildCommand = addSentryCommandToBuildCommand;
|
|
312
316
|
function defaultConfigureSourcemapGenerationFlow() {
|
|
313
317
|
return __awaiter(this, void 0, void 0, function () {
|
|
314
318
|
return __generator(this, function (_a) {
|
|
315
319
|
switch (_a.label) {
|
|
316
|
-
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
320
|
+
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
317
321
|
message: "Verify that your build tool is generating source maps. ".concat(chalk_1.default.dim('(Your build output folder should contain .js.map files after a build)')),
|
|
318
322
|
options: [{ label: 'I checked. Continue!', value: true }],
|
|
319
323
|
initialValue: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,2DAAmC;AACnC,gDAA0B;AAC1B,mDAAuC;AACvC,yCAA6B;AAC7B,qCAAyB;AACzB,uDAKiC;AAGjC,yDAA+E;AAC/E,6CAA4C;AAC5C,+DAAkE;AAElE,IAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,SAAsB,kBAAkB,CACtC,OAAgD,EAChD,gCAA+F;IAA/F,iDAAA,EAAA,0EAA+F;;;;;wBAExE,qBAAM,IAAA,+BAAiB,GAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAEhD,qBAAM,IAAA,4BAAc,EAAC;4BACnB,WAAW,EAAE,aAAa;4BAC1B,gBAAgB,EAAE,IAAA,kCAAmB,EAAC,aAAa,EAAE,cAAc,CAAC;yBACrE,CAAC,EAAA;;oBAHF,SAGE,CAAC;oBAEC,SAAS,GAAG,KAAK,CAAC;;wBAGI,qBAAM,IAAA,8BAAgB,EAC5C,iBAAK,CAAC,IAAI,CAAC;wBACT,OAAO,EAAE,yCAAyC;wBAClD,WAAW,EAAE,WAAI,IAAI,CAAC,GAAG,QAAK;wBAC9B,QAAQ,Y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b,CAAC;;;;;CACH;AAED,SAAe,uCAAuC;;;;wBACpD,qBAAM,IAAA,8BAAgB,EACpB,iBAAK,CAAC,MAAM,CAAC;wBACX,OAAO,EAAE,iEAA0D,eAAK,CAAC,GAAG,CAC1E,uEAAuE,CACxE,CAAE;wBACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;wBACzD,YAAY,EAAE,IAAI;qBACnB,CAAC,CACH,EAAA;;oBARD,SAQC,CAAC;;;;;CACH","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { detectPackageManger } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(\n packageDotJson,\n options,\n relativePosixArtifactPath,\n );\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(packageDotJson),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig(options.authToken);\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n packageDotJson: PackageDotJson,\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nasync function addSentryCommandToBuildCommand(\n packageDotJson: PackageDotJson,\n): Promise<void> {\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = detectPackageManger();\n const packageManagerName = packageManager?.name ?? 'npm';\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManagerName} run ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManagerName} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n packageDotJson.scripts[\n buildCommand\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n ] = `${packageDotJson.scripts[buildCommand]} && ${packageManager} run ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { detectPackageManger, NPM } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(\n packageDotJson,\n options,\n relativePosixArtifactPath,\n );\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(packageDotJson),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig(options.authToken);\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n packageDotJson: PackageDotJson,\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nexport async function addSentryCommandToBuildCommand(\n packageDotJson: PackageDotJson,\n): Promise<void> {\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = detectPackageManger() ?? NPM;\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManager.runScriptCommand} ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManager.name} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n const oldCommand = packageDotJson.scripts[buildCommand];\n if (!oldCommand) {\n // very unlikely to happen but nevertheless\n clack.log.warn(\n `\\`${buildCommand}\\` doesn't seem to be part of your package.json scripts`,\n );\n return;\n }\n\n packageDotJson.scripts[\n buildCommand\n ] = `${oldCommand} && ${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
|
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function configureTscSourcemapGenerationFlow(): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.
|
|
4
|
+
*
|
|
5
|
+
* Exported only for testing
|
|
6
|
+
*/
|
|
7
|
+
export declare function enableSourcemaps(tsConfigPath: string): Promise<boolean>;
|
|
@@ -62,32 +62,113 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.configureTscSourcemapGenerationFlow = void 0;
|
|
65
|
+
exports.enableSourcemaps = exports.configureTscSourcemapGenerationFlow = void 0;
|
|
66
|
+
var fs = __importStar(require("fs"));
|
|
67
|
+
var path = __importStar(require("path"));
|
|
68
|
+
var recast = __importStar(require("recast"));
|
|
69
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
66
70
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
67
|
-
var
|
|
71
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
68
72
|
var chalk_1 = __importDefault(require("chalk"));
|
|
69
73
|
var clack_utils_1 = require("../../utils/clack-utils");
|
|
74
|
+
var ast_utils_1 = require("../../utils/ast-utils");
|
|
75
|
+
var debug_1 = require("../../utils/debug");
|
|
76
|
+
var b = recast.types.builders;
|
|
77
|
+
var getCodeSnippet = function (colors) {
|
|
78
|
+
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
79
|
+
return unchanged("{\n \"compilerOptions\": {\n ".concat(plus('"sourceMap": true,'), "\n ").concat(plus('"inlineSources": true,'), "\n\n // Set `sourceRoot` to \"/\" to strip the build path prefix from\n // generated source code references. This will improve issue grouping in Sentry.\n ").concat(plus('"sourceRoot": "/"'), "\n }\n}"));
|
|
80
|
+
});
|
|
81
|
+
};
|
|
70
82
|
function configureTscSourcemapGenerationFlow() {
|
|
83
|
+
var _a;
|
|
71
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
var tsConfigPath, _b, successfullyAdded;
|
|
86
|
+
return __generator(this, function (_c) {
|
|
87
|
+
switch (_c.label) {
|
|
74
88
|
case 0:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return [
|
|
89
|
+
if (!((_a = (0, ast_utils_1.findFile)(path.join(process.cwd(), 'tsconfig'), ['.json'])) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
90
|
+
_b = _a;
|
|
91
|
+
return [3 /*break*/, 3];
|
|
92
|
+
case 1: return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('TypeScript', 'tsconfig.json')];
|
|
93
|
+
case 2:
|
|
94
|
+
_b = (_c.sent());
|
|
95
|
+
_c.label = 3;
|
|
96
|
+
case 3:
|
|
97
|
+
tsConfigPath = _b;
|
|
98
|
+
successfullyAdded = false;
|
|
99
|
+
if (!tsConfigPath) return [3 /*break*/, 5];
|
|
100
|
+
return [4 /*yield*/, enableSourcemaps(tsConfigPath)];
|
|
101
|
+
case 4:
|
|
102
|
+
successfullyAdded = _c.sent();
|
|
103
|
+
return [3 /*break*/, 7];
|
|
104
|
+
case 5: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'tsconfig.json'), getCodeSnippet(false))];
|
|
105
|
+
case 6:
|
|
106
|
+
successfullyAdded = _c.sent();
|
|
107
|
+
Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
|
|
108
|
+
_c.label = 7;
|
|
109
|
+
case 7:
|
|
110
|
+
if (!successfullyAdded) return [3 /*break*/, 8];
|
|
111
|
+
Sentry.setTag('ast-mod', 'success');
|
|
112
|
+
clack.log.info("We recommend checking the ".concat(tsConfigPath ? 'modified' : 'added', " file after the wizard finished to ensure it works with your build setup."));
|
|
113
|
+
return [3 /*break*/, 10];
|
|
114
|
+
case 8:
|
|
115
|
+
Sentry.setTag('ast-mod', 'fail');
|
|
116
|
+
return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)('tsconfig.json', getCodeSnippet(true), 'This ensures that source maps are generated correctly')];
|
|
117
|
+
case 9:
|
|
118
|
+
_c.sent();
|
|
119
|
+
_c.label = 10;
|
|
120
|
+
case 10: return [2 /*return*/];
|
|
87
121
|
}
|
|
88
122
|
});
|
|
89
123
|
});
|
|
90
124
|
}
|
|
91
125
|
exports.configureTscSourcemapGenerationFlow = configureTscSourcemapGenerationFlow;
|
|
92
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.
|
|
128
|
+
*
|
|
129
|
+
* Exported only for testing
|
|
130
|
+
*/
|
|
131
|
+
function enableSourcemaps(tsConfigPath) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var tsConfig, _a, ast, jsonObject, compilerOptionsProp, compilerOptionsObj, code, e_1;
|
|
134
|
+
return __generator(this, function (_b) {
|
|
135
|
+
switch (_b.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
_b.trys.push([0, 3, , 4]);
|
|
138
|
+
return [4 /*yield*/, fs.promises.readFile(tsConfigPath, 'utf-8')];
|
|
139
|
+
case 1:
|
|
140
|
+
tsConfig = _b.sent();
|
|
141
|
+
_a = (0, ast_utils_1.parseJsonC)(tsConfig.toString()), ast = _a.ast, jsonObject = _a.jsonObject;
|
|
142
|
+
if (!jsonObject || !ast) {
|
|
143
|
+
// this will only happen if the input file isn't valid JSON-C
|
|
144
|
+
Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');
|
|
145
|
+
return [2 /*return*/, false];
|
|
146
|
+
}
|
|
147
|
+
compilerOptionsProp = (0, ast_utils_1.getOrSetObjectProperty)(jsonObject, 'compilerOptions', b.objectExpression([]));
|
|
148
|
+
compilerOptionsObj = compilerOptionsProp.value;
|
|
149
|
+
if (!compilerOptionsObj || compilerOptionsObj.type !== 'ObjectExpression') {
|
|
150
|
+
// a valid compilerOptions prop should always be an object expression
|
|
151
|
+
Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');
|
|
152
|
+
return [2 /*return*/, false];
|
|
153
|
+
}
|
|
154
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(compilerOptionsObj, 'sourceMap', b.booleanLiteral(true));
|
|
155
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(compilerOptionsObj, 'inlineSources', b.booleanLiteral(true));
|
|
156
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(compilerOptionsObj, 'sourceRoot', b.stringLiteral('/'), 'Set `sourceRoot` to "/" to strip the build path prefix\nfrom generated source code references.\nThis improves issue grouping in Sentry.');
|
|
157
|
+
code = (0, ast_utils_1.printJsonC)(ast);
|
|
158
|
+
return [4 /*yield*/, fs.promises.writeFile(tsConfigPath, code)];
|
|
159
|
+
case 2:
|
|
160
|
+
_b.sent();
|
|
161
|
+
clack.log.success("Enabled source maps generation in ".concat(chalk_1.default.cyan(path.basename(tsConfigPath || 'tsconfig.json')), "."));
|
|
162
|
+
return [2 /*return*/, true];
|
|
163
|
+
case 3:
|
|
164
|
+
e_1 = _b.sent();
|
|
165
|
+
(0, debug_1.debug)(e_1);
|
|
166
|
+
Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
|
|
167
|
+
return [2 /*return*/, false];
|
|
168
|
+
case 4: return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
exports.enableSourcemaps = enableSourcemaps;
|
|
93
174
|
//# sourceMappingURL=tsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsc.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/tsc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"tsc.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/tsc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yCAA6B;AAE7B,6CAAiC;AAEjC,mDAAuC;AAEvC,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAE1B,uDAKiC;AACjC,mDAM+B;AAC/B,2CAA0C;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EACf,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CACvB,CAAC;oBAEF,IAAA,qCAAyB,EACvB,kBAAkB,EAClB,YAAY,EACZ,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,EACpB,0IAA0I,CAC3I,CAAC;oBAEI,IAAI,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC;oBAE7B,qBAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,EAAA;;oBAA/C,SAA+C,CAAC;oBAEhD,KAAK,CAAC,GAAG,CAAC,OAAO,CACf,4CAAqC,eAAK,CAAC,IAAI,CAC7C,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,eAAe,CAAC,CAC/C,MAAG,CACL,CAAC;oBAEF,sBAAO,IAAI,EAAC;;;oBAEZ,IAAA,aAAK,EAAC,GAAC,CAAC,CAAC;oBACT,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;oBACvD,sBAAO,KAAK,EAAC;;;;;CAEhB;AA7DD,4CA6DC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\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 {\n askForToolConfigPath,\n createNewConfigFile,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport {\n findFile,\n getOrSetObjectProperty,\n parseJsonC,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst b = recast.types.builders;\n\nconst getCodeSnippet = (colors: boolean) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(\n `{\n \"compilerOptions\": {\n ${plus('\"sourceMap\": true,')}\n ${plus('\"inlineSources\": true,')}\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix from\n // generated source code references. This will improve issue grouping in Sentry.\n ${plus('\"sourceRoot\": \"/\"')}\n }\n}`,\n ),\n );\n\nexport async function configureTscSourcemapGenerationFlow(): Promise<void> {\n const tsConfigPath =\n findFile(path.join(process.cwd(), 'tsconfig'), ['.json']) ??\n (await askForToolConfigPath('TypeScript', 'tsconfig.json'));\n\n let successfullyAdded = false;\n if (tsConfigPath) {\n successfullyAdded = await enableSourcemaps(tsConfigPath);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'tsconfig.json'),\n getCodeSnippet(false),\n );\n Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');\n }\n\n if (successfullyAdded) {\n Sentry.setTag('ast-mod', 'success');\n clack.log.info(\n `We recommend checking the ${\n tsConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n 'tsconfig.json',\n getCodeSnippet(true),\n 'This ensures that source maps are generated correctly',\n );\n }\n}\n\n/**\n * Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.\n *\n * Exported only for testing\n */\nexport async function enableSourcemaps(tsConfigPath: string): Promise<boolean> {\n try {\n const tsConfig = await fs.promises.readFile(tsConfigPath, 'utf-8');\n\n const { ast, jsonObject } = parseJsonC(tsConfig.toString());\n\n if (!jsonObject || !ast) {\n // this will only happen if the input file isn't valid JSON-C\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n const compilerOptionsProp = getOrSetObjectProperty(\n jsonObject,\n 'compilerOptions',\n b.objectExpression([]),\n );\n\n const compilerOptionsObj = compilerOptionsProp.value;\n\n if (!compilerOptionsObj || compilerOptionsObj.type !== 'ObjectExpression') {\n // a valid compilerOptions prop should always be an object expression\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceMap',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'inlineSources',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceRoot',\n b.stringLiteral('/'),\n 'Set `sourceRoot` to \"/\" to strip the build path prefix\\nfrom generated source code references.\\nThis improves issue grouping in Sentry.',\n );\n\n const code = printJsonC(ast);\n\n await fs.promises.writeFile(tsConfigPath, code);\n\n clack.log.success(\n `Enabled source maps generation in ${chalk.cyan(\n path.basename(tsConfigPath || 'tsconfig.json'),\n )}.`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n"]}
|
|
@@ -90,20 +90,10 @@ var path = __importStar(require("path"));
|
|
|
90
90
|
var fs = __importStar(require("fs"));
|
|
91
91
|
var debug_1 = require("../../utils/debug");
|
|
92
92
|
var getViteConfigSnippet = function (options, colors) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var importStmt = colors ? chalk_1.default.greenBright(rawImportStmt) : rawImportStmt;
|
|
97
|
-
var generateSourceMapsOption = colors
|
|
98
|
-
? chalk_1.default.greenBright(rawGenerateSourceMapsOption)
|
|
99
|
-
: rawGenerateSourceMapsOption;
|
|
100
|
-
var sentryVitePluginFunction = colors
|
|
101
|
-
? chalk_1.default.greenBright(rawSentryVitePluginFunction)
|
|
102
|
-
: rawSentryVitePluginFunction;
|
|
103
|
-
var code = getViteConfigContent(importStmt, generateSourceMapsOption, sentryVitePluginFunction);
|
|
104
|
-
return colors ? chalk_1.default.gray(code) : code;
|
|
93
|
+
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
94
|
+
return unchanged("import { defineConfig } from \"vite\";\n".concat(plus('import { sentryVitePlugin } from "@sentry/vite-plugin";'), "\n\nexport default defineConfig({\n build: {\n ").concat(plus('sourcemap: true, // Source map generation must be turned on'), "\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ").concat(plus("sentryVitePlugin({\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});"));
|
|
95
|
+
});
|
|
105
96
|
};
|
|
106
|
-
var getViteConfigContent = function (importStmt, generateSourceMapsOption, sentryVitePluginFunction) { return "import { defineConfig } from \"vite\";\n".concat(importStmt, "\n\nexport default defineConfig({\n build: {\n ").concat(generateSourceMapsOption, "\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ").concat(sentryVitePluginFunction, "\n ],\n});\n"); };
|
|
107
97
|
var configureVitePlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
98
|
var _a, _b, _c, viteConfigPath, _d, successfullyAdded;
|
|
109
99
|
var _e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAqD;AACrD,4EAA4E;AAC5E,4CAAiD;AAIjD,6CAAiC;AAEjC,mDAAuC;AAEvC,gDAA0B;AAC1B,uDAQiC;AACjC,yDAA+D;AAM/D,mDAAmE;AAEnE,yCAA6B;AAC7B,qCAAyB;AACzB,2CAA0C;AAE1C,IAAM,oBAAoB,GAAG,UAC3B,OAAgD,EAChD,MAAe;IAEf,IAAM,aAAa,GACjB,yDAAyD,CAAC;IAC5D,IAAM,2BAA2B,GAC/B,6DAA6D,CAAC;IAChE,IAAM,2BAA2B,GAAG,4FAExB,OAAO,CAAC,OAAO,mCACX,OAAO,CAAC,WAAW,gBACjC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAiB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E,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,MAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) => {\n const rawImportStmt =\n 'import { sentryVitePlugin } from \"@sentry/vite-plugin\";';\n const rawGenerateSourceMapsOption =\n 'sourcemap: true, // Source map generation must be turned on';\n const rawSentryVitePluginFunction = `sentryVitePlugin({\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 const importStmt = colors ? chalk.greenBright(rawImportStmt) : rawImportStmt;\n const generateSourceMapsOption = colors\n ? chalk.greenBright(rawGenerateSourceMapsOption)\n : rawGenerateSourceMapsOption;\n const sentryVitePluginFunction = colors\n ? chalk.greenBright(rawSentryVitePluginFunction)\n : rawSentryVitePluginFunction;\n\n const code = getViteConfigContent(\n importStmt,\n generateSourceMapsOption,\n sentryVitePluginFunction,\n );\n return colors ? chalk.gray(code) : code;\n};\n\nconst getViteConfigContent = (\n importStmt: string,\n generateSourceMapsOption: string,\n sentryVitePluginFunction: string,\n) => `import { defineConfig } from \"vite\";\n${importStmt}\n\nexport default defineConfig({\n build: {\n ${generateSourceMapsOption}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${sentryVitePluginFunction}\n ],\n});\n`;\n\nexport const configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ??\n (await askForToolConfigPath('Vite', 'vite.config.js'));\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'vite.config.js'),\n getViteConfigSnippet(options, false),\n 'More information about vite 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 viteConfigPath ? '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(viteConfigPath || 'vite.config.js'),\n getViteConfigSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite 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 const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAqD;AACrD,4EAA4E;AAC5E,4CAAiD;AAIjD,6CAAiC;AAEjC,mDAAuC;AAEvC,gDAA0B;AAC1B,uDASiC;AACjC,yDAA+D;AAM/D,mDAAmE;AAEnE,yCAA6B;AAC7B,qCAAyB;AACzB,2CAA0C;AAE1C,IAAM,oBAAoB,GAAG,UAC3B,OAAgD,EAChD,MAAe;IAEf,OAAA,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QACzC,OAAA,SAAS,CAAC,kDACZ,IAAI,CAAC,yDAAyD,CAAC,gEAI3D,IAAI,CAAC,6DAA6D,CAAC,kGAInE,IAAI,CAAC,4FAEG,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,gBAEL,CAAC;IAjBD,CAiBC,CACF;AAnBD,CAmBC,CAAC;AAEG,IAAM,mBAAmB,GAC9B,UAAO,OAAO;;;;;;;gBACN,KAAA,4BAAc,CAAA;;oBAClB,WAAW,EAAE,qBAAqB;;gBAChB,KAAA,kCAAmB,CAAA;sBACnC,qBAAqB;gBACrB,qBAAM,IAAA,+BAAiB,GAAE,EAAA;oBAJ7B,qBAAM,mBAEJ,mBAAgB,GAAE,4BAEhB,SAAyB,GAC1B;6BACD,EAAA;;gBANF,SAME,CAAC;4BAGD,IAAA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,IAAiB,EAAE;gBAAxC,IAAM,WAAW,SAAA;gBACpB,IACE,WAAW,CAAC,IAAI,KAAK,oBAAoB;oBACzC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,YAAY;oBACpC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,MAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\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';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`import { defineConfig } from \"vite\";\n${plus('import { sentryVitePlugin } from \"@sentry/vite-plugin\";')}\n\nexport default defineConfig({\n build: {\n ${plus('sourcemap: true, // Source map generation must be turned on')}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${plus(`sentryVitePlugin({\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 configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ??\n (await askForToolConfigPath('Vite', 'vite.config.js'));\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'vite.config.js'),\n getViteConfigSnippet(options, false),\n 'More information about vite 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 viteConfigPath ? '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(viteConfigPath || 'vite.config.js'),\n getViteConfigSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite 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 const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
|
|
@@ -84,20 +84,10 @@ var package_json_1 = require("../../utils/package-json");
|
|
|
84
84
|
var ast_utils_1 = require("../../utils/ast-utils");
|
|
85
85
|
var debug_1 = require("../../utils/debug");
|
|
86
86
|
var getCodeSnippet = function (options, colors) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var importStmt = colors ? chalk_1.default.greenBright(rawImportStmt) : rawImportStmt;
|
|
91
|
-
var generateSourceMapsOption = colors
|
|
92
|
-
? chalk_1.default.greenBright(rawGenerateSourceMapsOption)
|
|
93
|
-
: rawGenerateSourceMapsOption;
|
|
94
|
-
var sentryWebpackPluginFunction = colors
|
|
95
|
-
? chalk_1.default.greenBright(rawSentryWebpackPluginFunction)
|
|
96
|
-
: rawSentryWebpackPluginFunction;
|
|
97
|
-
var code = getWebpackConfigContent(importStmt, generateSourceMapsOption, sentryWebpackPluginFunction);
|
|
98
|
-
return colors ? chalk_1.default.gray(code) : code;
|
|
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
|
+
});
|
|
99
90
|
};
|
|
100
|
-
var getWebpackConfigContent = function (importStmt, generateSourceMapsOption, sentryWebpackPluginFunction) { return "".concat(importStmt, "\n\nmodule.exports = {\n // ... other options\n ").concat(generateSourceMapsOption, ",\n plugins: [\n // Put the Sentry Webpack plugin after all other plugins\n ").concat(sentryWebpackPluginFunction, ",\n ],\n}\n"); };
|
|
101
91
|
var configureWebPackPlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
102
92
|
var _a, _b, _c, webpackConfigPath, _d, successfullyAdded;
|
|
103
93
|
var _e;
|