UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

47 lines 2.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSentryInitFile = 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 node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const templates_1 = require("./templates"); const get_entry_point_from_wrangler_config_1 = require("./wrangler/get-entry-point-from-wrangler-config"); const wrap_worker_1 = require("./wrap-worker"); /** * Creates or updates the main worker file with Sentry initialization. * Currently focused on Cloudflare Workers */ async function createSentryInitFile(dsn, selectedFeatures) { const entryPointFromConfig = (0, get_entry_point_from_wrangler_config_1.getEntryPointFromWranglerConfig)(); if (!entryPointFromConfig) { prompts_1.default.log.info('No entry point found in wrangler config, creating a new one.'); const cloudflareWorkerTemplate = (0, templates_1.getCloudflareWorkerTemplateWithHandler)(); await node_fs_1.default.promises.mkdir(node_path_1.default.join(process.cwd(), node_path_1.default.dirname(get_entry_point_from_wrangler_config_1.defaultEntryPoint)), { recursive: true, }); await node_fs_1.default.promises.writeFile(node_path_1.default.join(process.cwd(), get_entry_point_from_wrangler_config_1.defaultEntryPoint), cloudflareWorkerTemplate, { encoding: 'utf-8', flag: 'w' }); prompts_1.default.log.success(`Created ${chalk_1.default.cyan(get_entry_point_from_wrangler_config_1.defaultEntryPoint)}.`); return; } const entryPointPath = node_path_1.default.join(process.cwd(), entryPointFromConfig); if (node_fs_1.default.existsSync(entryPointPath)) { prompts_1.default.log.info(`Found existing entry point: ${chalk_1.default.cyan(entryPointFromConfig)}`); try { await (0, wrap_worker_1.wrapWorkerWithSentry)(entryPointPath, dsn, selectedFeatures); prompts_1.default.log.success(`Wrapped ${chalk_1.default.cyan(entryPointFromConfig)} with Sentry initialization.`); } catch (error) { prompts_1.default.log.warn('Failed to wrap worker automatically.'); prompts_1.default.log.step('Please wrap your handler with Sentry initialization:'); prompts_1.default.note(chalk_1.default.cyan((0, templates_1.getCloudflareWorkerTemplate)(dsn, selectedFeatures))); } return; } } exports.createSentryInitFile = createSentryInitFile; //# sourceMappingURL=sdk-setup.js.map