@sentry/wizard
Version:
Sentry wizard helping you to configure your project
276 lines • 14.9 kB
JavaScript
"use strict";
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.ensureMinimumSdkVersionIsInstalled = 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 semver_1 = require("semver");
var clack_utils_1 = require("../../utils/clack-utils");
var Sentry = __importStar(require("@sentry/node"));
var package_json_1 = require("../../utils/package-json");
var MINIMUM_DEBUG_ID_SDK_VERSION = '7.47.0';
// This array is orderd by the SDKs we want to check for first.
// The reason is that some SDKs depend on others and some users might
// have added the dependencies to their package.json. We want to make sure
// that we actually detect the "top-level" SDK first.
var SENTRY_SDK_PACKAGE_NAMES = [
// SDKs using other framework SDKs need to be checked first
'@sentry/gatsby',
'@sentry/nextjs',
'@sentry/remix',
'@sentry/sveltekit',
// Framework SDKs
'@sentry/angular',
'@sentry/angular-ivy',
'@sentry/ember',
'@sentry/react',
'@sentry/svelte',
'@sentry/vue',
'@sentry/serverless',
// Base SDKs
'@sentry/browser',
'@sentry/node',
];
/**
* Check for a minimum SDK version and prompt the user to upgrade if necessary.
* We distinguish between 4 cases here:
*
* 1. Users didn't install any SDK yet
* -> We tell them to install an SDK and then continue with the wizard
* 2. Users installed an SDK in the range >=7.47.0
* -> All good, no need to do anything!
* 3. Users installed an SDK in the range >=7.0.0 <= 7.46.0
* -> We ask if they want to auto-update to the latest version
* 4. Users installed an SDK in the range <7.x
* -> We tell users to manually upgrade (migrate between majors)
*/
function ensureMinimumSdkVersionIsInstalled() {
return __awaiter(this, void 0, void 0, function () {
var installedSdkPackage, _a, _b, installedSdkName, installedSdkVersionOrRange, minInstalledVersion, hasDebugIdCompatibleSdkVersion, hasV7SdkVersion;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = package_json_1.findInstalledPackageFromList;
_b = [SENTRY_SDK_PACKAGE_NAMES];
return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
case 1:
installedSdkPackage = _a.apply(void 0, _b.concat([_c.sent()]));
if (!!installedSdkPackage) return [3 /*break*/, 3];
return [4 /*yield*/, handleNoSdkInstalled()];
case 2: return [2 /*return*/, _c.sent()];
case 3:
installedSdkName = installedSdkPackage.name, installedSdkVersionOrRange = installedSdkPackage.version;
Sentry.setTag('installed-sdk', installedSdkName);
minInstalledVersion = getMinInstalledVersion(installedSdkVersionOrRange, installedSdkName);
if (!minInstalledVersion) {
// This is handled in the getMinInstalledVersion function
return [2 /*return*/];
}
hasDebugIdCompatibleSdkVersion = (0, semver_1.satisfies)(minInstalledVersion, ">=".concat(MINIMUM_DEBUG_ID_SDK_VERSION));
// Case 2:
if (hasDebugIdCompatibleSdkVersion) {
Sentry.setTag('initial-sdk-version', '>=7.47.0');
return [2 /*return*/];
}
hasV7SdkVersion = (0, semver_1.satisfies)(minInstalledVersion, '>=7.0.0');
prompts_1.default.log.warn("".concat(chalk_1.default.yellowBright("It seems like you're using an outdated version (".concat(installedSdkVersionOrRange, ") of the ").concat(chalk_1.default.bold(installedSdkName), " SDK.")), "\nUploading source maps is easiest with an SDK from version ").concat(chalk_1.default.bold(MINIMUM_DEBUG_ID_SDK_VERSION), " or newer. \n"));
if (!hasV7SdkVersion) return [3 /*break*/, 5];
return [4 /*yield*/, handleAutoUpdateSdk(installedSdkName)];
case 4:
_c.sent();
return [2 /*return*/];
case 5:
// Case 4:
return [4 /*yield*/, handleManuallyUpdateSdk(minInstalledVersion)];
case 6:
// Case 4:
_c.sent();
return [2 /*return*/];
}
});
});
}
exports.ensureMinimumSdkVersionIsInstalled = ensureMinimumSdkVersionIsInstalled;
function handleManuallyUpdateSdk(minInstalledVersion) {
return __awaiter(this, void 0, void 0, function () {
var didUpdate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Sentry.setTag('initial-sdk-version', "".concat((0, semver_1.satisfies)(minInstalledVersion, '>=6.0.0') ? '6.x' : '<6.0.0'));
prompts_1.default.log
.info("When upgrading from a version older than 7.0.0, make sure to follow the migration guide:\nhttps://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#upgrading-from-6x-to-7x\n");
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
message: 'Did you update your SDK to the latest version?',
options: [
{
label: 'Yes!',
value: true,
},
{
label: "No, I'll do it later...",
value: false,
hint: chalk_1.default.yellow("Remember to update your SDK to at least ".concat(MINIMUM_DEBUG_ID_SDK_VERSION, ".")),
},
],
initialValue: true,
}))];
case 1:
didUpdate = _a.sent();
Sentry.setTag('resolved-sdk-status', didUpdate ? 'updated-manually' : 'update-later');
return [2 /*return*/];
}
});
});
}
function handleAutoUpdateSdk(packageName) {
return __awaiter(this, void 0, void 0, function () {
var shouldUpdate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Sentry.setTag('initial-sdk-version', '>=7.0.0 <7.47.0');
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
message: 'Do you want to automatically update your SDK to the latest version?',
options: [
{
label: 'Yes!',
value: true,
hint: chalk_1.default.green('Recommended'),
},
{
label: "No, I'll do it later...",
value: false,
hint: chalk_1.default.yellow("Remember to update your SDK to at least ".concat(MINIMUM_DEBUG_ID_SDK_VERSION, ".")),
},
],
initialValue: true,
}))];
case 1:
shouldUpdate = _a.sent();
if (!shouldUpdate) return [3 /*break*/, 3];
return [4 /*yield*/, (0, clack_utils_1.installPackage)({
packageName: packageName,
alreadyInstalled: true,
askBeforeUpdating: false, // we already did this above
})];
case 2:
_a.sent();
_a.label = 3;
case 3:
Sentry.setTag('resolved-sdk-status', shouldUpdate ? 'updated-automatically' : 'update-later');
return [2 /*return*/];
}
});
});
}
function handleNoSdkInstalled() {
return __awaiter(this, void 0, void 0, function () {
var installedSDK;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Sentry.setTag('initial-sdk-version', 'none');
Sentry.setTag('installed-sdk', 'none');
prompts_1.default.log.warn("".concat(chalk_1.default.yellowBright("It seems like you didn't yet install a Sentry SDK in your project."), "\nWe recommend setting up the SDK before continuing with the source maps wizard.\n\n").concat(chalk_1.default.dim("Take a look at our docs to get started:\nhttps://docs.sentry.io/")));
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
message: 'Did you set up your Sentry SDK?',
options: [
{ label: 'Yes, continue!', value: true },
{
label: "I'll do it later...",
value: false,
hint: chalk_1.default.yellow('You need to set up an SDK before you can use Sentry'),
},
],
initialValue: true,
}))];
case 1:
installedSDK = _a.sent();
Sentry.setTag('resolved-sdk-status', installedSDK ? 'installed-manually' : 'install-later');
return [2 /*return*/];
}
});
});
}
function getMinInstalledVersion(installedSdkVersionOrRange, installedSdkName) {
var _a;
try {
// If `minVersion` is unable to parse the version it will throw an error
// However, it will also return `null` if the parameter is undefined, which
// we explicitly checked before but the typing doesn't know that.
var minInstalledVersion = (_a = (0, semver_1.minVersion)(installedSdkVersionOrRange)) === null || _a === void 0 ? void 0 : _a.version;
if (minInstalledVersion) {
return minInstalledVersion;
}
}
catch (_b) {
// handling this, along with the `null` case below
}
Sentry.setTag('initial-sdk-version', 'unknown');
prompts_1.default.log.warn("".concat(chalk_1.default.yellow("Could not parse the version of your installed SDK (\"".concat(installedSdkName, "\": \"").concat(installedSdkVersionOrRange, "\")")), "\n\nPlease make sure that your Sentry SDK is updated to version ").concat(chalk_1.default.bold(MINIMUM_DEBUG_ID_SDK_VERSION), " or newer.\n "));
return undefined;
}
//# sourceMappingURL=sdk-version.js.map