UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

70 lines 3.56 kB
"use strict"; /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ 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.wrapAppWithSentry = void 0; const recast = __importStar(require("recast")); // @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"); function wrapAppWithSentry(rootRouteAst, rootFileName) { rootRouteAst.imports.$add({ from: '@sentry/remix', imported: 'withSentry', local: 'withSentry', }); recast.visit(rootRouteAst.$ast, { visitExportDefaultDeclaration(path) { if (path.value.declaration.type === 'FunctionDeclaration') { // Move the function declaration just before the default export path.insertBefore(path.value.declaration); // Get the name of the function to be wrapped const functionName = path.value.declaration.id.name; // Create the wrapped function call const functionCall = recast.types.builders.callExpression(recast.types.builders.identifier('withSentry'), [recast.types.builders.identifier(functionName)]); // Replace the default export with the wrapped function call path.value.declaration = functionCall; } else if (path.value.declaration.type === 'Identifier') { const rootRouteExport = rootRouteAst.exports.default; const expressionToWrap = (0, magicast_1.generateCode)(rootRouteExport.$ast).code; rootRouteAst.exports.default = magicast_1.builders.raw(`withSentry(${expressionToWrap})`); } else { prompts_1.default.log.warn(chalk_1.default.yellow(`Couldn't instrument ${chalk_1.default.bold(rootFileName)} automatically. Wrap your default export with: ${chalk_1.default.dim('withSentry()')}\n`)); } this.traverse(path); }, }); } exports.wrapAppWithSentry = wrapAppWithSentry; //# sourceMappingURL=root-common.js.map