UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

89 lines 4.39 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; var path = __importStar(require("path")); // @ts-expect-error - clack is ESM and TS complains about that. It works though var prompts_1 = __importDefault(require("@clack/prompts")); var chalk_1 = __importDefault(require("chalk")); var package_json_1 = require("../utils/package-json"); exports.POSSIBLE_SERVER_INSTRUMENTATION_PATHS = [ './instrumentation', './instrumentation.server', ]; function hasSentryContent(fileName, fileContent, expectedContent) { if (expectedContent === void 0) { expectedContent = '@sentry/remix'; } var includesContent = fileContent.includes(expectedContent); if (includesContent) { prompts_1.default.log.warn("File ".concat(chalk_1.default.cyan(path.basename(fileName)), " already contains ").concat(expectedContent, ".\nSkipping adding Sentry functionality to ").concat(chalk_1.default.cyan(path.basename(fileName)), ".")); } return includesContent; } exports.hasSentryContent = hasSentryContent; function serverHasInstrumentationImport(serverFileName, serverFileContent) { var includesServerInstrumentationImport = exports.POSSIBLE_SERVER_INSTRUMENTATION_PATHS.some(function (path) { return serverFileContent.includes(path); }); if (includesServerInstrumentationImport) { prompts_1.default.log.warn("File ".concat(chalk_1.default.cyan(path.basename(serverFileName)), " already contains instrumentation import.\nSkipping adding instrumentation functionality to ").concat(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 (var 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 (var 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