@socketsecurity/lib 3.0.2 → 3.0.4
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 +21 -1
- 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.js +57 -2
- package/dist/constants/core.js.map +2 -2
- 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/external/@socketregistry/packageurl-js.js +12 -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 +2 -2
- 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 +1383 -6
- 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 +3 -3
- 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 +2 -2
- package/dist/sorts.js +94 -1
- package/dist/sorts.js.map +2 -2
- package/dist/spawn.js +200 -1
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.js +965 -1
- package/dist/spinner.js.map +3 -3
- 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 +3 -3
- package/dist/themes/index.d.ts +2 -2
- package/dist/themes/index.js +57 -1
- package/dist/themes/index.js.map +3 -3
- package/dist/themes/themes.d.ts +5 -5
- package/dist/themes/themes.js +204 -1
- package/dist/themes/themes.js.map +3 -3
- 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 +2 -2
package/dist/debug.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/debug.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Debug logging utilities with lazy loading and environment-based control.\n * Provides Socket CLI specific debug functionality and logging formatters.\n */\n\nimport { getSpinner } from '#constants/process'\nimport { getDebug } from '#env/debug'\nimport { getSocketDebug } from '#env/socket'\nimport isUnicodeSupported from './external/@socketregistry/is-unicode-supported'\nimport debugJs from './external/debug'\n\nimport { getDefaultLogger } from './logger'\nimport { hasOwn } from './objects'\nimport { applyLinePrefix } from './strings'\n\nconst logger = getDefaultLogger()\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectApply = Reflect.apply\n\n// Type definitions\ninterface DebugOptions {\n namespaces?: string\n spinner?: { isSpinning: boolean; stop(): void; start(): void }\n [key: string]: unknown\n}\n\ntype NamespacesOrOptions = string | DebugOptions\n\ninterface InspectOptions {\n depth?: number | null\n colors?: boolean\n [key: string]: unknown\n}\n\nexport type { DebugOptions, NamespacesOrOptions, InspectOptions }\n\nconst debugByNamespace = new Map()\n/**\n * Get or create a debug instance for a namespace.\n * @private\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getDebugJsInstance(namespace: string) {\n let inst = debugByNamespace.get(namespace)\n if (inst) {\n return inst\n }\n if (\n !getDebug() &&\n getSocketDebug() &&\n (namespace === 'error' || namespace === 'notice')\n ) {\n debugJs.enable(namespace)\n }\n inst = debugJs(namespace)\n inst.log = customLog\n debugByNamespace.set(namespace, inst)\n return inst\n}\n\nlet _util: typeof import('util') | undefined\n/**\n * Lazily load the util module.\n * @private\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getUtil() {\n if (_util === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _util = /*@__PURE__*/ require('node:util')\n }\n return _util as typeof import('util')\n}\n\n/**\n * Extract caller information from the stack trace.\n * @private\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getCallerInfo(stackOffset: number = 3): string {\n let name = ''\n const captureStackTrace = Error.captureStackTrace\n if (typeof captureStackTrace === 'function') {\n const obj: { stack?: unknown } = {}\n captureStackTrace(obj, getCallerInfo)\n const stack = obj.stack\n if (typeof stack === 'string') {\n let lineCount = 0\n let lineStart = 0\n for (let i = 0, { length } = stack; i < length; i += 1) {\n if (stack[i] === '\\n') {\n lineCount += 1\n if (lineCount < stackOffset) {\n // Store the start index of the next line.\n lineStart = i + 1\n } else {\n // Extract the full line and trim it.\n const line = stack.slice(lineStart, i).trimStart()\n // Match the function name portion (e.g., \"async runFix\").\n const match = /(?<=^at\\s+).*?(?=\\s+\\(|$)/.exec(line)?.[0]\n if (match) {\n name = match\n // Strip known V8 invocation prefixes to get the name.\n .replace(/^(?:async|bound|get|new|set)\\s+/, '')\n if (name.startsWith('Object.')) {\n // Strip leading 'Object.' if not an own property of Object.\n const afterDot = name.slice(7 /*'Object.'.length*/)\n if (!hasOwn(Object, afterDot)) {\n name = afterDot\n }\n }\n }\n break\n }\n }\n }\n }\n }\n return name\n}\n\n/**\n * Custom log function for debug output.\n * @private\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction customLog(...args: unknown[]) {\n const util = getUtil()\n const inspectOpts = debugJs.inspectOpts\n ? {\n ...debugJs.inspectOpts,\n showHidden:\n debugJs.inspectOpts.showHidden === null\n ? undefined\n : debugJs.inspectOpts.showHidden,\n depth:\n debugJs.inspectOpts.depth === null ||\n typeof debugJs.inspectOpts.depth === 'boolean'\n ? undefined\n : debugJs.inspectOpts.depth,\n }\n : {}\n ReflectApply(logger.info, logger, [\n util.formatWithOptions(inspectOpts, ...args),\n ])\n}\n\n/**\n * Extract options from namespaces parameter.\n * @private\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction extractOptions(namespaces: NamespacesOrOptions): DebugOptions {\n return namespaces !== null && typeof namespaces === 'object'\n ? ({ __proto__: null, ...namespaces } as DebugOptions)\n : ({ __proto__: null, namespaces } as DebugOptions)\n}\n\n/**\n * Check if debug is enabled for given namespaces.\n * @private\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction isEnabled(namespaces: string | undefined) {\n // Check if debugging is enabled at all\n if (!getSocketDebug()) {\n return false\n }\n if (typeof namespaces !== 'string' || !namespaces || namespaces === '*') {\n return true\n }\n // Namespace splitting logic is based the 'debug' package implementation:\n // https://github.com/debug-js/debug/blob/4.4.1/src/common.js#L169-L173.\n const split = namespaces\n .trim()\n .replace(/\\s+/g, ',')\n .split(',')\n .filter(Boolean)\n const names = []\n const skips = []\n for (const ns of split) {\n if (ns.startsWith('-')) {\n skips.push(ns.slice(1))\n } else {\n names.push(ns)\n }\n }\n if (names.length && !names.some(ns => getDebugJsInstance(ns).enabled)) {\n return false\n }\n return skips.every(ns => !getDebugJsInstance(ns).enabled)\n}\n\n/**\n * Debug output for object inspection with caller info.\n */\nfunction debugDirNs(\n namespacesOrOpts: NamespacesOrOptions,\n obj: unknown,\n inspectOpts?: InspectOptions | undefined,\n) {\n const options = extractOptions(namespacesOrOpts)\n const { namespaces } = options\n if (!isEnabled(namespaces as string)) {\n return\n }\n // Get caller info with stack offset of 4 (caller -> debugDirNs -> getCallerInfo).\n const callerName = getCallerInfo(4) || 'anonymous'\n\n if (pointingTriangle === undefined) {\n const supported = isUnicodeSupported()\n pointingTriangle = supported ? '\u25B8' : '>'\n }\n\n let opts: InspectOptions | undefined = inspectOpts\n if (opts === undefined) {\n const debugOpts = debugJs.inspectOpts\n if (debugOpts) {\n opts = {\n ...debugOpts,\n showHidden:\n debugOpts.showHidden === null ? undefined : debugOpts.showHidden,\n depth:\n debugOpts.depth === null || typeof debugOpts.depth === 'boolean'\n ? null\n : debugOpts.depth,\n } as InspectOptions\n }\n }\n const spinnerInstance = options.spinner || getSpinner()\n const wasSpinning = spinnerInstance?.isSpinning\n spinnerInstance?.stop()\n logger.info(`[DEBUG] ${callerName} ${pointingTriangle} object inspection:`)\n logger.dir(obj, inspectOpts)\n if (wasSpinning) {\n spinnerInstance?.start()\n }\n}\n\nlet pointingTriangle: string | undefined\n/**\n * Debug output with caller info.\n */\nfunction debugNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {\n const options = extractOptions(namespacesOrOpts)\n const { namespaces } = options\n if (!isEnabled(namespaces as string)) {\n return\n }\n // Get caller info with stack offset of 4 (caller -> debugNs -> getCallerInfo).\n const name = getCallerInfo(4) || 'anonymous'\n if (pointingTriangle === undefined) {\n const supported = isUnicodeSupported()\n pointingTriangle = supported ? '\u25B8' : '>'\n }\n const text = args.at(0)\n const logArgs =\n typeof text === 'string'\n ? [\n applyLinePrefix(\n `${name ? `${name} ${pointingTriangle} ` : ''}${text}`,\n { prefix: '[DEBUG] ' },\n ),\n ...args.slice(1),\n ]\n : args\n const spinnerInstance = options.spinner || getSpinner()\n const wasSpinning = spinnerInstance?.isSpinning\n spinnerInstance?.stop()\n ReflectApply(logger.info, logger, logArgs)\n if (wasSpinning) {\n spinnerInstance?.start()\n }\n}\n\n/**\n * Debug logging function with caller info.\n */\nfunction debugLogNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {\n const options = extractOptions(namespacesOrOpts)\n const { namespaces } = options\n if (!isEnabled(namespaces as string)) {\n return\n }\n // Get caller info with stack offset of 4 (caller -> debugLogNs -> getCallerInfo).\n const callerName = getCallerInfo(4) || 'anonymous'\n\n if (pointingTriangle === undefined) {\n const supported = isUnicodeSupported()\n pointingTriangle = supported ? '\u25B8' : '>'\n }\n\n const text = args.at(0)\n const logArgs =\n typeof text === 'string'\n ? [\n applyLinePrefix(\n `${callerName ? `${callerName} ${pointingTriangle} ` : ''}${text}`,\n { prefix: '[DEBUG] ' },\n ),\n ...args.slice(1),\n ]\n : [`[DEBUG] ${callerName} ${pointingTriangle}`, ...args]\n\n const spinnerInstance = options.spinner || getSpinner()\n const wasSpinning = spinnerInstance?.isSpinning\n spinnerInstance?.stop()\n ReflectApply(logger.info, logger, logArgs)\n if (wasSpinning) {\n spinnerInstance?.start()\n }\n}\n\n/**\n * Debug output for cache operations with caller info.\n * First argument is the operation type (hit/miss/set/clear).\n * Second argument is the cache key or message.\n * Optional third argument is metadata object.\n */\nfunction debugCacheNs(\n namespacesOrOpts: NamespacesOrOptions,\n operation: string,\n key: string,\n meta?: unknown | undefined,\n) {\n const options = extractOptions(namespacesOrOpts)\n const { namespaces } = options\n if (!isEnabled(namespaces as string)) {\n return\n }\n // Get caller info with stack offset of 4 (caller -> debugCacheNs -> getCallerInfo).\n const callerName = getCallerInfo(4) || 'cache'\n\n if (pointingTriangle === undefined) {\n const supported = isUnicodeSupported()\n pointingTriangle = supported ? '\u25B8' : '>'\n }\n\n const prefix = `[CACHE] ${callerName} ${pointingTriangle} ${operation}: ${key}`\n const logArgs = meta !== undefined ? [prefix, meta] : [prefix]\n\n const spinnerInstance = options.spinner || getSpinner()\n const wasSpinning = spinnerInstance?.isSpinning\n spinnerInstance?.stop()\n ReflectApply(logger.info, logger, logArgs)\n if (wasSpinning) {\n spinnerInstance?.start()\n }\n}\n\n/**\n * Cache debug function with caller info.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function debugCache(\n operation: string,\n key: string,\n meta?: unknown | undefined,\n): void {\n if (!getSocketDebug()) {\n return\n }\n // Get caller info with stack offset of 3 (caller -> debugCache -> getCallerInfo).\n const callerName = getCallerInfo(3) || 'cache'\n\n if (pointingTriangle === undefined) {\n const supported = isUnicodeSupported()\n pointingTriangle = supported ? '\u25B8' : '>'\n }\n\n const prefix = `[CACHE] ${callerName} ${pointingTriangle} ${operation}: ${key}`\n const args = meta !== undefined ? [prefix, meta] : [prefix]\n console.log(...args)\n}\n\n/**\n * Check if debug mode is enabled.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction isDebugNs(namespaces: string | undefined): boolean {\n return !!getSocketDebug() && isEnabled(namespaces)\n}\n\n/**\n * Debug output with caller info (wrapper for debugNs with default namespace).\n */\nfunction debug(...args: unknown[]): void {\n debugNs('*', ...args)\n}\n\n/**\n * Debug output for object inspection (wrapper for debugDirNs with default namespace).\n */\nfunction debugDir(\n obj: unknown,\n inspectOpts?: InspectOptions | undefined,\n): void {\n debugDirNs('*', obj, inspectOpts)\n}\n\n/**\n * Debug logging function (wrapper for debugLogNs with default namespace).\n */\nfunction debugLog(...args: unknown[]): void {\n debugLogNs('*', ...args)\n}\n\n/**\n * Check if debug mode is enabled.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction isDebug(): boolean {\n return !!getSocketDebug()\n}\n\n/**\n * Create a Node.js util.debuglog compatible function.\n * Returns a function that conditionally writes debug messages to stderr.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction debuglog(section: string) {\n const util = getUtil()\n return util.debuglog(section)\n}\n\n/**\n * Create timing functions for measuring code execution time.\n * Returns an object with start() and end() methods, plus a callable function.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction debugtime(label: string) {\n const util = getUtil()\n // Node.js util doesn't have debugtime - create a custom implementation\n let startTime: number | undefined\n const impl = () => {\n if (startTime === undefined) {\n startTime = Date.now()\n } else {\n const duration = Date.now() - startTime\n util.debuglog('time')(`${label}: ${duration}ms`)\n startTime = undefined\n }\n }\n impl.start = () => {\n startTime = Date.now()\n }\n impl.end = () => {\n if (startTime !== undefined) {\n const duration = Date.now() - startTime\n util.debuglog('time')(`${label}: ${duration}ms`)\n startTime = undefined\n }\n }\n return impl\n}\n\n// Export main debug functions with caller info.\nexport { debug }\n// debugCache is already exported directly above\nexport { debugCacheNs }\nexport { debugDir }\nexport { debugDirNs }\nexport { debugLog }\nexport { debuglog }\nexport { debugLogNs }\nexport { debugNs }\nexport { debugtime }\nexport { isDebug }\nexport { isDebugNs }\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;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|
|
7
|
-
|
|
8
|
-
|
|
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 dlx_binary_exports = {};
|
|
30
|
+
__export(dlx_binary_exports, {
|
|
31
|
+
cleanDlxCache: () => cleanDlxCache,
|
|
32
|
+
dlxBinary: () => dlxBinary,
|
|
33
|
+
downloadBinary: () => downloadBinary,
|
|
34
|
+
executeBinary: () => executeBinary,
|
|
35
|
+
getDlxCachePath: () => getDlxCachePath,
|
|
36
|
+
listDlxCache: () => listDlxCache
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(dlx_binary_exports);
|
|
39
|
+
var import_crypto = require("crypto");
|
|
40
|
+
var import_os = __toESM(require("os"));
|
|
41
|
+
var import_path = __toESM(require("path"));
|
|
42
|
+
var import_platform = require("#constants/platform");
|
|
43
|
+
var import_dlx = require("./dlx");
|
|
44
|
+
var import_http_request = require("./http-request");
|
|
45
|
+
var import_fs = require("./fs");
|
|
46
|
+
var import_objects = require("./objects");
|
|
47
|
+
var import_path2 = require("./path");
|
|
48
|
+
var import_paths = require("./paths");
|
|
49
|
+
var import_process_lock = require("./process-lock");
|
|
50
|
+
var import_spawn = require("./spawn");
|
|
51
|
+
let _fs;
|
|
52
|
+
// @__NO_SIDE_EFFECTS__
|
|
53
|
+
function getFs() {
|
|
54
|
+
if (_fs === void 0) {
|
|
55
|
+
_fs = require("node:fs");
|
|
56
|
+
}
|
|
57
|
+
return _fs;
|
|
58
|
+
}
|
|
59
|
+
function getMetadataPath(cacheEntryPath) {
|
|
60
|
+
return import_path.default.join(cacheEntryPath, ".dlx-metadata.json");
|
|
61
|
+
}
|
|
62
|
+
async function isCacheValid(cacheEntryPath, cacheTtl) {
|
|
63
|
+
const fs = /* @__PURE__ */ getFs();
|
|
64
|
+
try {
|
|
65
|
+
const metaPath = getMetadataPath(cacheEntryPath);
|
|
66
|
+
if (!fs.existsSync(metaPath)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
|
|
70
|
+
if (!(0, import_objects.isObjectObject)(metadata)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const now = Date.now();
|
|
74
|
+
const timestamp = metadata["timestamp"];
|
|
75
|
+
if (typeof timestamp !== "number" || timestamp <= 0) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const age = now - timestamp;
|
|
79
|
+
return age < cacheTtl;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function downloadBinaryFile(url, destPath, checksum) {
|
|
85
|
+
const cacheEntryDir = import_path.default.dirname(destPath);
|
|
86
|
+
const lockPath = import_path.default.join(cacheEntryDir, "concurrency.lock");
|
|
87
|
+
return await import_process_lock.processLock.withLock(
|
|
88
|
+
lockPath,
|
|
89
|
+
async () => {
|
|
90
|
+
const fs = /* @__PURE__ */ getFs();
|
|
91
|
+
if (fs.existsSync(destPath)) {
|
|
92
|
+
const stats = await fs.promises.stat(destPath);
|
|
93
|
+
if (stats.size > 0) {
|
|
94
|
+
const fileBuffer2 = await fs.promises.readFile(destPath);
|
|
95
|
+
const hasher2 = (0, import_crypto.createHash)("sha256");
|
|
96
|
+
hasher2.update(fileBuffer2);
|
|
97
|
+
return hasher2.digest("hex");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
await (0, import_http_request.httpDownload)(url, destPath);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Failed to download binary from ${url}
|
|
105
|
+
Destination: ${destPath}
|
|
106
|
+
Check your internet connection or verify the URL is accessible.`,
|
|
107
|
+
{ cause: e }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const fileBuffer = await fs.promises.readFile(destPath);
|
|
111
|
+
const hasher = (0, import_crypto.createHash)("sha256");
|
|
112
|
+
hasher.update(fileBuffer);
|
|
113
|
+
const actualChecksum = hasher.digest("hex");
|
|
114
|
+
if (checksum && actualChecksum !== checksum) {
|
|
115
|
+
await (0, import_fs.safeDelete)(destPath);
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Checksum mismatch: expected ${checksum}, got ${actualChecksum}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (!import_platform.WIN32) {
|
|
121
|
+
await fs.promises.chmod(destPath, 493);
|
|
122
|
+
}
|
|
123
|
+
return actualChecksum;
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
// Align with npm npx locking strategy.
|
|
127
|
+
staleMs: 5e3,
|
|
128
|
+
touchIntervalMs: 2e3
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
async function writeMetadata(cacheEntryPath, cacheKey, url, checksum, size) {
|
|
133
|
+
const metaPath = getMetadataPath(cacheEntryPath);
|
|
134
|
+
const metadata = {
|
|
135
|
+
version: "1.0.0",
|
|
136
|
+
cache_key: cacheKey,
|
|
137
|
+
timestamp: Date.now(),
|
|
138
|
+
checksum,
|
|
139
|
+
checksum_algorithm: "sha256",
|
|
140
|
+
platform: import_os.default.platform(),
|
|
141
|
+
arch: import_os.default.arch(),
|
|
142
|
+
size,
|
|
143
|
+
source: {
|
|
144
|
+
type: "download",
|
|
145
|
+
url
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const fs = /* @__PURE__ */ getFs();
|
|
149
|
+
await fs.promises.writeFile(metaPath, JSON.stringify(metadata, null, 2));
|
|
150
|
+
}
|
|
151
|
+
async function cleanDlxCache(maxAge = (
|
|
152
|
+
/*@__INLINE__*/
|
|
153
|
+
require("#constants/time").DLX_BINARY_CACHE_TTL
|
|
154
|
+
)) {
|
|
155
|
+
const cacheDir = getDlxCachePath();
|
|
156
|
+
const fs = /* @__PURE__ */ getFs();
|
|
157
|
+
if (!fs.existsSync(cacheDir)) {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
let cleaned = 0;
|
|
161
|
+
const now = Date.now();
|
|
162
|
+
const entries = await fs.promises.readdir(cacheDir);
|
|
163
|
+
for (const entry of entries) {
|
|
164
|
+
const entryPath = import_path.default.join(cacheDir, entry);
|
|
165
|
+
const metaPath = getMetadataPath(entryPath);
|
|
166
|
+
try {
|
|
167
|
+
if (!await (0, import_fs.isDir)(entryPath)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
|
|
171
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const timestamp = metadata["timestamp"];
|
|
175
|
+
const age = typeof timestamp === "number" && timestamp > 0 ? now - timestamp : Number.POSITIVE_INFINITY;
|
|
176
|
+
if (age > maxAge) {
|
|
177
|
+
await (0, import_fs.safeDelete)(entryPath, { force: true, recursive: true });
|
|
178
|
+
cleaned += 1;
|
|
179
|
+
}
|
|
180
|
+
} catch {
|
|
181
|
+
try {
|
|
182
|
+
const contents = await fs.promises.readdir(entryPath);
|
|
183
|
+
if (!contents.length) {
|
|
184
|
+
await (0, import_fs.safeDelete)(entryPath);
|
|
185
|
+
cleaned += 1;
|
|
186
|
+
}
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return cleaned;
|
|
192
|
+
}
|
|
193
|
+
async function dlxBinary(args, options, spawnExtra) {
|
|
194
|
+
const {
|
|
195
|
+
cacheTtl = (
|
|
196
|
+
/*@__INLINE__*/
|
|
197
|
+
require("#constants/time").DLX_BINARY_CACHE_TTL
|
|
198
|
+
),
|
|
199
|
+
checksum,
|
|
200
|
+
force: userForce = false,
|
|
201
|
+
name,
|
|
202
|
+
spawnOptions,
|
|
203
|
+
url,
|
|
204
|
+
yes
|
|
205
|
+
} = { __proto__: null, ...options };
|
|
206
|
+
const force = yes === true ? true : userForce;
|
|
207
|
+
const cacheDir = getDlxCachePath();
|
|
208
|
+
const binaryName = name || `binary-${process.platform}-${import_os.default.arch()}`;
|
|
209
|
+
const spec = `${url}:${binaryName}`;
|
|
210
|
+
const cacheKey = (0, import_dlx.generateCacheKey)(spec);
|
|
211
|
+
const cacheEntryDir = import_path.default.join(cacheDir, cacheKey);
|
|
212
|
+
const binaryPath = (0, import_path2.normalizePath)(import_path.default.join(cacheEntryDir, binaryName));
|
|
213
|
+
const fs = /* @__PURE__ */ getFs();
|
|
214
|
+
let downloaded = false;
|
|
215
|
+
let computedChecksum = checksum;
|
|
216
|
+
if (!force && fs.existsSync(cacheEntryDir) && await isCacheValid(cacheEntryDir, cacheTtl)) {
|
|
217
|
+
try {
|
|
218
|
+
const metaPath = getMetadataPath(cacheEntryDir);
|
|
219
|
+
const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
|
|
220
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata) && typeof metadata["checksum"] === "string") {
|
|
221
|
+
computedChecksum = metadata["checksum"];
|
|
222
|
+
} else {
|
|
223
|
+
downloaded = true;
|
|
224
|
+
}
|
|
225
|
+
} catch {
|
|
226
|
+
downloaded = true;
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
downloaded = true;
|
|
230
|
+
}
|
|
231
|
+
if (downloaded) {
|
|
232
|
+
try {
|
|
233
|
+
await (0, import_fs.safeMkdir)(cacheEntryDir, { recursive: true });
|
|
234
|
+
} catch (e) {
|
|
235
|
+
const code = e.code;
|
|
236
|
+
if (code === "EACCES" || code === "EPERM") {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Permission denied creating binary cache directory: ${cacheEntryDir}
|
|
239
|
+
Please check directory permissions or run with appropriate access.`,
|
|
240
|
+
{ cause: e }
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
if (code === "EROFS") {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}
|
|
246
|
+
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,
|
|
247
|
+
{ cause: e }
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
throw new Error(
|
|
251
|
+
`Failed to create binary cache directory: ${cacheEntryDir}`,
|
|
252
|
+
{ cause: e }
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
computedChecksum = await downloadBinaryFile(url, binaryPath, checksum);
|
|
256
|
+
const stats = await fs.promises.stat(binaryPath);
|
|
257
|
+
await writeMetadata(
|
|
258
|
+
cacheEntryDir,
|
|
259
|
+
cacheKey,
|
|
260
|
+
url,
|
|
261
|
+
computedChecksum || "",
|
|
262
|
+
stats.size
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
const needsShell = import_platform.WIN32 && /\.(?:bat|cmd|ps1)$/i.test(binaryPath);
|
|
266
|
+
const finalSpawnOptions = needsShell ? {
|
|
267
|
+
...spawnOptions,
|
|
268
|
+
env: {
|
|
269
|
+
...spawnOptions?.env,
|
|
270
|
+
PATH: `${cacheEntryDir}${import_path.default.delimiter}${process.env["PATH"] || ""}`
|
|
271
|
+
},
|
|
272
|
+
shell: true
|
|
273
|
+
} : spawnOptions;
|
|
274
|
+
const spawnPromise = (0, import_spawn.spawn)(binaryPath, args, finalSpawnOptions, spawnExtra);
|
|
275
|
+
return {
|
|
276
|
+
binaryPath,
|
|
277
|
+
downloaded,
|
|
278
|
+
spawnPromise
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async function downloadBinary(options) {
|
|
282
|
+
const {
|
|
283
|
+
cacheTtl = (
|
|
284
|
+
/*@__INLINE__*/
|
|
285
|
+
require("#constants/time").DLX_BINARY_CACHE_TTL
|
|
286
|
+
),
|
|
287
|
+
checksum,
|
|
288
|
+
force = false,
|
|
289
|
+
name,
|
|
290
|
+
url
|
|
291
|
+
} = { __proto__: null, ...options };
|
|
292
|
+
const cacheDir = getDlxCachePath();
|
|
293
|
+
const binaryName = name || `binary-${process.platform}-${import_os.default.arch()}`;
|
|
294
|
+
const spec = `${url}:${binaryName}`;
|
|
295
|
+
const cacheKey = (0, import_dlx.generateCacheKey)(spec);
|
|
296
|
+
const cacheEntryDir = import_path.default.join(cacheDir, cacheKey);
|
|
297
|
+
const binaryPath = (0, import_path2.normalizePath)(import_path.default.join(cacheEntryDir, binaryName));
|
|
298
|
+
const fs = /* @__PURE__ */ getFs();
|
|
299
|
+
let downloaded = false;
|
|
300
|
+
if (!force && fs.existsSync(cacheEntryDir) && await isCacheValid(cacheEntryDir, cacheTtl)) {
|
|
301
|
+
downloaded = false;
|
|
302
|
+
} else {
|
|
303
|
+
try {
|
|
304
|
+
await (0, import_fs.safeMkdir)(cacheEntryDir, { recursive: true });
|
|
305
|
+
} catch (e) {
|
|
306
|
+
const code = e.code;
|
|
307
|
+
if (code === "EACCES" || code === "EPERM") {
|
|
308
|
+
throw new Error(
|
|
309
|
+
`Permission denied creating binary cache directory: ${cacheEntryDir}
|
|
310
|
+
Please check directory permissions or run with appropriate access.`,
|
|
311
|
+
{ cause: e }
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (code === "EROFS") {
|
|
315
|
+
throw new Error(
|
|
316
|
+
`Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}
|
|
317
|
+
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,
|
|
318
|
+
{ cause: e }
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
throw new Error(
|
|
322
|
+
`Failed to create binary cache directory: ${cacheEntryDir}`,
|
|
323
|
+
{ cause: e }
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
const computedChecksum = await downloadBinaryFile(url, binaryPath, checksum);
|
|
327
|
+
const stats = await fs.promises.stat(binaryPath);
|
|
328
|
+
await writeMetadata(
|
|
329
|
+
cacheEntryDir,
|
|
330
|
+
cacheKey,
|
|
331
|
+
url,
|
|
332
|
+
computedChecksum || "",
|
|
333
|
+
stats.size
|
|
334
|
+
);
|
|
335
|
+
downloaded = true;
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
binaryPath,
|
|
339
|
+
downloaded
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function executeBinary(binaryPath, args, spawnOptions, spawnExtra) {
|
|
343
|
+
const needsShell = import_platform.WIN32 && /\.(?:bat|cmd|ps1)$/i.test(binaryPath);
|
|
344
|
+
const cacheEntryDir = import_path.default.dirname(binaryPath);
|
|
345
|
+
const finalSpawnOptions = needsShell ? {
|
|
346
|
+
...spawnOptions,
|
|
347
|
+
env: {
|
|
348
|
+
...spawnOptions?.env,
|
|
349
|
+
PATH: `${cacheEntryDir}${import_path.default.delimiter}${process.env["PATH"] || ""}`
|
|
350
|
+
},
|
|
351
|
+
shell: true
|
|
352
|
+
} : spawnOptions;
|
|
353
|
+
return (0, import_spawn.spawn)(binaryPath, args, finalSpawnOptions, spawnExtra);
|
|
354
|
+
}
|
|
355
|
+
function getDlxCachePath() {
|
|
356
|
+
return (0, import_paths.getSocketDlxDir)();
|
|
357
|
+
}
|
|
358
|
+
async function listDlxCache() {
|
|
359
|
+
const cacheDir = getDlxCachePath();
|
|
360
|
+
const fs = /* @__PURE__ */ getFs();
|
|
361
|
+
if (!fs.existsSync(cacheDir)) {
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
const results = [];
|
|
365
|
+
const now = Date.now();
|
|
366
|
+
const entries = await fs.promises.readdir(cacheDir);
|
|
367
|
+
for (const entry of entries) {
|
|
368
|
+
const entryPath = import_path.default.join(cacheDir, entry);
|
|
369
|
+
try {
|
|
370
|
+
if (!await (0, import_fs.isDir)(entryPath)) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const metaPath = getMetadataPath(entryPath);
|
|
374
|
+
const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
|
|
375
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
const metaObj = metadata;
|
|
379
|
+
const source = metaObj["source"];
|
|
380
|
+
const url = source?.["url"] || metaObj["url"] || "";
|
|
381
|
+
const files = await fs.promises.readdir(entryPath);
|
|
382
|
+
const binaryFile = files.find((f) => !f.startsWith("."));
|
|
383
|
+
if (binaryFile) {
|
|
384
|
+
const binaryPath = import_path.default.join(entryPath, binaryFile);
|
|
385
|
+
const binaryStats = await fs.promises.stat(binaryPath);
|
|
386
|
+
results.push({
|
|
387
|
+
age: now - (metaObj["timestamp"] || 0),
|
|
388
|
+
arch: metaObj["arch"] || "unknown",
|
|
389
|
+
checksum: metaObj["checksum"] || "",
|
|
390
|
+
name: binaryFile,
|
|
391
|
+
platform: metaObj["platform"] || "unknown",
|
|
392
|
+
size: binaryStats.size,
|
|
393
|
+
url
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
} catch {
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return results;
|
|
400
|
+
}
|
|
401
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
402
|
+
0 && (module.exports = {
|
|
403
|
+
cleanDlxCache,
|
|
404
|
+
dlxBinary,
|
|
405
|
+
downloadBinary,
|
|
406
|
+
executeBinary,
|
|
407
|
+
getDlxCachePath,
|
|
408
|
+
listDlxCache
|
|
409
|
+
});
|
|
9
410
|
//# sourceMappingURL=dlx-binary.js.map
|