@socketsecurity/lib 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/abort.js +60 -1
- package/dist/abort.js.map +2 -2
- package/dist/agent.js +289 -1
- package/dist/agent.js.map +2 -2
- package/dist/ansi.js +60 -1
- package/dist/ansi.js.map +2 -2
- package/dist/argv/flags.js +282 -1
- package/dist/argv/flags.js.map +2 -2
- package/dist/argv/parse.js +171 -1
- package/dist/argv/parse.js.map +2 -2
- package/dist/arrays.js +85 -1
- package/dist/arrays.js.map +2 -2
- package/dist/bin.js +419 -5
- package/dist/bin.js.map +2 -2
- package/dist/cacache.js +139 -1
- package/dist/cacache.js.map +2 -2
- package/dist/cache-with-ttl.js +223 -1
- package/dist/cache-with-ttl.js.map +2 -2
- package/dist/constants/agents.js +126 -1
- package/dist/constants/agents.js.map +2 -2
- package/dist/constants/core.d.ts +1 -1
- package/dist/constants/core.js +57 -2
- package/dist/constants/core.js.map +3 -3
- package/dist/constants/encoding.js +48 -1
- package/dist/constants/encoding.js.map +2 -2
- package/dist/constants/github.js +30 -1
- package/dist/constants/github.js.map +2 -2
- package/dist/constants/licenses.js +66 -1
- package/dist/constants/licenses.js.map +2 -2
- package/dist/constants/node.js +185 -1
- package/dist/constants/node.js.map +2 -2
- package/dist/constants/packages.js +128 -1
- package/dist/constants/packages.js.map +2 -2
- package/dist/constants/paths.js +150 -1
- package/dist/constants/paths.js.map +2 -2
- package/dist/constants/platform.js +41 -1
- package/dist/constants/platform.js.map +2 -2
- package/dist/constants/process.js +52 -1
- package/dist/constants/process.js.map +2 -2
- package/dist/constants/socket.js +102 -1
- package/dist/constants/socket.js.map +2 -2
- package/dist/constants/testing.js +36 -1
- package/dist/constants/testing.js.map +2 -2
- package/dist/constants/time.js +39 -1
- package/dist/constants/time.js.map +2 -2
- package/dist/constants/typescript.js +54 -1
- package/dist/constants/typescript.js.map +2 -2
- package/dist/cover/code.js +135 -1
- package/dist/cover/code.js.map +2 -2
- package/dist/cover/formatters.js +101 -11
- package/dist/cover/formatters.js.map +2 -2
- package/dist/cover/type.js +63 -1
- package/dist/cover/type.js.map +2 -2
- package/dist/cover/types.js +15 -1
- package/dist/cover/types.js.map +2 -2
- package/dist/debug.js +337 -2
- package/dist/debug.js.map +2 -2
- package/dist/dlx-binary.js +408 -7
- package/dist/dlx-binary.js.map +2 -2
- package/dist/dlx-package.js +278 -7
- package/dist/dlx-package.js.map +2 -2
- package/dist/dlx.js +214 -7
- package/dist/dlx.js.map +3 -3
- package/dist/effects/pulse-frames.js +64 -1
- package/dist/effects/pulse-frames.js.map +2 -2
- package/dist/effects/text-shimmer.js +174 -1
- package/dist/effects/text-shimmer.js.map +2 -2
- package/dist/effects/types.js +15 -1
- package/dist/effects/types.js.map +2 -2
- package/dist/effects/ultra.js +61 -1
- package/dist/effects/ultra.js.map +2 -2
- package/dist/env/ci.js +31 -1
- package/dist/env/ci.js.map +2 -2
- package/dist/env/debug.js +30 -1
- package/dist/env/debug.js.map +2 -2
- package/dist/env/github.js +65 -1
- package/dist/env/github.js.map +2 -2
- package/dist/env/helpers.js +47 -1
- package/dist/env/helpers.js.map +2 -2
- package/dist/env/home.js +30 -1
- package/dist/env/home.js.map +2 -2
- package/dist/env/locale.js +40 -1
- package/dist/env/locale.js.map +2 -2
- package/dist/env/node-auth-token.js +30 -1
- package/dist/env/node-auth-token.js.map +2 -2
- package/dist/env/node-env.js +30 -1
- package/dist/env/node-env.js.map +2 -2
- package/dist/env/npm.js +50 -1
- package/dist/env/npm.js.map +2 -2
- package/dist/env/package-manager.js +73 -1
- package/dist/env/package-manager.js.map +2 -2
- package/dist/env/path.js +30 -1
- package/dist/env/path.js.map +2 -2
- package/dist/env/pre-commit.js +31 -1
- package/dist/env/pre-commit.js.map +2 -2
- package/dist/env/rewire.js +72 -1
- package/dist/env/rewire.js.map +2 -2
- package/dist/env/shell.js +30 -1
- package/dist/env/shell.js.map +2 -2
- package/dist/env/socket-cli-shadow.js +51 -1
- package/dist/env/socket-cli-shadow.js.map +2 -2
- package/dist/env/socket-cli.js +86 -1
- package/dist/env/socket-cli.js.map +2 -2
- package/dist/env/socket.js +101 -1
- package/dist/env/socket.js.map +2 -2
- package/dist/env/temp-dir.js +40 -1
- package/dist/env/temp-dir.js.map +2 -2
- package/dist/env/term.js +30 -1
- package/dist/env/term.js.map +2 -2
- package/dist/env/test.js +43 -1
- package/dist/env/test.js.map +2 -2
- package/dist/env/windows.js +45 -1
- package/dist/env/windows.js.map +2 -2
- package/dist/env/xdg.js +40 -1
- package/dist/env/xdg.js.map +2 -2
- package/dist/env.js +170 -1
- package/dist/env.js.map +2 -2
- package/dist/fs.js +670 -7
- package/dist/fs.js.map +2 -2
- package/dist/functions.js +68 -1
- package/dist/functions.js.map +2 -2
- package/dist/git.js +329 -2
- package/dist/git.js.map +2 -2
- package/dist/github.js +202 -1
- package/dist/github.js.map +2 -2
- package/dist/globs.js +149 -1
- package/dist/globs.js.map +3 -3
- package/dist/http-request.js +335 -3
- package/dist/http-request.js.map +2 -2
- package/dist/index.js +69 -1
- package/dist/index.js.map +2 -2
- package/dist/ipc.js +244 -1
- package/dist/ipc.js.map +2 -2
- package/dist/json.js +73 -1
- package/dist/json.js.map +2 -2
- package/dist/links/index.js +60 -1
- package/dist/links/index.js.map +2 -2
- package/dist/logger.js +1384 -1
- package/dist/logger.js.map +2 -2
- package/dist/maintained-node-versions.js +35 -1
- package/dist/maintained-node-versions.js.map +2 -2
- package/dist/memoization.js +210 -1
- package/dist/memoization.js.map +2 -2
- package/dist/objects.js +311 -1
- package/dist/objects.js.map +2 -2
- package/dist/packages/editable.js +356 -9
- package/dist/packages/editable.js.map +2 -2
- package/dist/packages/exports.js +162 -1
- package/dist/packages/exports.js.map +2 -2
- package/dist/packages/isolation.js +187 -1
- package/dist/packages/isolation.js.map +2 -2
- package/dist/packages/licenses.js +214 -1
- package/dist/packages/licenses.js.map +2 -2
- package/dist/packages/manifest.js +190 -1
- package/dist/packages/manifest.js.map +2 -2
- package/dist/packages/normalize.js +132 -1
- package/dist/packages/normalize.js.map +2 -2
- package/dist/packages/operations.js +320 -1
- package/dist/packages/operations.js.map +2 -2
- package/dist/packages/paths.js +53 -1
- package/dist/packages/paths.js.map +2 -2
- package/dist/packages/provenance.js +178 -1
- package/dist/packages/provenance.js.map +2 -2
- package/dist/packages/specs.js +83 -1
- package/dist/packages/specs.js.map +2 -2
- package/dist/packages/validation.js +51 -1
- package/dist/packages/validation.js.map +2 -2
- package/dist/packages.js +129 -1
- package/dist/packages.js.map +2 -2
- package/dist/path.js +446 -1
- package/dist/path.js.map +2 -2
- package/dist/paths/rewire.js +79 -1
- package/dist/paths/rewire.js.map +2 -2
- package/dist/paths.js +190 -1
- package/dist/paths.js.map +2 -2
- package/dist/performance.js +216 -15
- package/dist/performance.js.map +2 -2
- package/dist/process-lock.js +287 -8
- package/dist/process-lock.js.map +2 -2
- package/dist/promise-queue.js +109 -1
- package/dist/promise-queue.js.map +2 -2
- package/dist/promises.js +267 -1
- package/dist/promises.js.map +2 -2
- package/dist/prompts/index.js +45 -1
- package/dist/prompts/index.js.map +2 -2
- package/dist/prompts.js +58 -1
- package/dist/prompts.js.map +2 -2
- package/dist/regexps.js +30 -1
- package/dist/regexps.js.map +2 -2
- package/dist/sea.js +44 -1
- package/dist/sea.js.map +2 -2
- package/dist/shadow.js +58 -1
- package/dist/shadow.js.map +2 -2
- package/dist/signal-exit.js +248 -1
- package/dist/signal-exit.js.map +3 -3
- package/dist/sorts.js +94 -1
- package/dist/sorts.js.map +3 -3
- package/dist/spawn.js +200 -1
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.js +961 -1
- package/dist/spinner.js.map +2 -2
- package/dist/ssri.js +71 -1
- package/dist/ssri.js.map +2 -2
- package/dist/stdio/clear.js +82 -1
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.js +89 -3
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.js +94 -2
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.js +100 -2
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.js +207 -5
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.js +209 -2
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.js +88 -1
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.js +89 -2
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.js +103 -2
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/streams.js +78 -1
- package/dist/streams.js.map +2 -2
- package/dist/strings.js +251 -3
- package/dist/strings.js.map +2 -2
- package/dist/suppress-warnings.js +98 -1
- package/dist/suppress-warnings.js.map +2 -2
- package/dist/tables.js +128 -3
- package/dist/tables.js.map +2 -2
- package/dist/temporary-executor.js +53 -1
- package/dist/temporary-executor.js.map +2 -2
- package/dist/themes/context.js +71 -1
- package/dist/themes/context.js.map +2 -2
- package/dist/themes/index.js +57 -1
- package/dist/themes/index.js.map +2 -2
- package/dist/themes/themes.js +195 -1
- package/dist/themes/themes.js.map +2 -2
- package/dist/themes/types.js +15 -1
- package/dist/themes/types.js.map +2 -2
- package/dist/themes/utils.js +116 -1
- package/dist/themes/utils.js.map +2 -2
- package/dist/types.js +59 -1
- package/dist/types.js.map +2 -2
- package/dist/url.js +142 -1
- package/dist/url.js.map +2 -2
- package/dist/utils/get-ipc.js +58 -1
- package/dist/utils/get-ipc.js.map +2 -2
- package/dist/validation/json-parser.js +127 -1
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.js +15 -1
- package/dist/validation/types.js.map +2 -2
- package/dist/versions.js +154 -1
- package/dist/versions.js.map +2 -2
- package/dist/words.js +50 -1
- package/dist/words.js.map +2 -2
- package/dist/zod.js +27 -1
- package/dist/zod.js.map +2 -2
- package/package.json +1 -1
package/dist/bin.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/bin.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Binary path resolution and execution utilities for package managers.\n * Provides cross-platform bin path lookup, command execution, and path normalization.\n */\n\nimport { getHome } from '#env/home'\nimport { getAppdata, getLocalappdata } from '#env/windows'\nimport { getXdgDataHome } from '#env/xdg'\n\nimport { WIN32 } from '#constants/platform'\nimport { readJsonSync } from './fs'\nimport { isPath, normalizePath } from './path'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('node:fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getFs() {\n if (_fs === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _fs = /*@__PURE__*/ require('node:fs')\n }\n return _fs!\n}\n\nlet _path: typeof import('node:path') | undefined\n/**\n * Lazily load the path module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPath() {\n if (_path === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _path = /*@__PURE__*/ require('node:path')\n }\n return _path!\n}\n\nlet _which: typeof import('which') | undefined\n/**\n * Lazily load the which module for finding executables.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getWhich() {\n if (_which === undefined) {\n _which = /*@__PURE__*/ require('./external/which')\n }\n return _which!\n}\n\n/**\n * Execute a binary with the given arguments.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport async function execBin(\n binPath: string,\n args?: string[],\n options?: import('./spawn').SpawnOptions,\n) {\n // Resolve the binary path.\n const resolvedPath = isPath(binPath)\n ? resolveBinPathSync(binPath)\n : await whichBin(binPath)\n\n if (!resolvedPath) {\n const error = new Error(\n `Binary not found: ${binPath}\\n` +\n 'Possible causes:\\n' +\n ` - Binary \"${binPath}\" is not installed or not in PATH\\n` +\n ' - Binary name is incorrect or misspelled\\n' +\n ' - Installation directory is not in system PATH\\n' +\n 'To resolve:\\n' +\n ` 1. Verify \"${binPath}\" is installed: which ${binPath} (Unix) or where ${binPath} (Windows)\\n` +\n ` 2. Install the binary if missing, ex: npm install -g ${binPath}\\n` +\n ' 3. Check PATH environment variable includes the binary location',\n ) as Error & {\n code: string\n }\n error.code = 'ENOENT'\n throw error\n }\n\n // Execute the binary directly.\n const binCommand = Array.isArray(resolvedPath)\n ? resolvedPath[0]!\n : resolvedPath\n // On Windows, binaries are often .cmd files that require shell to execute.\n return await spawn(binCommand, args ?? [], {\n shell: WIN32,\n ...options,\n })\n}\n\n/**\n * Options for the which function.\n */\nexport interface WhichOptions {\n /** If true, return all matches instead of just the first one. */\n all?: boolean | undefined\n /** If true, return null instead of throwing when no match is found. */\n nothrow?: boolean | undefined\n /** Path to search in. */\n path?: string | undefined\n /** Path separator character. */\n pathExt?: string | undefined\n /** Environment variables to use. */\n env?: Record<string, string | undefined> | undefined\n}\n\n/**\n * Find an executable in the system PATH asynchronously.\n * Wrapper around the which package for lazy loading.\n */\n/* c8 ignore start */\nexport async function which(\n binName: string,\n options?: WhichOptions,\n): Promise<string | string[] | undefined> {\n return await getWhich()(binName, options)\n}\n/* c8 ignore stop */\n\n/**\n * Find an executable in the system PATH synchronously.\n * Wrapper around the which package for lazy loading.\n */\n/* c8 ignore start */\nexport function whichSync(\n binName: string,\n options?: WhichOptions,\n): string | string[] | undefined {\n return getWhich().sync(binName, options)\n}\n/* c8 ignore stop */\n\n/**\n * Find and resolve a binary in the system PATH asynchronously.\n * @throws {Error} If the binary is not found and nothrow is false.\n */\nexport async function whichBin(\n binName: string,\n options?: WhichOptions,\n): Promise<string | string[] | undefined> {\n const which = getWhich()\n // Default to nothrow: true if not specified to return undefined instead of throwing\n const opts = { nothrow: true, ...options }\n // Depending on options `which` may throw if `binName` is not found.\n // With nothrow: true, it returns null when `binName` is not found.\n const result = await which(binName, opts)\n\n // When 'all: true' is specified, ensure we always return an array.\n if (opts?.all) {\n const paths = Array.isArray(result)\n ? result\n : typeof result === 'string'\n ? [result]\n : undefined\n // If all is true and we have paths, resolve each one.\n return paths?.length ? paths.map(p => resolveBinPathSync(p)) : paths\n }\n\n // If result is undefined (binary not found), return undefined\n if (!result) {\n return undefined\n }\n\n return resolveBinPathSync(result)\n}\n\n/**\n * Find and resolve a binary in the system PATH synchronously.\n * @throws {Error} If the binary is not found and nothrow is false.\n */\nexport function whichBinSync(\n binName: string,\n options?: WhichOptions,\n): string | string[] | undefined {\n // Default to nothrow: true if not specified to return undefined instead of throwing\n const opts = { nothrow: true, ...options }\n // Depending on options `which` may throw if `binName` is not found.\n // With nothrow: true, it returns null when `binName` is not found.\n const result = whichSync(binName, opts)\n\n // When 'all: true' is specified, ensure we always return an array.\n if (opts.all) {\n const paths = Array.isArray(result)\n ? result\n : typeof result === 'string'\n ? [result]\n : undefined\n // If all is true and we have paths, resolve each one.\n return paths?.length ? paths.map(p => resolveBinPathSync(p)) : paths\n }\n\n // If result is undefined (binary not found), return undefined\n if (!result) {\n return undefined\n }\n\n return resolveBinPathSync(result as string)\n}\n\n/**\n * Check if a directory path contains any shadow bin patterns.\n */\nexport function isShadowBinPath(dirPath: string | undefined): boolean {\n if (!dirPath) {\n return false\n }\n // Check for node_modules/.bin pattern (Unix and Windows)\n const normalized = dirPath.replace(/\\\\/g, '/')\n return normalized.includes('node_modules/.bin')\n}\n\n/**\n * Find the real executable for a binary, bypassing shadow bins.\n */\nexport function findRealBin(\n binName: string,\n commonPaths: string[] = [],\n): string | undefined {\n const fs = getFs()\n const path = getPath()\n const which = getWhich()\n\n // Try common locations first.\n for (const binPath of commonPaths) {\n if (fs?.existsSync(binPath)) {\n return binPath\n }\n }\n\n // Fall back to which.sync if no direct path found.\n const binPath = which?.sync(binName, { nothrow: true })\n if (binPath) {\n const binDir = path?.dirname(binPath)\n\n if (isShadowBinPath(binDir)) {\n // This is likely a shadowed binary, try to find the real one.\n const allPaths = which?.sync(binName, { all: true, nothrow: true }) || []\n // Ensure allPaths is an array.\n const pathsArray = Array.isArray(allPaths)\n ? allPaths\n : typeof allPaths === 'string'\n ? [allPaths]\n : []\n\n for (const altPath of pathsArray) {\n const altDir = path?.dirname(altPath)\n if (!isShadowBinPath(altDir)) {\n return altPath\n }\n }\n }\n return binPath\n }\n // If all else fails, return undefined to indicate binary not found.\n return undefined\n}\n\n/**\n * Find the real npm executable, bypassing any aliases and shadow bins.\n */\nexport function findRealNpm(): string {\n const fs = getFs()\n const path = getPath()\n\n // Try to find npm in the same directory as the node executable.\n const nodeDir = path?.dirname(process.execPath)\n const npmInNodeDir = path?.join(nodeDir, 'npm')\n\n if (fs?.existsSync(npmInNodeDir)) {\n return npmInNodeDir\n }\n\n // Try common npm locations.\n const commonPaths = ['/usr/local/bin/npm', '/usr/bin/npm']\n const result = findRealBin('npm', commonPaths)\n\n // If we found a valid path, return it.\n if (result && fs?.existsSync(result)) {\n return result\n }\n\n // As a last resort, try to use whichBinSync to find npm.\n // This handles cases where npm is installed in non-standard locations.\n const npmPath = whichBinSync('npm', { nothrow: true })\n if (npmPath && typeof npmPath === 'string' && fs?.existsSync(npmPath)) {\n return npmPath\n }\n\n // Return the basic 'npm' and let the system resolve it.\n return 'npm'\n}\n\n/**\n * Find the real pnpm executable, bypassing any aliases and shadow bins.\n */\nexport function findRealPnpm(): string {\n const path = getPath()\n\n // Try common pnpm locations.\n const commonPaths = WIN32\n ? [\n // Windows common paths.\n path?.join(getAppdata() as string, 'npm', 'pnpm.cmd'),\n path?.join(getAppdata() as string, 'npm', 'pnpm'),\n path?.join(getLocalappdata() as string, 'pnpm', 'pnpm.cmd'),\n path?.join(getLocalappdata() as string, 'pnpm', 'pnpm'),\n 'C:\\\\Program Files\\\\nodejs\\\\pnpm.cmd',\n 'C:\\\\Program Files\\\\nodejs\\\\pnpm',\n ].filter(Boolean)\n : [\n // Unix common paths.\n '/usr/local/bin/pnpm',\n '/usr/bin/pnpm',\n path?.join(\n (getXdgDataHome() as string) || `${getHome() as string}/.local/share`,\n 'pnpm/pnpm',\n ),\n path?.join(getHome() as string, '.pnpm/pnpm'),\n ].filter(Boolean)\n\n return findRealBin('pnpm', commonPaths) ?? ''\n}\n\n/**\n * Find the real yarn executable, bypassing any aliases and shadow bins.\n */\nexport function findRealYarn(): string {\n const path = getPath()\n\n // Try common yarn locations.\n const commonPaths = [\n '/usr/local/bin/yarn',\n '/usr/bin/yarn',\n path?.join(getHome() as string, '.yarn/bin/yarn'),\n path?.join(\n getHome() as string,\n '.config/yarn/global/node_modules/.bin/yarn',\n ),\n ].filter(Boolean)\n\n return findRealBin('yarn', commonPaths) ?? ''\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n/**\n * Resolve a binary path to its actual executable file.\n * Handles Windows .cmd wrappers and Unix shell scripts.\n */\nexport function resolveBinPathSync(binPath: string): string {\n const fs = getFs()\n const path = getPath()\n\n // If it's not an absolute path, try to find it in PATH first\n if (!path?.isAbsolute(binPath)) {\n try {\n const resolved = whichBinSync(binPath)\n if (resolved) {\n binPath = resolved as string\n }\n } catch {}\n }\n\n // Normalize the path once for consistent pattern matching.\n binPath = normalizePath(binPath)\n\n // Handle empty string that normalized to '.' (current directory)\n if (binPath === '.') {\n return binPath\n }\n\n const ext = path?.extname(binPath)\n const extLowered = ext.toLowerCase()\n const basename = path?.basename(binPath, ext)\n const voltaIndex =\n basename === 'node' ? -1 : (/(?<=\\/)\\.volta\\//i.exec(binPath)?.index ?? -1)\n if (voltaIndex !== -1) {\n const voltaPath = binPath.slice(0, voltaIndex)\n const voltaToolsPath = path?.join(voltaPath, 'tools')\n const voltaImagePath = path?.join(voltaToolsPath, 'image')\n const voltaUserPath = path?.join(voltaToolsPath, 'user')\n const voltaPlatform = readJsonSync(\n path?.join(voltaUserPath, 'platform.json'),\n { throws: false },\n ) as any\n const voltaNodeVersion = voltaPlatform?.node?.runtime\n const voltaNpmVersion = voltaPlatform?.node?.npm\n let voltaBinPath = ''\n if (basename === 'npm' || basename === 'npx') {\n if (voltaNpmVersion) {\n const relCliPath = `bin/${basename}-cli.js`\n voltaBinPath = path?.join(\n voltaImagePath,\n `npm/${voltaNpmVersion}/${relCliPath}`,\n )\n if (voltaNodeVersion && !fs?.existsSync(voltaBinPath)) {\n voltaBinPath = path?.join(\n voltaImagePath,\n `node/${voltaNodeVersion}/lib/node_modules/npm/${relCliPath}`,\n )\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = ''\n }\n }\n }\n } else {\n const voltaUserBinPath = path?.join(voltaUserPath, 'bin')\n const binInfo = readJsonSync(\n path?.join(voltaUserBinPath, `${basename}.json`),\n { throws: false },\n ) as any\n const binPackage = binInfo?.package\n if (binPackage) {\n voltaBinPath = path?.join(\n voltaImagePath,\n `packages/${binPackage}/bin/${basename}`,\n )\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = `${voltaBinPath}.cmd`\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = ''\n }\n }\n }\n }\n if (voltaBinPath) {\n try {\n return normalizePath(fs?.realpathSync.native(voltaBinPath))\n } catch {}\n return voltaBinPath\n }\n }\n if (WIN32) {\n const hasKnownExt =\n extLowered === '' ||\n extLowered === '.cmd' ||\n extLowered === '.exe' ||\n extLowered === '.ps1'\n const isNpmOrNpx = basename === 'npm' || basename === 'npx'\n const isPnpmOrYarn = basename === 'pnpm' || basename === 'yarn'\n if (hasKnownExt && isNpmOrNpx) {\n // The quick route assumes a bin path like: C:\\Program Files\\nodejs\\npm.cmd\n const quickPath = path?.join(\n path?.dirname(binPath),\n `node_modules/npm/bin/${basename}-cli.js`,\n )\n if (fs?.existsSync(quickPath)) {\n try {\n return fs?.realpathSync.native(quickPath)\n } catch {}\n return quickPath\n }\n }\n let relPath = ''\n if (\n hasKnownExt &&\n // Only parse shell scripts and batch files, not actual executables.\n // .exe files are already executables and don't need path resolution from wrapper scripts.\n extLowered !== '.exe' &&\n // Check if file exists before attempting to read it to avoid ENOENT errors.\n fs?.existsSync(binPath)\n ) {\n const source = fs?.readFileSync(binPath, 'utf8')\n if (isNpmOrNpx) {\n if (extLowered === '.cmd') {\n // \"npm.cmd\" and \"npx.cmd\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm.cmd\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx.cmd\n relPath =\n basename === 'npm'\n ? /(?<=\"NPM_CLI_JS=%~dp0\\\\).*(?=\")/.exec(source)?.[0] || ''\n : /(?<=\"NPX_CLI_JS=%~dp0\\\\).*(?=\")/.exec(source)?.[0] || ''\n } else if (extLowered === '') {\n // Extensionless \"npm\" and \"npx\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx\n relPath =\n basename === 'npm'\n ? /(?<=NPM_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] ||\n ''\n : /(?<=NPX_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] ||\n ''\n } else if (extLowered === '.ps1') {\n // \"npm.ps1\" and \"npx.ps1\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm.ps1\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx.ps1\n relPath =\n basename === 'npm'\n ? /(?<=\\$NPM_CLI_JS=\"\\$PSScriptRoot\\/).*(?=\")/.exec(\n source,\n )?.[0] || ''\n : /(?<=\\$NPX_CLI_JS=\"\\$PSScriptRoot\\/).*(?=\")/.exec(\n source,\n )?.[0] || ''\n }\n } else if (isPnpmOrYarn) {\n if (extLowered === '.cmd') {\n // pnpm.cmd and yarn.cmd can have different formats depending on installation method\n // Common formats include:\n // 1. Setup-pnpm action format: node \"%~dp0\\..\\pnpm\\bin\\pnpm.cjs\" %*\n // 2. npm install -g pnpm format: similar to cmd-shim\n // 3. Standalone installer format: various patterns\n\n // Try setup-pnpm/setup-yarn action format first\n relPath =\n /(?<=node\\s+\")%~dp0\\\\([^\"]+)(?=\"\\s+%\\*)/.exec(source)?.[1] || ''\n\n // Try alternative format: \"%~dp0\\node.exe\" \"%~dp0\\..\\package\\bin\\binary.js\" %*\n if (!relPath) {\n relPath =\n /(?<=\"%~dp0\\\\[^\"]*node[^\"]*\"\\s+\")%~dp0\\\\([^\"]+)(?=\"\\s+%\\*)/.exec(\n source,\n )?.[1] || ''\n }\n\n // Try cmd-shim format as fallback\n if (!relPath) {\n relPath = /(?<=\"%dp0%\\\\).*(?=\" %\\*\\r\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '') {\n // Extensionless pnpm/yarn - try common shebang formats\n // Handle pnpm installed via standalone installer or global install\n // Format: exec \"$basedir/node\" \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n // Note: may have multiple spaces between arguments\n relPath =\n /(?<=\"\\$basedir\\/)\\.tools\\/pnpm\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(\n source,\n )?.[0] || ''\n if (!relPath) {\n // Also try: exec node \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n relPath =\n /(?<=exec\\s+node\\s+\"\\$basedir\\/)\\.tools\\/pnpm\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(\n source,\n )?.[0] || ''\n }\n if (!relPath) {\n // Try standard cmd-shim format: exec node \"$basedir/../package/bin/binary.js\" \"$@\"\n relPath = /(?<=\"\\$basedir\\/).*(?=\" \"\\$@\"\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '.ps1') {\n // PowerShell format\n relPath = /(?<=\"\\$basedir\\/).*(?=\" $args\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '.cmd') {\n // \"bin.CMD\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L98:\n //\n // @ECHO off\n // GOTO start\n // :find_dp0\n // SET dp0=%~dp0\n // EXIT /b\n // :start\n // SETLOCAL\n // CALL :find_dp0\n //\n // IF EXIST \"%dp0%\\node.exe\" (\n // SET \"_prog=%dp0%\\node.exe\"\n // ) ELSE (\n // SET \"_prog=node\"\n // SET PATHEXT=%PATHEXT:;.JS;=;%\n // )\n //\n // endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & \"%_prog%\" \"%dp0%\\..\\<PACKAGE_NAME>\\path\\to\\bin.js\" %*\n relPath = /(?<=\"%dp0%\\\\).*(?=\" %\\*\\r\\n)/.exec(source)?.[0] || ''\n } else if (extLowered === '') {\n // Extensionless \"bin\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L138:\n //\n // #!/bin/sh\n // basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n //\n // case `uname` in\n // *CYGWIN*|*MINGW*|*MSYS*)\n // if command -v cygpath > /dev/null 2>&1; then\n // basedir=`cygpath -w \"$basedir\"`\n // fi\n // ;;\n // esac\n //\n // if [ -x \"$basedir/node\" ]; then\n // exec \"$basedir/node\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" \"$@\"\n // else\n // exec node \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" \"$@\"\n // fi\n relPath = /(?<=\"$basedir\\/).*(?=\" \"\\$@\"\\n)/.exec(source)?.[0] || ''\n } else if (extLowered === '.ps1') {\n // \"bin.PS1\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L192:\n //\n // #!/usr/bin/env pwsh\n // $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n //\n // $exe=\"\"\n // if ($PSVersionTable.PSVersion -lt \"6.0\" -or $IsWindows) {\n // # Fix case when both the Windows and Linux builds of Node\n // # are installed in the same directory\n // $exe=\".exe\"\n // }\n // $ret=0\n // if (Test-Path \"$basedir/node$exe\") {\n // # Support pipeline input\n // if ($MyInvocation.ExpectingInput) {\n // $input | & \"$basedir/node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // } else {\n // & \"$basedir/node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // }\n // $ret=$LASTEXITCODE\n // } else {\n // # Support pipeline input\n // if ($MyInvocation.ExpectingInput) {\n // $input | & \"node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // } else {\n // & \"node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // }\n // $ret=$LASTEXITCODE\n // }\n // exit $ret\n relPath = /(?<=\"\\$basedir\\/).*(?=\" $args\\n)/.exec(source)?.[0] || ''\n }\n if (relPath) {\n binPath = normalizePath(path?.resolve(path?.dirname(binPath), relPath))\n }\n }\n } else {\n // Handle Unix shell scripts (non-Windows platforms)\n let hasNoExt = extLowered === ''\n const isPnpmOrYarn = basename === 'pnpm' || basename === 'yarn'\n const isNpmOrNpx = basename === 'npm' || basename === 'npx'\n\n // Handle special case where pnpm path in CI has extra segments.\n // In setup-pnpm GitHub Action, the path might be malformed like:\n // /home/user/setup-pnpm/node_modules/.bin/pnpm/bin/pnpm.cjs\n // This happens when the shell script contains a relative path that\n // when resolved, creates an invalid nested structure.\n if (isPnpmOrYarn && binPath.includes('/.bin/pnpm/bin/')) {\n // Extract the correct pnpm bin path.\n const binIndex = binPath.indexOf('/.bin/pnpm')\n if (binIndex !== -1) {\n // Get the base path up to /.bin/pnpm.\n const baseBinPath = binPath.slice(0, binIndex + '/.bin/pnpm'.length)\n // Check if the original shell script exists.\n try {\n const stats = fs?.statSync(baseBinPath)\n // Only use this path if it's a file (the shell script).\n if (stats.isFile()) {\n binPath = normalizePath(baseBinPath)\n // Recompute hasNoExt since we changed the path.\n hasNoExt = !path?.extname(binPath)\n }\n } catch {\n // If stat fails, continue with the original path.\n }\n }\n }\n\n if (\n hasNoExt &&\n (isPnpmOrYarn || isNpmOrNpx) &&\n // For extensionless files (Unix shell scripts), verify existence before reading.\n // This prevents ENOENT errors when the bin path doesn't exist.\n fs?.existsSync(binPath)\n ) {\n const source = fs?.readFileSync(binPath, 'utf8')\n let relPath = ''\n\n if (isPnpmOrYarn) {\n // Handle pnpm/yarn Unix shell scripts.\n // Format: exec \"$basedir/node\" \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n // or: exec node \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n relPath =\n /(?<=\"\\$basedir\\/)\\.tools\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(source)?.[0] || ''\n if (!relPath) {\n // Try standard cmd-shim format: exec node \"$basedir/../package/bin/binary.js\" \"$@\"\n // Example: exec node \"$basedir/../pnpm/bin/pnpm.cjs\" \"$@\"\n // ^^^^^^^^^^^^^^^^^^^^^ captures this part\n // This regex needs to be more careful to not match \"$@\" at the end.\n relPath =\n /(?<=\"\\$basedir\\/)[^\"]+(?=\"\\s+\"\\$@\")/.exec(source)?.[0] || ''\n }\n // Special case for setup-pnpm GitHub Action which may use a different format.\n // The setup-pnpm action creates a shell script that references ../pnpm/bin/pnpm.cjs\n if (!relPath) {\n // Try to match: exec node \"$basedir/../pnpm/bin/pnpm.cjs\" \"$@\"\n const match = /exec\\s+node\\s+\"?\\$basedir\\/([^\"]+)\"?\\s+\"\\$@\"/.exec(\n source,\n )\n if (match) {\n relPath = match[1] || ''\n }\n }\n // Check if the extracted path looks wrong (e.g., pnpm/bin/pnpm.cjs without ../).\n // This happens with setup-pnpm action when it creates a malformed shell script.\n if (relPath && basename === 'pnpm' && relPath.startsWith('pnpm/')) {\n // The path should be ../pnpm/... not pnpm/...\n // Prepend ../ to fix the relative path.\n relPath = `../${relPath}`\n }\n } else if (isNpmOrNpx) {\n // Handle npm/npx Unix shell scripts\n relPath =\n basename === 'npm'\n ? /(?<=NPM_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] || ''\n : /(?<=NPX_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] || ''\n }\n\n if (relPath) {\n // Resolve the relative path to handle .. segments properly.\n binPath = normalizePath(path?.resolve(path?.dirname(binPath), relPath))\n }\n }\n }\n try {\n const realPath = fs?.realpathSync.native(binPath)\n return normalizePath(realPath)\n } catch {}\n // Return normalized path even if realpath fails.\n return normalizePath(binPath)\n}\n"],
|
|
5
|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- Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cacache_exports = {};
|
|
20
|
+
__export(cacache_exports, {
|
|
21
|
+
clear: () => clear,
|
|
22
|
+
get: () => get,
|
|
23
|
+
getCacache: () => getCacache,
|
|
24
|
+
put: () => put,
|
|
25
|
+
remove: () => remove,
|
|
26
|
+
safeGet: () => safeGet,
|
|
27
|
+
withTmp: () => withTmp
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(cacache_exports);
|
|
30
|
+
var import_paths = require("./paths");
|
|
31
|
+
function getCacache() {
|
|
32
|
+
return require("./external/cacache");
|
|
33
|
+
}
|
|
34
|
+
function patternToRegex(pattern) {
|
|
35
|
+
const escaped = pattern.replaceAll(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
36
|
+
const regexPattern = escaped.replaceAll("*", ".*");
|
|
37
|
+
return new RegExp(`^${regexPattern}`);
|
|
38
|
+
}
|
|
39
|
+
function matchesPattern(key, pattern) {
|
|
40
|
+
if (!pattern.includes("*")) {
|
|
41
|
+
return key.startsWith(pattern);
|
|
42
|
+
}
|
|
43
|
+
const regex = patternToRegex(pattern);
|
|
44
|
+
return regex.test(key);
|
|
45
|
+
}
|
|
46
|
+
async function clear(options) {
|
|
47
|
+
const opts = { __proto__: null, ...options };
|
|
48
|
+
const cacache = getCacache();
|
|
49
|
+
const cacheDir = (0, import_paths.getSocketCacacheDir)();
|
|
50
|
+
if (!opts.prefix) {
|
|
51
|
+
try {
|
|
52
|
+
await cacache.rm.all(cacheDir);
|
|
53
|
+
return;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
if (e?.code !== "ENOTEMPTY") {
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const hasWildcard = opts.prefix.includes("*");
|
|
62
|
+
if (!hasWildcard) {
|
|
63
|
+
let removed2 = 0;
|
|
64
|
+
const stream2 = cacache.ls.stream(cacheDir);
|
|
65
|
+
for await (const entry of stream2) {
|
|
66
|
+
if (entry.key.startsWith(opts.prefix)) {
|
|
67
|
+
try {
|
|
68
|
+
await cacache.rm.entry(cacheDir, entry.key);
|
|
69
|
+
removed2++;
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return removed2;
|
|
75
|
+
}
|
|
76
|
+
let removed = 0;
|
|
77
|
+
const stream = cacache.ls.stream(cacheDir);
|
|
78
|
+
for await (const entry of stream) {
|
|
79
|
+
if (matchesPattern(entry.key, opts.prefix)) {
|
|
80
|
+
try {
|
|
81
|
+
await cacache.rm.entry(cacheDir, entry.key);
|
|
82
|
+
removed++;
|
|
83
|
+
} catch {
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return removed;
|
|
88
|
+
}
|
|
89
|
+
async function get(key, options) {
|
|
90
|
+
if (key.includes("*")) {
|
|
91
|
+
throw new TypeError(
|
|
92
|
+
'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const cacache = getCacache();
|
|
96
|
+
return await cacache.get((0, import_paths.getSocketCacacheDir)(), key, options);
|
|
97
|
+
}
|
|
98
|
+
async function put(key, data, options) {
|
|
99
|
+
if (key.includes("*")) {
|
|
100
|
+
throw new TypeError(
|
|
101
|
+
'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).'
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const cacache = getCacache();
|
|
105
|
+
return await cacache.put((0, import_paths.getSocketCacacheDir)(), key, data, options);
|
|
106
|
+
}
|
|
107
|
+
async function remove(key) {
|
|
108
|
+
if (key.includes("*")) {
|
|
109
|
+
throw new TypeError(
|
|
110
|
+
'Cache key cannot contain wildcards (*). Use clear({ prefix: "pattern*" }) to remove multiple entries.'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
const cacache = getCacache();
|
|
114
|
+
return await cacache.rm.entry((0, import_paths.getSocketCacacheDir)(), key);
|
|
115
|
+
}
|
|
116
|
+
async function safeGet(key, options) {
|
|
117
|
+
try {
|
|
118
|
+
return await get(key, options);
|
|
119
|
+
} catch {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function withTmp(callback) {
|
|
124
|
+
const cacache = getCacache();
|
|
125
|
+
return await cacache.tmp.withTmp(
|
|
126
|
+
(0, import_paths.getSocketCacacheDir)(),
|
|
127
|
+
{},
|
|
128
|
+
callback
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
clear,
|
|
134
|
+
get,
|
|
135
|
+
getCacache,
|
|
136
|
+
put,
|
|
137
|
+
remove,
|
|
138
|
+
safeGet,
|
|
139
|
+
withTmp
|
|
140
|
+
});
|
|
3
141
|
//# sourceMappingURL=cacache.js.map
|
package/dist/cacache.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/cacache.ts"],
|
|
4
4
|
"sourcesContent": ["/** @fileoverview Cacache utilities for Socket ecosystem shared content-addressable cache. */\n\nimport { getSocketCacacheDir } from './paths'\n\nexport interface GetOptions {\n integrity?: string | undefined\n size?: number | undefined\n memoize?: boolean | undefined\n}\n\nexport interface PutOptions {\n integrity?: string | undefined\n size?: number | undefined\n metadata?: any | undefined\n memoize?: boolean | undefined\n}\n\nexport interface CacheEntry {\n data: Buffer\n integrity: string\n key: string\n metadata?: any | undefined\n path: string\n size: number\n time: number\n}\n\nexport interface RemoveOptions {\n /**\n * Optional key prefix to filter removals.\n * If provided, only keys starting with this prefix will be removed.\n * Can include wildcards (*) for pattern matching.\n *\n * @example\n * { prefix: 'socket-sdk' } // Simple prefix\n * { prefix: 'socket-sdk:scans:abc*' } // With wildcard\n */\n prefix?: string | undefined\n}\n\n/**\n * Get the cacache module for cache operations.\n */\nexport function getCacache() {\n return /*@__PURE__*/ require('./external/cacache')\n}\n\n/**\n * Convert wildcard pattern to regex for matching.\n * Supports * as wildcard (matches any characters).\n */\nfunction patternToRegex(pattern: string): RegExp {\n // Escape regex special characters except *\n const escaped = pattern.replaceAll(/[.+?^${}()|[\\]\\\\]/g, '\\\\$&')\n // Convert * to .* (match any characters)\n const regexPattern = escaped.replaceAll('*', '.*')\n return new RegExp(`^${regexPattern}`)\n}\n\n/**\n * Check if a key matches a pattern (with wildcard support).\n */\nfunction matchesPattern(key: string, pattern: string): boolean {\n // If no wildcards, use simple prefix matching (faster)\n if (!pattern.includes('*')) {\n return key.startsWith(pattern)\n }\n // Use regex for wildcard patterns\n const regex = patternToRegex(pattern)\n return regex.test(key)\n}\n\n/**\n * Clear entries from the Socket shared cache.\n *\n * Supports wildcard patterns (*) in prefix for flexible matching.\n * For simple prefixes without wildcards, uses efficient streaming.\n * For wildcard patterns, iterates and matches each entry.\n *\n * @param options - Optional configuration for selective clearing\n * @param options.prefix - Prefix or pattern to match (supports * wildcards)\n * @returns Number of entries removed (only when prefix is specified)\n *\n * @example\n * // Clear all entries\n * await clear()\n *\n * @example\n * // Clear entries with simple prefix\n * const removed = await clear({ prefix: 'socket-sdk:scans' })\n * console.log(`Removed ${removed} scan cache entries`)\n *\n * @example\n * // Clear entries with wildcard pattern\n * await clear({ prefix: 'socket-sdk:scans:abc*' })\n * await clear({ prefix: 'socket-sdk:npm/lodash/*' })\n */\nexport async function clear(\n options?: RemoveOptions | undefined,\n): Promise<number | undefined> {\n const opts = { __proto__: null, ...options } as RemoveOptions\n const cacache = getCacache()\n const cacheDir = getSocketCacacheDir()\n\n // If no prefix specified, clear everything.\n if (!opts.prefix) {\n try {\n await cacache.rm.all(cacheDir)\n return\n } catch (e) {\n // Ignore ENOTEMPTY errors - can occur when multiple processes\n // are cleaning up concurrently (e.g., in CI test environments).\n if ((e as NodeJS.ErrnoException)?.code !== 'ENOTEMPTY') {\n throw e\n }\n return\n }\n }\n\n const hasWildcard = opts.prefix.includes('*')\n\n // For simple prefix (no wildcards), use faster iteration.\n if (!hasWildcard) {\n let removed = 0\n const stream = cacache.ls.stream(cacheDir)\n\n for await (const entry of stream) {\n if (entry.key.startsWith(opts.prefix)) {\n try {\n await cacache.rm.entry(cacheDir, entry.key)\n removed++\n } catch {\n // Ignore individual removal errors (e.g., already removed by another process).\n }\n }\n }\n\n return removed\n }\n\n // For wildcard patterns, need to match each entry.\n let removed = 0\n const stream = cacache.ls.stream(cacheDir)\n\n for await (const entry of stream) {\n if (matchesPattern(entry.key, opts.prefix)) {\n try {\n await cacache.rm.entry(cacheDir, entry.key)\n removed++\n } catch {\n // Ignore individual removal errors.\n }\n }\n }\n\n return removed\n}\n\n/**\n * Get data from the Socket shared cache by key.\n * @throws {Error} When cache entry is not found.\n * @throws {TypeError} If key contains wildcards (*)\n */\nexport async function get(\n key: string,\n options?: GetOptions | undefined,\n): Promise<CacheEntry> {\n if (key.includes('*')) {\n throw new TypeError(\n 'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: \"pattern*\" }).',\n )\n }\n const cacache = getCacache() as any\n return await cacache.get(getSocketCacacheDir(), key, options)\n}\n\n/**\n * Put data into the Socket shared cache with a key.\n *\n * @throws {TypeError} If key contains wildcards (*)\n */\nexport async function put(\n key: string,\n data: string | Buffer,\n options?: PutOptions | undefined,\n) {\n if (key.includes('*')) {\n throw new TypeError(\n 'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: \"pattern*\" }).',\n )\n }\n const cacache = getCacache()\n return await cacache.put(getSocketCacacheDir(), key, data, options)\n}\n\n/**\n * Remove an entry from the Socket shared cache by key.\n *\n * @throws {TypeError} If key contains wildcards (*)\n */\nexport async function remove(key: string): Promise<unknown> {\n if (key.includes('*')) {\n throw new TypeError(\n 'Cache key cannot contain wildcards (*). Use clear({ prefix: \"pattern*\" }) to remove multiple entries.',\n )\n }\n const cacache = getCacache() as any\n return await cacache.rm.entry(getSocketCacacheDir(), key)\n}\n\n/**\n * Get data from the Socket shared cache by key without throwing.\n */\nexport async function safeGet(\n key: string,\n options?: GetOptions | undefined,\n): Promise<CacheEntry | undefined> {\n try {\n return await get(key, options)\n } catch {\n return undefined\n }\n}\n\n/**\n * Execute a callback with a temporary directory for cache operations.\n */\nexport async function withTmp<T>(\n callback: (tmpDirPath: string) => Promise<T>,\n): Promise<T> {\n const cacache = getCacache()\n // The DefinitelyTyped types for cacache.tmp.withTmp are incorrect.\n // It actually returns the callback's return value, not void.\n return (await cacache.tmp.withTmp(\n getSocketCacacheDir(),\n {},\n callback as any,\n )) as T\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAoC;AAyC7B,SAAS,aAAa;AAC3B,SAAqB,QAAQ,oBA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,MAAM,GAAG;AAC1C;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAOA,eAAsB,IACpB,KACA,SACqB;AACrB,MAAI,IAAI,SAAS,GAAG,GAAG;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,UAAU,WAAW;AAC3B,SAAO,MAAM,QAAQ,QAAI,kCAAoB,GAAG,KAAK,OAAO;AAC9D;AAOA,eAAsB,IACpB,KACA,MACA,SACA;AACA,MAAI,IAAI,SAAS,GAAG,GAAG;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,UAAU,WAAW;AAC3B,SAAO,MAAM,QAAQ,QAAI,kCAAoB,GAAG,KAAK,MAAM,OAAO;AACpE;AAOA,eAAsB,OAAO,KAA+B;AAC1D,MAAI,IAAI,SAAS,GAAG,GAAG;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,UAAU,WAAW;AAC3B,SAAO,MAAM,QAAQ,GAAG,UAAM,kCAAoB,GAAG,GAAG;AAC1D;AAKA,eAAsB,QACpB,KACA,SACiC;AACjC,MAAI;AACF,WAAO,MAAM,IAAI,KAAK,OAAO;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAKA,eAAsB,QACpB,UACY;AACZ,QAAM,UAAU,WAAW;AAG3B,SAAQ,MAAM,QAAQ,IAAI;AAAA,QACxB,kCAAoB;AAAA,IACpB,CAAC;AAAA,IACD;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["removed", "stream"]
|
|
7
7
|
}
|
package/dist/cache-with-ttl.js
CHANGED
|
@@ -1,3 +1,225 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var cache_with_ttl_exports = {};
|
|
30
|
+
__export(cache_with_ttl_exports, {
|
|
31
|
+
createTtlCache: () => createTtlCache
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(cache_with_ttl_exports);
|
|
34
|
+
var cacache = __toESM(require("./cacache"));
|
|
35
|
+
const DEFAULT_TTL_MS = 5 * 60 * 1e3;
|
|
36
|
+
const DEFAULT_PREFIX = "ttl-cache";
|
|
37
|
+
function createTtlCache(options) {
|
|
38
|
+
const opts = {
|
|
39
|
+
__proto__: null,
|
|
40
|
+
memoize: true,
|
|
41
|
+
prefix: DEFAULT_PREFIX,
|
|
42
|
+
ttl: DEFAULT_TTL_MS,
|
|
43
|
+
...options
|
|
44
|
+
};
|
|
45
|
+
if (opts.prefix?.includes("*")) {
|
|
46
|
+
throw new TypeError(
|
|
47
|
+
'Cache prefix cannot contain wildcards (*). Use clear({ prefix: "pattern*" }) for wildcard matching.'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const memoCache = /* @__PURE__ */ new Map();
|
|
51
|
+
const ttl = opts.ttl ?? DEFAULT_TTL_MS;
|
|
52
|
+
function buildKey(key) {
|
|
53
|
+
return `${opts.prefix}:${key}`;
|
|
54
|
+
}
|
|
55
|
+
function isExpired(entry) {
|
|
56
|
+
return Date.now() > entry.expiresAt;
|
|
57
|
+
}
|
|
58
|
+
function createMatcher(pattern) {
|
|
59
|
+
const fullPattern = buildKey(pattern);
|
|
60
|
+
const hasWildcard = pattern.includes("*");
|
|
61
|
+
if (!hasWildcard) {
|
|
62
|
+
return (key) => key.startsWith(fullPattern);
|
|
63
|
+
}
|
|
64
|
+
const escaped = fullPattern.replaceAll(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
65
|
+
const regexPattern = escaped.replaceAll("*", ".*");
|
|
66
|
+
const regex = new RegExp(`^${regexPattern}`);
|
|
67
|
+
return (key) => regex.test(key);
|
|
68
|
+
}
|
|
69
|
+
async function get(key) {
|
|
70
|
+
if (key.includes("*")) {
|
|
71
|
+
throw new TypeError(
|
|
72
|
+
"Cache key cannot contain wildcards (*). Use getAll(pattern) to retrieve multiple entries."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const fullKey = buildKey(key);
|
|
76
|
+
if (opts.memoize) {
|
|
77
|
+
const memoEntry = memoCache.get(fullKey);
|
|
78
|
+
if (memoEntry && !isExpired(memoEntry)) {
|
|
79
|
+
return memoEntry.data;
|
|
80
|
+
}
|
|
81
|
+
if (memoEntry) {
|
|
82
|
+
memoCache.delete(fullKey);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const cacheEntry = await cacache.safeGet(fullKey);
|
|
86
|
+
if (cacheEntry) {
|
|
87
|
+
const entry = JSON.parse(
|
|
88
|
+
cacheEntry.data.toString("utf8")
|
|
89
|
+
);
|
|
90
|
+
if (!isExpired(entry)) {
|
|
91
|
+
if (opts.memoize) {
|
|
92
|
+
memoCache.set(fullKey, entry);
|
|
93
|
+
}
|
|
94
|
+
return entry.data;
|
|
95
|
+
}
|
|
96
|
+
await cacache.remove(fullKey);
|
|
97
|
+
}
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
async function getAll(pattern) {
|
|
101
|
+
const results = /* @__PURE__ */ new Map();
|
|
102
|
+
const matches = createMatcher(pattern);
|
|
103
|
+
if (opts.memoize) {
|
|
104
|
+
for (const [key, entry] of memoCache.entries()) {
|
|
105
|
+
if (!matches(key)) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (isExpired(entry)) {
|
|
109
|
+
memoCache.delete(key);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const originalKey = key.slice((opts.prefix?.length ?? 0) + 1);
|
|
113
|
+
results.set(originalKey, entry.data);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const cacheDir = (await import("./paths")).getSocketCacacheDir();
|
|
117
|
+
const cacacheModule = await import("./cacache");
|
|
118
|
+
const stream = cacacheModule.getCacache().ls.stream(cacheDir);
|
|
119
|
+
for await (const cacheEntry of stream) {
|
|
120
|
+
if (!cacheEntry.key.startsWith(`${opts.prefix}:`)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!matches(cacheEntry.key)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const originalKey = cacheEntry.key.slice((opts.prefix?.length ?? 0) + 1);
|
|
127
|
+
if (results.has(originalKey)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const entry = await cacache.safeGet(cacheEntry.key);
|
|
132
|
+
if (!entry) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const parsed = JSON.parse(
|
|
136
|
+
entry.data.toString("utf8")
|
|
137
|
+
);
|
|
138
|
+
if (isExpired(parsed)) {
|
|
139
|
+
await cacache.remove(cacheEntry.key);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
results.set(originalKey, parsed.data);
|
|
143
|
+
if (opts.memoize) {
|
|
144
|
+
memoCache.set(cacheEntry.key, parsed);
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return results;
|
|
150
|
+
}
|
|
151
|
+
async function set(key, data) {
|
|
152
|
+
if (key.includes("*")) {
|
|
153
|
+
throw new TypeError(
|
|
154
|
+
'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).'
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
const fullKey = buildKey(key);
|
|
158
|
+
const entry = {
|
|
159
|
+
data,
|
|
160
|
+
expiresAt: Date.now() + ttl
|
|
161
|
+
};
|
|
162
|
+
if (opts.memoize) {
|
|
163
|
+
memoCache.set(fullKey, entry);
|
|
164
|
+
}
|
|
165
|
+
await cacache.put(fullKey, JSON.stringify(entry), {
|
|
166
|
+
metadata: { expiresAt: entry.expiresAt }
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async function getOrFetch(key, fetcher) {
|
|
170
|
+
const cached = await get(key);
|
|
171
|
+
if (cached !== void 0) {
|
|
172
|
+
return cached;
|
|
173
|
+
}
|
|
174
|
+
const data = await fetcher();
|
|
175
|
+
await set(key, data);
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
async function deleteEntry(key) {
|
|
179
|
+
if (key.includes("*")) {
|
|
180
|
+
throw new TypeError(
|
|
181
|
+
"Cache key cannot contain wildcards (*). Use deleteAll(pattern) to remove multiple entries."
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const fullKey = buildKey(key);
|
|
185
|
+
memoCache.delete(fullKey);
|
|
186
|
+
await cacache.remove(fullKey);
|
|
187
|
+
}
|
|
188
|
+
async function deleteAll(pattern) {
|
|
189
|
+
const fullPrefix = pattern ? `${opts.prefix}:${pattern}` : opts.prefix;
|
|
190
|
+
if (!pattern) {
|
|
191
|
+
memoCache.clear();
|
|
192
|
+
} else {
|
|
193
|
+
const matches = createMatcher(pattern);
|
|
194
|
+
for (const key of memoCache.keys()) {
|
|
195
|
+
if (matches(key)) {
|
|
196
|
+
memoCache.delete(key);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const removed = await cacache.clear({ prefix: fullPrefix });
|
|
201
|
+
return removed ?? 0;
|
|
202
|
+
}
|
|
203
|
+
async function clear(options2) {
|
|
204
|
+
const opts2 = { __proto__: null, ...options2 };
|
|
205
|
+
memoCache.clear();
|
|
206
|
+
if (opts2.memoOnly) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
await deleteAll();
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
clear,
|
|
213
|
+
delete: deleteEntry,
|
|
214
|
+
deleteAll,
|
|
215
|
+
get,
|
|
216
|
+
getAll,
|
|
217
|
+
getOrFetch,
|
|
218
|
+
set
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
createTtlCache
|
|
224
|
+
});
|
|
3
225
|
//# sourceMappingURL=cache-with-ttl.js.map
|