@sentry/wizard
Version:
Sentry wizard helping you to configure your project
209 lines (207 loc) • 9.05 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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureMinimumSdkVersionIsInstalled = void 0;
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const prompts_1 = __importDefault(require("@clack/prompts"));
const chalk_1 = __importDefault(require("chalk"));
const semver_1 = require("semver");
const clack_1 = require("../../utils/clack");
const Sentry = __importStar(require("@sentry/node"));
const package_json_1 = require("../../utils/package-json");
const 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.
const SENTRY_SDK_PACKAGE_NAMES = [
// SDKs using other framework SDKs need to be checked first
'@sentry/astro',
'@sentry/gatsby',
'@sentry/nextjs',
'@sentry/nuxt',
'@sentry/react-router',
'@sentry/remix',
'@sentry/solidstart',
'@sentry/sveltekit',
'@sentry/tanstackstart-react',
// Framework SDKs
'@sentry/angular',
'@sentry/angular-ivy',
'@sentry/aws-serverless',
'@sentry/bun',
'@sentry/ember',
'@sentry/google-cloud-serverless',
'@sentry/nestjs',
'@sentry/react',
'@sentry/solid',
'@sentry/svelte',
'@sentry/vue',
'@sentry/serverless',
// Base SDKs
'@sentry/browser',
'@sentry/cloudflare',
'@sentry/node',
'@sentry/deno',
];
/**
* 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)
*/
async function ensureMinimumSdkVersionIsInstalled() {
const installedSdkPackage = (0, package_json_1.findInstalledPackageFromList)(SENTRY_SDK_PACKAGE_NAMES, await (0, clack_1.getPackageDotJson)());
// Case 1:
if (!installedSdkPackage) {
return await handleNoSdkInstalled();
}
const { name: installedSdkName, version: installedSdkVersionOrRange } = installedSdkPackage;
Sentry.setTag('installed-sdk', installedSdkName);
const minInstalledVersion = getMinInstalledVersion(installedSdkVersionOrRange, installedSdkName);
if (!minInstalledVersion) {
// This is handled in the getMinInstalledVersion function
return;
}
const hasDebugIdCompatibleSdkVersion = (0, semver_1.satisfies)(minInstalledVersion, `>=${MINIMUM_DEBUG_ID_SDK_VERSION}`);
// Case 2:
if (hasDebugIdCompatibleSdkVersion) {
Sentry.setTag('initial-sdk-version', '>=7.47.0');
return;
}
const hasV7SdkVersion = (0, semver_1.satisfies)(minInstalledVersion, '>=7.0.0');
prompts_1.default.log.warn(`${chalk_1.default.yellowBright(`It seems like you're using an outdated version (${installedSdkVersionOrRange}) of the ${chalk_1.default.bold(installedSdkName)} SDK.`)}
Uploading source maps is easiest with an SDK from version ${chalk_1.default.bold(MINIMUM_DEBUG_ID_SDK_VERSION)} or newer.
`);
// Case 3:
if (hasV7SdkVersion) {
await handleAutoUpdateSdk(installedSdkName);
return;
}
// Case 4:
await handleManuallyUpdateSdk(minInstalledVersion);
}
exports.ensureMinimumSdkVersionIsInstalled = ensureMinimumSdkVersionIsInstalled;
async function handleManuallyUpdateSdk(minInstalledVersion) {
Sentry.setTag('initial-sdk-version', `${(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:
https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#upgrading-from-6x-to-7x
`);
const didUpdate = await (0, clack_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 ${MINIMUM_DEBUG_ID_SDK_VERSION}.`),
},
],
initialValue: true,
}));
Sentry.setTag('resolved-sdk-status', didUpdate ? 'updated-manually' : 'update-later');
}
async function handleAutoUpdateSdk(packageName) {
Sentry.setTag('initial-sdk-version', '>=7.0.0 <7.47.0');
const shouldUpdate = await (0, clack_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 ${MINIMUM_DEBUG_ID_SDK_VERSION}.`),
},
],
initialValue: true,
}));
if (shouldUpdate) {
await (0, clack_1.installPackage)({
packageName,
alreadyInstalled: true,
askBeforeUpdating: false, // we already did this above
});
}
Sentry.setTag('resolved-sdk-status', shouldUpdate ? 'updated-automatically' : 'update-later');
}
async function handleNoSdkInstalled() {
Sentry.setTag('initial-sdk-version', 'none');
Sentry.setTag('installed-sdk', 'none');
prompts_1.default.log.warn(`${chalk_1.default.yellowBright(`It seems like you didn't yet install a Sentry SDK in your project.`)}
We recommend setting up the SDK before continuing with the source maps wizard.
${chalk_1.default.dim(`Take a look at our docs to get started:
https://docs.sentry.io/`)}`);
const installedSDK = await (0, clack_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,
}));
Sentry.setTag('resolved-sdk-status', installedSDK ? 'installed-manually' : 'install-later');
}
function getMinInstalledVersion(installedSdkVersionOrRange, installedSdkName) {
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.
const minInstalledVersion = (0, semver_1.minVersion)(installedSdkVersionOrRange)?.version;
if (minInstalledVersion) {
return minInstalledVersion;
}
}
catch {
// handling this, along with the `null` case below
}
Sentry.setTag('initial-sdk-version', 'unknown');
prompts_1.default.log.warn(`${chalk_1.default.yellow(`Could not parse the version of your installed SDK ("${installedSdkName}": "${installedSdkVersionOrRange}")`)}
Please make sure that your Sentry SDK is updated to version ${chalk_1.default.bold(MINIMUM_DEBUG_ID_SDK_VERSION)} or newer.
`);
return undefined;
}
//# sourceMappingURL=sdk-version.js.map
;