UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

68 lines 3.77 kB
"use strict"; 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.downloadPrebuiltBinary = downloadPrebuiltBinary; const promises_1 = require("node:fs/promises"); const node_os_1 = __importDefault(require("node:os")); const path_1 = __importDefault(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_CACHE_DIRECTORY, REDIS_SETUP_LOCK_FILE } = constants_js_1.constants; const tarballs = { linux: { x64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-linux-x64-v7.2.8-2.tar.gz', arm64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-linux-arm64-v7.2.8-2.tar.gz', }, darwin: { x64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-macos-x64-v7.2.8-2.tar.gz', arm64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-macos-arm64-v7.2.8-2.tar.gz', }, }; function downloadAndExtractRedis(url, downloadPath) { return __awaiter(this, void 0, void 0, function* () { const tarballPath = path_1.default.join(downloadPath, 'redis-server.tar.gz'); yield index_js_2.env.downloadFile(url, tarballPath); const extractionDir = path_1.default.join(downloadPath, 'extracted'); yield index_js_2.env.ensureDirectoryExists(extractionDir); yield index_js_1.archive.extractTgz(tarballPath, extractionDir); return path_1.default.join(extractionDir, 'src', 'valkey-server'); }); } function downloadPrebuiltBinary() { return __awaiter(this, void 0, void 0, function* () { const platform = (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); if (!(yield index_js_2.env.doesPathExist(REDIS_BINARY_PATH))) { const tempDir = path_1.default.join(node_os_1.default.tmpdir(), `redis-${Date.now()}`); yield index_js_2.env.ensureDirectoryExists(tempDir); const arch = node_os_1.default.arch(); const tarball = tarballs[platform][arch]; const redisBinary = yield downloadAndExtractRedis(tarball, tempDir); yield (0, promises_1.copyFile)(redisBinary, 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=redis-binary.js.map