UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

117 lines 5.76 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildRedisBinary = buildRedisBinary; const child_process_1 = require("child_process"); const promises_1 = require("node:fs/promises"); const node_os_1 = __importDefault(require("node:os")); const path = __importStar(require("path")); const index_js_1 = require("../archive/index.js"); const index_js_2 = require("../env/index.js"); const index_js_3 = require("../file-lock/index.js"); const get_supported_platform_js_1 = require("./get-supported-platform.js"); const constants_js_1 = require("./constants.js"); const { REDIS_BINARY_PATH, REDIS_SETUP_LOCK_FILE, REDIS_SERVER_VERSION, REDIS_CACHE_DIRECTORY, } = constants_js_1.constants; function compileRedis(sourceDir) { return __awaiter(this, void 0, void 0, function* () { console.log(`Compiling Redis (${sourceDir})...`); return new Promise((resolve, reject) => { const makeProcess = (0, child_process_1.spawn)('make', [], { cwd: sourceDir, stdio: 'inherit', }); const onError = (err) => { makeProcess.removeListener('close', onClose); makeProcess.kill(); reject(err); }; const onClose = (code) => { makeProcess.removeListener('error', onError); if (code === 0) { console.log('Redis compilation completed successfully.'); resolve(); } else { reject(new Error(`Redis compilation failed with exit code ${code}.`)); } }; makeProcess.once('error', onError); makeProcess.once('close', onClose); }); }); } function buildRedisBinary() { return __awaiter(this, void 0, void 0, function* () { (0, get_supported_platform_js_1.getSupportedPlatform)(); const fileLock = new index_js_3.FileLock(); try { yield index_js_2.env.ensureDirectoryExists(REDIS_CACHE_DIRECTORY); yield fileLock.acquireLock(REDIS_SETUP_LOCK_FILE); const cacheExists = yield index_js_2.env.doesPathExist(REDIS_BINARY_PATH); if (!cacheExists) { const tempDirectory = path.join(node_os_1.default.tmpdir(), String(Date.now())); yield index_js_2.env.ensureDirectoryExists(tempDirectory); const sourcePath = `https://github.com/valkey-io/valkey/archive/refs/tags/${REDIS_SERVER_VERSION}.tar.gz`; const savePath = path.join(tempDirectory, `redis-${REDIS_SERVER_VERSION}.tar.gz`); yield index_js_2.env.downloadFile(sourcePath, savePath); const extractDirectory = path.join(tempDirectory, 'extracted'); yield index_js_2.env.ensureDirectoryExists(extractDirectory); yield index_js_1.archive.extractTgz(savePath, extractDirectory); const sourceDir = path.join(extractDirectory, `valkey-${REDIS_SERVER_VERSION}`); yield compileRedis(sourceDir); const redisBin = path.join(extractDirectory, `valkey-${REDIS_SERVER_VERSION}`, 'src', 'valkey-server'); yield (0, promises_1.copyFile)(redisBin, REDIS_BINARY_PATH); yield (0, promises_1.chmod)(REDIS_BINARY_PATH, 0o755); } return REDIS_BINARY_PATH; } finally { yield fileLock.releaseLock(REDIS_SETUP_LOCK_FILE); } }); } //# sourceMappingURL=build-redis.js.map