UNPKG

@socketsecurity/lib

Version:

Core utilities and infrastructure for Socket.dev security tools

193 lines (192 loc) 6.09 kB
"use strict"; /* Socket Lib - Built with esbuild */ var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var paths_exports = {}; __export(paths_exports, { getOsHomeDir: () => getOsHomeDir, getOsTmpDir: () => getOsTmpDir, getSocketAppCacheDir: () => getSocketAppCacheDir, getSocketAppCacheTtlDir: () => getSocketAppCacheTtlDir, getSocketAppDir: () => getSocketAppDir, getSocketCacacheDir: () => getSocketCacacheDir, getSocketCliDir: () => getSocketCliDir, getSocketDlxDir: () => getSocketDlxDir, getSocketHomePath: () => getSocketHomePath, getSocketRegistryDir: () => getSocketRegistryDir, getSocketRegistryGithubCacheDir: () => getSocketRegistryGithubCacheDir, getSocketUserDir: () => getSocketUserDir, getUserHomeDir: () => getUserHomeDir, invalidateCache: () => invalidateCache }); module.exports = __toCommonJS(paths_exports); var os = __toESM(require("os")); var path = __toESM(require("path")); var import_home = require("./env/home"); var import_socket = require("./env/socket"); var import_windows = require("./env/windows"); var import_path = require("./path"); var import_rewire = require("./paths/rewire"); function getOsHomeDir() { return (0, import_rewire.getPathValue)("homedir", () => os.homedir()); } function getOsTmpDir() { return (0, import_rewire.getPathValue)("tmpdir", () => os.tmpdir()); } function getSocketHomePath() { return getSocketUserDir(); } let _cachedSocketUserDir; function getSocketUserDir() { if (_cachedSocketUserDir === void 0) { _cachedSocketUserDir = (0, import_path.normalizePath)( path.join( getUserHomeDir(), /*@__INLINE__*/ require("./constants/paths").DOT_SOCKET_DIR ) ); } return _cachedSocketUserDir; } function getSocketAppDir(appName) { return (0, import_path.normalizePath)( path.join( getSocketUserDir(), `${/*@__INLINE__*/ require("./constants/socket").SOCKET_APP_PREFIX}${appName}` ) ); } let _cachedSocketCacacheDir; function getSocketCacacheDir() { if (_cachedSocketCacacheDir === void 0) { if ((0, import_socket.getSocketCacacheDir)()) { _cachedSocketCacacheDir = (0, import_path.normalizePath)( (0, import_socket.getSocketCacacheDir)() ); } else { _cachedSocketCacacheDir = (0, import_path.normalizePath)( path.join( getSocketUserDir(), `${/*@__INLINE__*/ require("./constants/socket").SOCKET_APP_PREFIX}cacache` ) ); } } return _cachedSocketCacacheDir; } function getSocketDlxDir() { if ((0, import_socket.getSocketDlxDirEnv)()) { return (0, import_path.normalizePath)((0, import_socket.getSocketDlxDirEnv)()); } return (0, import_path.normalizePath)( path.join( getSocketUserDir(), `${/*@__INLINE__*/ require("./constants/socket").SOCKET_APP_PREFIX}${/*@__INLINE__*/ require("./constants/socket").SOCKET_DLX_APP_NAME}` ) ); } function getSocketAppCacheDir(appName) { return (0, import_path.normalizePath)( path.join( getSocketAppDir(appName), /*@__INLINE__*/ require("./constants/paths").CACHE_DIR ) ); } function getSocketAppCacheTtlDir(appName) { return (0, import_path.normalizePath)( path.join( getSocketAppCacheDir(appName), /*@__INLINE__*/ require("./constants/paths").CACHE_TTL_DIR ) ); } function getSocketCliDir() { return getSocketAppDir( /*@__INLINE__*/ require("./constants/socket").SOCKET_CLI_APP_NAME ); } function getSocketRegistryDir() { return getSocketAppDir( /*@__INLINE__*/ require("./constants/socket").SOCKET_REGISTRY_APP_NAME ); } function getSocketRegistryGithubCacheDir() { return (0, import_path.normalizePath)( path.join( getSocketAppCacheTtlDir( /*@__INLINE__*/ require("./constants/socket").SOCKET_REGISTRY_APP_NAME ), /*@__INLINE__*/ require("./constants/github").CACHE_GITHUB_DIR ) ); } function getUserHomeDir() { const home = (0, import_home.getHome)(); if (home) { return home; } const userProfile = (0, import_windows.getUserprofile)(); if (userProfile) { return userProfile; } return getOsHomeDir(); } function invalidateCache() { _cachedSocketUserDir = void 0; _cachedSocketCacacheDir = void 0; } (0, import_rewire.registerCacheInvalidation)(invalidateCache); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getOsHomeDir, getOsTmpDir, getSocketAppCacheDir, getSocketAppCacheTtlDir, getSocketAppDir, getSocketCacacheDir, getSocketCliDir, getSocketDlxDir, getSocketHomePath, getSocketRegistryDir, getSocketRegistryGithubCacheDir, getSocketUserDir, getUserHomeDir, invalidateCache });