UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

88 lines 4.27 kB
"use strict"; 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.isHydrogenApp = exports.getAfterImportsInsertionIndex = exports.getBeforeImportsInsertionIndex = exports.serverHasInstrumentationImport = exports.hasSentryContent = exports.POSSIBLE_SERVER_INSTRUMENTATION_PATHS = void 0; 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")); const package_json_1 = require("../utils/package-json"); exports.POSSIBLE_SERVER_INSTRUMENTATION_PATHS = [ './instrumentation', './instrumentation.server', ]; function hasSentryContent(fileName, fileContent, expectedContent = '@sentry/remix') { const includesContent = fileContent.includes(expectedContent); if (includesContent) { prompts_1.default.log.warn(`File ${chalk_1.default.cyan(path.basename(fileName))} already contains ${expectedContent}. Skipping adding Sentry functionality to ${chalk_1.default.cyan(path.basename(fileName))}.`); } return includesContent; } exports.hasSentryContent = hasSentryContent; function serverHasInstrumentationImport(serverFileName, serverFileContent) { const includesServerInstrumentationImport = exports.POSSIBLE_SERVER_INSTRUMENTATION_PATHS.some((path) => serverFileContent.includes(path)); if (includesServerInstrumentationImport) { prompts_1.default.log.warn(`File ${chalk_1.default.cyan(path.basename(serverFileName))} already contains instrumentation import. Skipping adding instrumentation functionality to ${chalk_1.default.cyan(path.basename(serverFileName))}.`); } return includesServerInstrumentationImport; } exports.serverHasInstrumentationImport = serverHasInstrumentationImport; /** * We want to insert the init call on top of the file, before any other imports. */ function getBeforeImportsInsertionIndex(originalHooksModAST) { for (let x = 0; x < originalHooksModAST.body.length - 1; x++) { if (originalHooksModAST.body[x].type === 'ImportDeclaration' && // @ts-expect-error - source is available in body // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access originalHooksModAST.body[x].source.value === '@sentry/remix') { return x + 1; } } return 0; } exports.getBeforeImportsInsertionIndex = getBeforeImportsInsertionIndex; /** * 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; function isHydrogenApp(packageJson) { return (0, package_json_1.hasPackageInstalled)('@shopify/hydrogen', packageJson); } exports.isHydrogenApp = isHydrogenApp; //# sourceMappingURL=utils.js.map