@sentry/wizard
Version:
Sentry wizard helping you to configure your project
414 lines • 23.4 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.configureCI = exports.runSourcemapsWizard = void 0;
// @ts-ignore - clack is ESM and TS complains about that. It works though
var prompts_1 = __importDefault(require("@clack/prompts"));
var chalk_1 = __importDefault(require("chalk"));
var Sentry = __importStar(require("@sentry/node"));
var clack_utils_1 = require("../utils/clack-utils");
var is_unicorn_supported_1 = require("../utils/vendor/is-unicorn-supported");
var vite_1 = require("./tools/vite");
var sentry_cli_1 = require("./tools/sentry-cli");
var webpack_1 = require("./tools/webpack");
var tsc_1 = require("./tools/tsc");
var rollup_1 = require("./tools/rollup");
var esbuild_1 = require("./tools/esbuild");
var create_react_app_1 = require("./tools/create-react-app");
var sdk_version_1 = require("./utils/sdk-version");
var telemetry_1 = require("../telemetry");
var other_wizards_1 = require("./utils/other-wizards");
var angular_1 = require("./tools/angular");
var detect_tool_1 = require("./utils/detect-tool");
var nextjs_1 = require("./tools/nextjs");
var remix_1 = require("./tools/remix");
var package_manager_1 = require("../utils/package-manager");
var url_1 = require("../utils/url");
function runSourcemapsWizard(options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, telemetry_1.withTelemetry)({
enabled: options.telemetryEnabled,
integration: 'sourcemaps',
}, function () { return runSourcemapsWizardWithTelemetry(options); })];
});
});
}
exports.runSourcemapsWizard = runSourcemapsWizard;
function runSourcemapsWizardWithTelemetry(options) {
return __awaiter(this, void 0, void 0, function () {
var moreSuitableWizard, _a, selfHosted, selectedProject, sentryUrl, authToken, wizardOptionsWithPreSelectedProject, selectedTool;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
(0, clack_utils_1.printWelcome)({
wizardName: 'Sentry Source Maps Upload Configuration Wizard',
message: "This wizard will help you upload source maps to Sentry as part of your build.\nThank you for using Sentry :)".concat(options.telemetryEnabled
? "\n\n(This setup wizard sends telemetry data and crash reports to Sentry.\nYou can turn this off by running the wizard with the '--disable-telemetry' flag.)"
: ''),
promoCode: options.promoCode,
});
return [4 /*yield*/, (0, telemetry_1.traceStep)('check-framework-wizard', other_wizards_1.checkIfMoreSuitableWizardExistsAndAskForRedirect)];
case 1:
moreSuitableWizard = _b.sent();
if (!moreSuitableWizard) return [3 /*break*/, 3];
return [4 /*yield*/, (0, telemetry_1.traceStep)('run-framework-wizard', function () { return moreSuitableWizard(options); })];
case 2:
_b.sent();
return [2 /*return*/];
case 3: return [4 /*yield*/, (0, clack_utils_1.confirmContinueIfNoOrDirtyGitRepo)()];
case 4:
_b.sent();
return [4 /*yield*/, (0, telemetry_1.traceStep)('check-sdk-version', sdk_version_1.ensureMinimumSdkVersionIsInstalled)];
case 5:
_b.sent();
return [4 /*yield*/, (0, clack_utils_1.getOrAskForProjectData)(options)];
case 6:
_a = _b.sent(), selfHosted = _a.selfHosted, selectedProject = _a.selectedProject, sentryUrl = _a.sentryUrl, authToken = _a.authToken;
wizardOptionsWithPreSelectedProject = __assign(__assign({}, options), { preSelectedProject: {
project: selectedProject,
authToken: authToken,
selfHosted: selfHosted,
} });
return [4 /*yield*/, (0, telemetry_1.traceStep)('select-tool', askForUsedBundlerTool)];
case 7:
selectedTool = _b.sent();
Sentry.setTag('selected-tool', selectedTool);
if (!(selectedTool === 'no-tool')) return [3 /*break*/, 9];
prompts_1.default.log.info("No Problem! But in this case, there's nothing to configure :)");
return [4 /*yield*/, (0, clack_utils_1.abort)('Exiting, have a great day!', 0)];
case 8:
_b.sent();
return [2 /*return*/];
case 9: return [4 /*yield*/, (0, telemetry_1.traceStep)('tool-setup', function () {
return startToolSetupFlow(selectedTool, {
orgSlug: selectedProject.organization.slug,
projectSlug: selectedProject.slug,
selfHosted: selfHosted,
url: sentryUrl,
authToken: authToken,
}, wizardOptionsWithPreSelectedProject);
})];
case 10:
_b.sent();
return [4 /*yield*/, (0, telemetry_1.traceStep)('ci-setup', function () { return configureCI(selectedTool, authToken); })];
case 11:
_b.sent();
(0, telemetry_1.traceStep)('outro', function () {
return printOutro(sentryUrl, selectedProject.organization.slug, selectedProject.id);
});
return [2 /*return*/];
}
});
});
}
function askForUsedBundlerTool() {
return __awaiter(this, void 0, void 0, function () {
var selectedTool, _a, _b, _c;
var _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_a = clack_utils_1.abortIfCancelled;
_c = (_b = prompts_1.default).select;
_d = {
message: 'Which framework, bundler or build tool are you using?',
options: [
{
label: 'Angular',
value: 'angular',
hint: 'Select this option if you are using Angular.',
},
{
label: 'Create React App',
value: 'create-react-app',
hint: 'Select this option if you set up your app with Create React App.',
},
{
label: 'Next.js',
value: 'nextjs',
hint: 'Select this option if you want to set up source maps in a NextJS project.',
},
{
label: 'Remix',
value: 'remix',
hint: 'Select this option if you want to set up source maps in a Remix project.',
},
{
label: 'Webpack',
value: 'webpack',
hint: 'Select this if you are using Webpack and you have access to your Webpack config.',
},
{
label: 'Vite',
value: 'vite',
hint: 'Select this if you are using Vite and you have access to your Vite config.',
},
{
label: 'esbuild',
value: 'esbuild',
hint: 'Select this if you are using esbuild and you have access to your esbuild config.',
},
{
label: 'Rollup',
value: 'rollup',
hint: 'Select this if you are using Rollup and you have access to your Rollup config.',
},
{
label: 'tsc',
value: 'tsc',
hint: 'Configure source maps when using tsc as build tool',
},
{
label: 'I use another tool',
value: 'sentry-cli',
hint: 'This will configure source maps upload for you using sentry-cli',
},
{
label: "I don't minify, transpile or bundle my code",
value: 'no-tool',
hint: 'This will exit the wizard',
},
]
};
return [4 /*yield*/, (0, detect_tool_1.detectUsedTool)()];
case 1: return [4 /*yield*/, _a.apply(void 0, [_c.apply(_b, [(_d.initialValue = _e.sent(),
_d)])])];
case 2:
selectedTool = _e.sent();
return [2 /*return*/, selectedTool];
}
});
});
}
function startToolSetupFlow(selctedTool, options, wizardOptions) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = selctedTool;
switch (_a) {
case 'webpack': return [3 /*break*/, 1];
case 'vite': return [3 /*break*/, 3];
case 'esbuild': return [3 /*break*/, 5];
case 'rollup': return [3 /*break*/, 7];
case 'tsc': return [3 /*break*/, 9];
case 'create-react-app': return [3 /*break*/, 11];
case 'angular': return [3 /*break*/, 13];
case 'nextjs': return [3 /*break*/, 15];
case 'remix': return [3 /*break*/, 17];
}
return [3 /*break*/, 19];
case 1: return [4 /*yield*/, (0, webpack_1.configureWebPackPlugin)(options)];
case 2:
_b.sent();
return [3 /*break*/, 21];
case 3: return [4 /*yield*/, (0, vite_1.configureVitePlugin)(options)];
case 4:
_b.sent();
return [3 /*break*/, 21];
case 5: return [4 /*yield*/, (0, esbuild_1.configureEsbuildPlugin)(options)];
case 6:
_b.sent();
return [3 /*break*/, 21];
case 7: return [4 /*yield*/, (0, rollup_1.configureRollupPlugin)(options)];
case 8:
_b.sent();
return [3 /*break*/, 21];
case 9: return [4 /*yield*/, (0, sentry_cli_1.configureSentryCLI)(options, tsc_1.configureTscSourcemapGenerationFlow)];
case 10:
_b.sent();
return [3 /*break*/, 21];
case 11: return [4 /*yield*/, (0, sentry_cli_1.configureSentryCLI)(options, create_react_app_1.configureCRASourcemapGenerationFlow)];
case 12:
_b.sent();
return [3 /*break*/, 21];
case 13: return [4 /*yield*/, (0, sentry_cli_1.configureSentryCLI)(options, angular_1.configureAngularSourcemapGenerationFlow)];
case 14:
_b.sent();
return [3 /*break*/, 21];
case 15: return [4 /*yield*/, (0, nextjs_1.configureNextJsSourceMapsUpload)(options, wizardOptions)];
case 16:
_b.sent();
return [3 /*break*/, 21];
case 17: return [4 /*yield*/, (0, remix_1.configureRemixSourceMapsUpload)(options, wizardOptions)];
case 18:
_b.sent();
return [3 /*break*/, 21];
case 19: return [4 /*yield*/, (0, sentry_cli_1.configureSentryCLI)(options)];
case 20:
_b.sent();
return [3 /*break*/, 21];
case 21: return [2 /*return*/];
}
});
});
}
function configureCI(selectedTool, authToken) {
return __awaiter(this, void 0, void 0, function () {
var isUsingCI, isCliBasedFlowTool, usesSentryCliRc, authTokenFile;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
message: "Are you using a CI/CD tool to build and deploy your application?",
options: [
{
label: 'Yes',
hint: 'I use a tool like GitHub Actions, GitLab, CircleCI, TravisCI, Jenkins, Vercel, ...',
value: true,
},
{
label: 'No',
hint: 'I build and deploy my application manually',
value: false,
},
],
initialValue: true,
}))];
case 1:
isUsingCI = _a.sent();
Sentry.setTag('using-ci', isUsingCI);
isCliBasedFlowTool = [
'sentry-cli',
'tsc',
'angular',
'create-react-app',
].includes(selectedTool);
usesSentryCliRc = selectedTool === 'nextjs';
authTokenFile = isCliBasedFlowTool || usesSentryCliRc
? clack_utils_1.SENTRY_CLI_RC_FILE
: clack_utils_1.SENTRY_DOT_ENV_FILE;
if (!isUsingCI) {
prompts_1.default.log.info("No Problem! Just make sure that the Sentry auth token from ".concat(chalk_1.default.cyan(authTokenFile), " is available whenever you build and deploy your app."));
return [2 /*return*/];
}
if (!isCliBasedFlowTool) return [3 /*break*/, 3];
return [4 /*yield*/, (0, telemetry_1.traceStep)('ci-npm-script-setup', sentry_cli_1.setupNpmScriptInCI)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [4 /*yield*/, (0, telemetry_1.traceStep)('ci-auth-token-setup', function () { return setupAuthTokenInCI(authToken); })];
case 4:
_a.sent();
return [2 /*return*/];
}
});
});
}
exports.configureCI = configureCI;
function setupAuthTokenInCI(authToken) {
return __awaiter(this, void 0, void 0, function () {
var addedEnvVarToCI;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prompts_1.default.log.step('Add the Sentry authentication token as an environment variable to your CI setup:');
// Intentially logging directly to console here so that the code can be copied/pasted directly
// eslint-disable-next-line no-console
console.log(chalk_1.default.greenBright("\nSENTRY_AUTH_TOKEN=".concat(authToken, "\n")));
prompts_1.default.log.warn(chalk_1.default.yellow('DO NOT commit this auth token to your repository!'));
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
message: 'Did you configure CI as shown above?',
options: [
{ label: 'Yes, continue!', value: true },
{
label: "I'll do it later...",
value: false,
hint: chalk_1.default.yellow('You need to set the auth token to upload source maps in CI'),
},
],
initialValue: true,
}))];
case 1:
addedEnvVarToCI = _a.sent();
Sentry.setTag('added-env-var-to-ci', addedEnvVarToCI);
if (!addedEnvVarToCI) {
prompts_1.default.log.info("Don't forget! :)");
}
return [2 /*return*/];
}
});
});
}
function printOutro(url, orgSlug, projectId) {
var _a;
var packageManager = (0, package_manager_1.detectPackageManger)();
var buildCommand = (_a = packageManager === null || packageManager === void 0 ? void 0 : packageManager.buildCommand) !== null && _a !== void 0 ? _a : 'npm run build';
var issueStreamUrl = (0, url_1.getIssueStreamUrl)({ url: url, orgSlug: orgSlug, projectId: projectId });
var arrow = (0, is_unicorn_supported_1.isUnicodeSupported)() ? '→' : '->';
prompts_1.default.outro("".concat(chalk_1.default.green("That's it - everything is set up!"), "\n\n ").concat(chalk_1.default.cyan("Test and validate your setup locally with the following Steps:\n\n 1. Build your application in ".concat(chalk_1.default.bold('production mode'), ".\n ").concat(chalk_1.default.gray("".concat(arrow, " For example, run ").concat(chalk_1.default.bold(buildCommand), ".")), "\n ").concat(chalk_1.default.gray("".concat(arrow, " You should see source map upload logs in your console.")), "\n 2. Run your application and throw a test error.\n ").concat(chalk_1.default.gray("".concat(arrow, " The error should appear in Sentry:")), "\n ").concat(chalk_1.default.gray("".concat(arrow, " ").concat(issueStreamUrl)), "\n 3. Open the error in Sentry and verify that it's source-mapped.\n ").concat(chalk_1.default.gray("".concat(arrow, " The stack trace should show your original source code.")), "\n ")), "\n ").concat(chalk_1.default.dim("If you encounter any issues, please refer to the Troubleshooting Guide:\n https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js\n\n If the guide doesn't help or you encounter a bug, please let us know:\n https://github.com/getsentry/sentry-javascript/issues"), "\n"));
}
//# sourceMappingURL=sourcemaps-wizard.js.map