@sentry/wizard
Version:
Sentry wizard helping you to configure your project
65 lines • 2.89 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAfterImportsInsertionIndex = exports.getInitCallArgs = exports.insertInitCall = exports.updateAppEntryMod = void 0;
const magicast_1 = require("magicast");
function updateAppEntryMod(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
originalAppModuleMod, dsn, selectedFeatures) {
originalAppModuleMod.imports.$add({
from: '@sentry/angular',
imported: '*',
local: 'Sentry',
});
insertInitCall(originalAppModuleMod, dsn, selectedFeatures);
return originalAppModuleMod;
}
exports.updateAppEntryMod = updateAppEntryMod;
function insertInitCall(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
originalAppModuleMod, dsn, selectedFeatures) {
const initCallArgs = getInitCallArgs(dsn, selectedFeatures);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- builders return Proxified which defaults to any
const initCall = magicast_1.builders.functionCall('Sentry.init', initCallArgs);
const originalAppModuleModAst = originalAppModuleMod.$ast;
const initCallInsertionIndex = getAfterImportsInsertionIndex(originalAppModuleModAst);
originalAppModuleModAst.body.splice(initCallInsertionIndex, 0,
// @ts-expect-error - string works here because the AST is proxified by magicast
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- builders return Proxified which defaults to any.
(0, magicast_1.generateCode)(initCall).code);
}
exports.insertInitCall = insertInitCall;
function getInitCallArgs(dsn, selectedFeatures) {
const initCallArgs = {
dsn,
};
if (selectedFeatures.replay || selectedFeatures.performance) {
initCallArgs.integrations = [];
if (selectedFeatures.performance) {
initCallArgs.integrations.push(magicast_1.builders.functionCall('Sentry.browserTracingIntegration'));
initCallArgs.tracesSampleRate = 1.0;
}
if (selectedFeatures.replay) {
initCallArgs.integrations.push(magicast_1.builders.functionCall('Sentry.replayIntegration'));
initCallArgs.replaysSessionSampleRate = 0.1;
initCallArgs.replaysOnErrorSampleRate = 1.0;
}
}
if (selectedFeatures.logs) {
initCallArgs.enableLogs = true;
}
return initCallArgs;
}
exports.getInitCallArgs = getInitCallArgs;
/**
* We want to insert the handleError function just after all imports
*/
function getAfterImportsInsertionIndex(originalEntryServerModAST) {
for (let x = originalEntryServerModAST.body.length - 1; x >= 0; x--) {
if (originalEntryServerModAST.body[x].type === 'ImportDeclaration') {
return x + 1;
}
}
return 0;
}
exports.getAfterImportsInsertionIndex = getAfterImportsInsertionIndex;
//# sourceMappingURL=main.js.map
;