@sentry/wizard
Version:
Sentry wizard helping you to configure your project
217 lines • 12.6 kB
JavaScript
;
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.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");
function runSourcemapsWizard(options) {
return __awaiter(this, void 0, void 0, function () {
var _a, sentryUrl, selfHosted, _b, projects, apiKeys, selectedProject, selectedTool, addedEnvVarToCI, arrow;
return __generator(this, function (_c) {
switch (_c.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 :)\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, clack_utils_1.confirmContinueEvenThoughNoGitRepo)()];
case 1:
_c.sent();
return [4 /*yield*/, (0, clack_utils_1.askForSelfHosted)()];
case 2:
_a = _c.sent(), sentryUrl = _a.url, selfHosted = _a.selfHosted;
return [4 /*yield*/, (0, clack_utils_1.askForWizardLogin)({
promoCode: options.promoCode,
url: sentryUrl,
})];
case 3:
_b = _c.sent(), projects = _b.projects, apiKeys = _b.apiKeys;
return [4 /*yield*/, (0, clack_utils_1.askForProjectSelection)(projects)];
case 4:
selectedProject = _c.sent();
return [4 /*yield*/, askForUsedBundlerTool()];
case 5:
selectedTool = _c.sent();
Sentry.setTag('selected-tool', selectedTool);
return [4 /*yield*/, startToolSetupFlow(selectedTool, {
selfHosted: selfHosted,
orgSlug: selectedProject.organization.slug,
projectSlug: selectedProject.slug,
url: sentryUrl,
authToken: apiKeys.token,
})];
case 6:
_c.sent();
prompts_1.default.log.step('Add the Sentry auth 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(apiKeys.token, "\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 7:
addedEnvVarToCI = _c.sent();
Sentry.setTag('added-env-var-to-ci', addedEnvVarToCI);
if (!addedEnvVarToCI) {
prompts_1.default.log.info("Don't forget! :)");
}
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("Validate your setup 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, " You should see source map upload logs in your console when building")), "\n 2. Run your application and throw a test error\n ").concat(chalk_1.default.gray("".concat(arrow, " You should see the error in Sentry")), "\n 3. Open the error in Sentry and verify it's source-mapped\n ").concat(chalk_1.default.gray("".concat(arrow, " If your error is source-mapped, the stack trace should show your original source code")), "\n ")), "\n ").concat(chalk_1.default.dim("If you encounter any issues, follow our Troubleshooting Guide:\n https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js\n\n If the guide didn't help or you encountered a bug, let us know:\n https://github.com/getsentry/sentry-javascript/issues"), "\n"));
return [2 /*return*/];
}
});
});
}
exports.runSourcemapsWizard = runSourcemapsWizard;
function askForUsedBundlerTool() {
return __awaiter(this, void 0, void 0, function () {
var selectedTool;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
message: 'Which bundler or build tool are you using?',
options: [
{
label: 'Webpack',
value: 'webpack',
hint: 'Configure source maps upload using Webpack',
},
{
label: 'Vite',
value: 'vite',
hint: 'Configure source maps upload using Vite',
},
// TODO: Implement rollup and esbuild flows
// {
// label: 'esbuild',
// value: 'esbuild',
// hint: 'Configure source maps upload using esbuild',
// },
// {
// label: 'Rollup',
// value: 'rollup',
// hint: 'Configure source maps upload using Rollup',
// },
{
label: 'None of the above',
value: 'sentry-cli',
hint: 'This will configure source maps upload for you using sentry-cli',
},
],
}))];
case 1:
selectedTool = _a.sent();
return [2 /*return*/, selectedTool];
}
});
});
}
function startToolSetupFlow(selctedTool, options) {
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 'vite': return [3 /*break*/, 1];
case 'webpack': return [3 /*break*/, 3];
}
return [3 /*break*/, 5];
case 1: return [4 /*yield*/, (0, vite_1.configureVitePlugin)(options)];
case 2:
_b.sent();
return [3 /*break*/, 7];
case 3: return [4 /*yield*/, (0, webpack_1.configureWebPackPlugin)(options)];
case 4:
_b.sent();
return [3 /*break*/, 7];
case 5: return [4 /*yield*/, (0, sentry_cli_1.configureSentryCLI)(options)];
case 6:
_b.sent();
return [3 /*break*/, 7];
case 7: return [2 /*return*/];
}
});
});
}
//# sourceMappingURL=sourcemaps-wizard.js.map