@sentry/wizard
Version:
Sentry wizard helping you to configure your project
76 lines • 3.45 kB
JavaScript
;
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
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.instrumentClientEntry = void 0;
const recast = __importStar(require("recast"));
const path = __importStar(require("path"));
// @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"));
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
const magicast_1 = require("magicast");
const ast_utils_1 = require("../../utils/ast-utils");
const utils_1 = require("./utils");
async function instrumentClientEntry(clientEntryPath, dsn, enableTracing, enableReplay, enableLogs) {
const clientEntryAst = await (0, magicast_1.loadFile)(clientEntryPath);
if ((0, ast_utils_1.hasSentryContent)(clientEntryAst.$ast)) {
const filename = path.basename(clientEntryPath);
prompts_1.default.log.info(`Sentry initialization found in ${chalk_1.default.cyan(filename)}`);
return;
}
clientEntryAst.imports.$add({
from: '@sentry/react-router',
imported: '*',
local: 'Sentry',
});
const integrations = [];
if (enableTracing) {
integrations.push('Sentry.reactRouterTracingIntegration()');
}
if (enableReplay) {
integrations.push('Sentry.replayIntegration()');
}
const initContent = `
Sentry.init({
dsn: "${dsn}",
sendDefaultPii: true,
integrations: [${integrations.join(', ')}],
${enableLogs ? 'enableLogs: true,' : ''}
tracesSampleRate: ${enableTracing ? '1.0' : '0'},${enableTracing
? '\n tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],'
: ''}${enableReplay
? '\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,'
: ''}
});`;
clientEntryAst.$ast.body.splice((0, utils_1.getAfterImportsInsertionIndex)(clientEntryAst.$ast), 0, ...recast.parse(initContent).program.body);
await (0, magicast_1.writeFile)(clientEntryAst.$ast, clientEntryPath);
}
exports.instrumentClientEntry = instrumentClientEntry;
//# sourceMappingURL=client.entry.js.map