UNPKG

nginx-binaries

Version:

A downloader for nginx and njs standalone binaries.

38 lines 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCacheDir = void 0; const FS = require("node:fs"); const OS = require("node:os"); const path = require("node:path"); function getCacheDir(name) { const nodeModules = findPkgNodeModules(process.cwd()); return nodeModules ? path.join(nodeModules, '.cache', name) : path.join(OS.tmpdir(), name); } exports.getCacheDir = getCacheDir; function findPkgNodeModules(cwd) { let dir = path.resolve(cwd); const rootDir = path.parse(dir).root; while (dir !== rootDir) { const nodeModules = path.join(dir, 'node_modules'); if (isWritableDir(nodeModules)) { return nodeModules; } dir = path.dirname(dir); } return null; } function isWritableDir(path) { try { if (!FS.statSync(path).isDirectory()) { return false; } FS.accessSync(path, FS.constants.W_OK); return true; } catch { return false; } } //# sourceMappingURL=cacheDir.js.map