@socketsecurity/lib 2.10.4 → 3.0.1
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 +50 -24
- package/README.md +231 -40
- package/dist/constants/platform.js +1 -1
- package/dist/constants/platform.js.map +3 -3
- package/dist/cover/code.js +1 -1
- package/dist/cover/code.js.map +3 -3
- package/dist/debug.js +2 -2
- package/dist/debug.js.map +3 -3
- package/dist/dlx-binary.d.ts +29 -6
- package/dist/dlx-binary.js +6 -6
- package/dist/dlx-binary.js.map +3 -3
- package/dist/dlx-package.d.ts +16 -1
- package/dist/dlx-package.js +6 -6
- package/dist/dlx-package.js.map +3 -3
- package/dist/dlx.js +1 -1
- package/dist/dlx.js.map +3 -3
- package/dist/env/rewire.js +1 -1
- package/dist/env/rewire.js.map +3 -3
- package/dist/external/yoctocolors-cjs.d.ts +14 -0
- package/dist/fs.d.ts +2 -2
- package/dist/fs.js.map +1 -1
- package/dist/git.js +1 -1
- package/dist/git.js.map +3 -3
- package/dist/http-request.js +1 -1
- package/dist/http-request.js.map +3 -3
- package/dist/index.d.ts +6 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/ipc.js +1 -1
- package/dist/ipc.js.map +3 -3
- package/dist/links/index.d.ts +65 -0
- package/dist/links/index.js +3 -0
- package/dist/links/index.js.map +7 -0
- package/dist/logger.d.ts +21 -18
- package/dist/logger.js +1 -1
- package/dist/logger.js.map +3 -3
- package/dist/packages/isolation.js +1 -1
- package/dist/packages/isolation.js.map +3 -3
- package/dist/paths.js +1 -1
- package/dist/paths.js.map +2 -2
- package/dist/process-lock.js +2 -2
- package/dist/process-lock.js.map +3 -3
- package/dist/promises.d.ts +6 -21
- package/dist/promises.js +1 -1
- package/dist/promises.js.map +2 -2
- package/dist/prompts/index.d.ts +115 -0
- package/dist/prompts/index.js +3 -0
- package/dist/prompts/index.js.map +7 -0
- package/dist/spinner.d.ts +33 -23
- package/dist/spinner.js +1 -1
- package/dist/spinner.js.map +3 -3
- package/dist/stdio/mask.d.ts +2 -2
- package/dist/stdio/mask.js +4 -4
- package/dist/stdio/mask.js.map +3 -3
- package/dist/stdio/stdout.js +1 -1
- package/dist/stdio/stdout.js.map +3 -3
- package/dist/themes/context.d.ts +80 -0
- package/dist/themes/context.js +3 -0
- package/dist/themes/context.js.map +7 -0
- package/dist/themes/index.d.ts +53 -0
- package/dist/themes/index.js +3 -0
- package/dist/themes/index.js.map +7 -0
- package/dist/themes/themes.d.ts +49 -0
- package/dist/themes/themes.js +3 -0
- package/dist/themes/themes.js.map +7 -0
- package/dist/themes/types.d.ts +92 -0
- package/dist/themes/types.js +3 -0
- package/dist/themes/types.js.map +7 -0
- package/dist/themes/utils.d.ts +78 -0
- package/dist/themes/utils.js +3 -0
- package/dist/themes/utils.js.map +7 -0
- package/package.json +39 -11
- package/dist/download-lock.d.ts +0 -49
- package/dist/download-lock.js +0 -10
- package/dist/download-lock.js.map +0 -7
- package/dist/packages/registry.d.ts +0 -8
- package/dist/packages/registry.js +0 -3
- package/dist/packages/registry.js.map +0 -7
package/dist/debug.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/debug.ts"],
|
|
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 { logger } from './logger'\nimport { hasOwn } from './objects'\nimport { applyLinePrefix } from './strings'\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": ";6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,eAAAC,EAAA,iBAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,YAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,YAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAd,GAKA,IAAAe,EAA2B,8BAC3BC,EAAyB,sBACzBC,EAA+B,uBAC/BC,EAA+B,8DAC/BF,EAAoB,+BAEpBG,
|
|
6
|
-
"names": ["debug_exports", "__export", "debug", "debugCache", "debugCacheNs", "debugDir", "debugDirNs", "debugLog", "debugLogNs", "debugNs", "debuglog", "debugtime", "isDebug", "isDebugNs", "__toCommonJS", "import_process", "import_debug", "import_socket", "import_is_unicode_supported", "import_logger", "import_objects", "import_strings", "ReflectApply", "debugByNamespace", "getDebugJsInstance", "namespace", "inst", "debugJs", "customLog", "_util", "getUtil", "getCallerInfo", "stackOffset", "name", "captureStackTrace", "obj", "stack", "lineCount", "lineStart", "i", "length", "line", "match", "afterDot", "args", "util", "inspectOpts", "extractOptions", "namespaces", "isEnabled", "split", "names", "skips", "ns", "namespacesOrOpts", "options", "callerName", "pointingTriangle", "isUnicodeSupported", "opts", "debugOpts", "spinnerInstance", "wasSpinning", "text", "logArgs", "operation", "key", "meta", "prefix", "section", "label", "startTime", "impl", "duration"]
|
|
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 { debugLogN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AI,MAChB,CACL,MAAME,EAAW,KAAK,IAAI,EAAIF,EAC9B1B,EAAK,SAAS,MAAM,EAAE,GAAGyB,CAAK,KAAKG,CAAQ,IAAI,EAC/CF,EAAY,MACd,CACF,EACA,OAAAC,EAAK,MAAQ,IAAM,CACjBD,EAAY,KAAK,IAAI,CACvB,EACAC,EAAK,IAAM,IAAM,CACf,GAAID,IAAc,OAAW,CAC3B,MAAME,EAAW,KAAK,IAAI,EAAIF,EAC9B1B,EAAK,SAAS,MAAM,EAAE,GAAGyB,CAAK,KAAKG,CAAQ,IAAI,EAC/CF,EAAY,MACd,CACF,EACOC,CACT",
|
|
6
|
+
"names": ["debug_exports", "__export", "debug", "debugCache", "debugCacheNs", "debugDir", "debugDirNs", "debugLog", "debugLogNs", "debugNs", "debuglog", "debugtime", "isDebug", "isDebugNs", "__toCommonJS", "import_process", "import_debug", "import_socket", "import_is_unicode_supported", "import_logger", "import_objects", "import_strings", "logger", "ReflectApply", "debugByNamespace", "getDebugJsInstance", "namespace", "inst", "debugJs", "customLog", "_util", "getUtil", "getCallerInfo", "stackOffset", "name", "captureStackTrace", "obj", "stack", "lineCount", "lineStart", "i", "length", "line", "match", "afterDot", "args", "util", "inspectOpts", "extractOptions", "namespaces", "isEnabled", "split", "names", "skips", "ns", "namespacesOrOpts", "options", "callerName", "pointingTriangle", "isUnicodeSupported", "opts", "debugOpts", "spinnerInstance", "wasSpinning", "text", "logArgs", "operation", "key", "meta", "prefix", "section", "label", "startTime", "impl", "duration"]
|
|
7
7
|
}
|
package/dist/dlx-binary.d.ts
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
import type { SpawnExtra, SpawnOptions } from './spawn';
|
|
2
2
|
import { spawn } from './spawn';
|
|
3
3
|
export interface DlxBinaryOptions {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* URL to download the binary from.
|
|
6
|
+
*/
|
|
5
7
|
url: string;
|
|
6
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Optional name for the cached binary (defaults to URL hash).
|
|
10
|
+
*/
|
|
7
11
|
name?: string | undefined;
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Expected checksum (sha256) for verification.
|
|
14
|
+
*/
|
|
9
15
|
checksum?: string | undefined;
|
|
10
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Cache TTL in milliseconds (default: 7 days).
|
|
18
|
+
*/
|
|
11
19
|
cacheTtl?: number | undefined;
|
|
12
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Force re-download even if cached.
|
|
22
|
+
* Aligns with npm/npx --force flag.
|
|
23
|
+
*/
|
|
13
24
|
force?: boolean | undefined;
|
|
14
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Skip confirmation prompts (auto-approve).
|
|
27
|
+
* Aligns with npx --yes/-y flag.
|
|
28
|
+
*/
|
|
29
|
+
yes?: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Suppress output (quiet mode).
|
|
32
|
+
* Aligns with npx --quiet/-q and pnpm --silent/-s flags.
|
|
33
|
+
*/
|
|
34
|
+
quiet?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Additional spawn options.
|
|
37
|
+
*/
|
|
15
38
|
spawnOptions?: SpawnOptions | undefined;
|
|
16
39
|
}
|
|
17
40
|
export interface DlxBinaryResult {
|
package/dist/dlx-binary.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var Y=Object.create;var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Q=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},F=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of W(e))!G.call(t,r)&&r!==n&&P(t,r,{get:()=>e[r],enumerable:!(s=V(e,r))||s.enumerable});return t};var I=(t,e,n)=>(n=t!=null?Y(U(t)):{},F(e||!t||!t.__esModule?P(n,"default",{value:t,enumerable:!0}):n,t)),Z=t=>F(P({},"__esModule",{value:!0}),t);var ae={};Q(ae,{cleanDlxCache:()=>ee,dlxBinary:()=>te,downloadBinary:()=>ne,executeBinary:()=>re,getDlxCachePath:()=>_,listDlxCache:()=>se});module.exports=Z(ae);var T=require("crypto"),k=I(require("os")),p=I(require("path")),$=require("#constants/platform"),j=require("./dlx"),N=require("./http-request"),f=require("./fs"),L=require("./objects"),B=require("./path"),z=require("./paths"),H=require("./process-lock"),v=require("./spawn");let A;function b(){return A===void 0&&(A=require("node:fs")),A}function S(t){return p.default.join(t,".dlx-metadata.json")}async function M(t,e){const n=b();try{const s=S(t);if(!n.existsSync(s))return!1;const r=await(0,f.readJson)(s,{throws:!1});if(!(0,L.isObjectObject)(r))return!1;const a=Date.now(),o=r.timestamp;return typeof o!="number"||o<=0?!1:a-o<e}catch{return!1}}async function q(t,e,n){const s=p.default.dirname(e),r=p.default.join(s,"concurrency.lock");return await H.processLock.withLock(r,async()=>{const a=b();if(a.existsSync(e)&&(await a.promises.stat(e)).size>0){const u=await a.promises.readFile(e),d=(0,T.createHash)("sha256");return d.update(u),d.digest("hex")}try{await(0,N.httpDownload)(t,e)}catch(i){throw new Error(`Failed to download binary from ${t}
|
|
3
3
|
Destination: ${e}
|
|
4
|
-
Check your internet connection or verify the URL is accessible.`,{cause:i})}const o=await a.promises.readFile(e),c=(0,
|
|
5
|
-
Please check directory permissions or run with appropriate access.`,{cause:
|
|
6
|
-
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,{cause:
|
|
7
|
-
Please check directory permissions or run with appropriate access.`,{cause:
|
|
8
|
-
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,{cause:
|
|
4
|
+
Check your internet connection or verify the URL is accessible.`,{cause:i})}const o=await a.promises.readFile(e),c=(0,T.createHash)("sha256");c.update(o);const m=c.digest("hex");if(n&&m!==n)throw await(0,f.safeDelete)(e),new Error(`Checksum mismatch: expected ${n}, got ${m}`);return $.WIN32||await a.promises.chmod(e,493),m},{staleMs:5e3,touchIntervalMs:2e3})}async function K(t,e,n,s,r){const a=S(t),o={version:"1.0.0",cache_key:e,timestamp:Date.now(),checksum:s,checksum_algorithm:"sha256",platform:k.default.platform(),arch:k.default.arch(),size:r,source:{type:"download",url:n}};await b().promises.writeFile(a,JSON.stringify(o,null,2))}async function ee(t=require("#constants/time").DLX_BINARY_CACHE_TTL){const e=_(),n=b();if(!n.existsSync(e))return 0;let s=0;const r=Date.now(),a=await n.promises.readdir(e);for(const o of a){const c=p.default.join(e,o),m=S(c);try{if(!await(0,f.isDir)(c))continue;const i=await(0,f.readJson)(m,{throws:!1});if(!i||typeof i!="object"||Array.isArray(i))continue;const u=i.timestamp;(typeof u=="number"&&u>0?r-u:Number.POSITIVE_INFINITY)>t&&(await(0,f.safeDelete)(c,{force:!0,recursive:!0}),s+=1)}catch{try{(await n.promises.readdir(c)).length||(await(0,f.safeDelete)(c),s+=1)}catch{}}}return s}async function te(t,e,n){const{cacheTtl:s=require("#constants/time").DLX_BINARY_CACHE_TTL,checksum:r,force:a=!1,name:o,spawnOptions:c,url:m,yes:i}={__proto__:null,...e},u=i===!0?!0:a,d=_(),x=o||`binary-${process.platform}-${k.default.arch()}`,w=`${m}:${x}`,g=(0,j.generateCacheKey)(w),l=p.default.join(d,g),h=(0,B.normalizePath)(p.default.join(l,x)),E=b();let D=!1,C=r;if(!u&&E.existsSync(l)&&await M(l,s))try{const O=S(l),y=await(0,f.readJson)(O,{throws:!1});y&&typeof y=="object"&&!Array.isArray(y)&&typeof y.checksum=="string"?C=y.checksum:D=!0}catch{D=!0}else D=!0;if(D){try{await(0,f.safeMkdir)(l,{recursive:!0})}catch(y){const R=y.code;throw R==="EACCES"||R==="EPERM"?new Error(`Permission denied creating binary cache directory: ${l}
|
|
5
|
+
Please check directory permissions or run with appropriate access.`,{cause:y}):R==="EROFS"?new Error(`Cannot create binary cache directory on read-only filesystem: ${l}
|
|
6
|
+
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,{cause:y}):new Error(`Failed to create binary cache directory: ${l}`,{cause:y})}C=await q(m,h,r);const O=await E.promises.stat(h);await K(l,g,m,C||"",O.size)}const X=$.WIN32&&/\.(?:bat|cmd|ps1)$/i.test(h)?{...c,env:{...c?.env,PATH:`${l}${p.default.delimiter}${process.env.PATH||""}`},shell:!0}:c,J=(0,v.spawn)(h,t,X,n);return{binaryPath:h,downloaded:D,spawnPromise:J}}async function ne(t){const{cacheTtl:e=require("#constants/time").DLX_BINARY_CACHE_TTL,checksum:n,force:s=!1,name:r,url:a}={__proto__:null,...t},o=_(),c=r||`binary-${process.platform}-${k.default.arch()}`,m=`${a}:${c}`,i=(0,j.generateCacheKey)(m),u=p.default.join(o,i),d=(0,B.normalizePath)(p.default.join(u,c)),x=b();let w=!1;if(!s&&x.existsSync(u)&&await M(u,e))w=!1;else{try{await(0,f.safeMkdir)(u,{recursive:!0})}catch(h){const E=h.code;throw E==="EACCES"||E==="EPERM"?new Error(`Permission denied creating binary cache directory: ${u}
|
|
7
|
+
Please check directory permissions or run with appropriate access.`,{cause:h}):E==="EROFS"?new Error(`Cannot create binary cache directory on read-only filesystem: ${u}
|
|
8
|
+
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,{cause:h}):new Error(`Failed to create binary cache directory: ${u}`,{cause:h})}const g=await q(a,d,n),l=await x.promises.stat(d);await K(u,i,a,g||"",l.size),w=!0}return{binaryPath:d,downloaded:w}}function re(t,e,n,s){const r=$.WIN32&&/\.(?:bat|cmd|ps1)$/i.test(t),a=p.default.dirname(t),o=r?{...n,env:{...n?.env,PATH:`${a}${p.default.delimiter}${process.env.PATH||""}`},shell:!0}:n;return(0,v.spawn)(t,e,o,s)}function _(){return(0,z.getSocketDlxDir)()}async function se(){const t=_(),e=b();if(!e.existsSync(t))return[];const n=[],s=Date.now(),r=await e.promises.readdir(t);for(const a of r){const o=p.default.join(t,a);try{if(!await(0,f.isDir)(o))continue;const c=S(o),m=await(0,f.readJson)(c,{throws:!1});if(!m||typeof m!="object"||Array.isArray(m))continue;const i=m,d=i.source?.url||i.url||"",w=(await e.promises.readdir(o)).find(g=>!g.startsWith("."));if(w){const g=p.default.join(o,w),l=await e.promises.stat(g);n.push({age:s-(i.timestamp||0),arch:i.arch||"unknown",checksum:i.checksum||"",name:w,platform:i.platform||"unknown",size:l.size,url:d})}}catch{}}return n}0&&(module.exports={cleanDlxCache,dlxBinary,downloadBinary,executeBinary,getDlxCachePath,listDlxCache});
|
|
9
9
|
//# sourceMappingURL=dlx-binary.js.map
|
package/dist/dlx-binary.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dlx-binary.ts"],
|
|
4
|
-
"sourcesContent": ["/** @fileoverview DLX binary execution utilities for Socket ecosystem. */\n\nimport { createHash } from 'node:crypto'\n\nimport os from 'node:os'\n\nimport path from 'node:path'\n\nimport { WIN32 } from '#constants/platform'\n\nimport { generateCacheKey } from './dlx'\nimport { httpDownload } from './http-request'\nimport { isDir, readJson, safeDelete, safeMkdir } from './fs'\nimport { isObjectObject } from './objects'\nimport { normalizePath } from './path'\nimport { getSocketDlxDir } from './paths'\nimport { processLock } from './process-lock'\nimport type { SpawnExtra, SpawnOptions } from './spawn'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n * Uses non-'node:' prefixed require to prevent Webpack bundling issues.\n *\n * @returns The Node.js fs module\n * @private\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 as typeof import('fs')\n}\n\nexport interface DlxBinaryOptions {\n /** URL to download the binary from. */\n url: string\n /** Optional name for the cached binary (defaults to URL hash). */\n name?: string | undefined\n /** Expected checksum (sha256) for verification. */\n checksum?: string | undefined\n /** Cache TTL in milliseconds (default: 7 days). */\n cacheTtl?: number | undefined\n /** Force re-download even if cached. */\n force?: boolean | undefined\n /** Additional spawn options. */\n spawnOptions?: SpawnOptions | undefined\n}\n\nexport interface DlxBinaryResult {\n /** Path to the cached binary. */\n binaryPath: string\n /** Whether the binary was newly downloaded. */\n downloaded: boolean\n /** The spawn promise for the running process. */\n spawnPromise: ReturnType<typeof spawn>\n}\n\n/**\n * Metadata structure for cached binaries (.dlx-metadata.json).\n * Unified schema shared across TypeScript (dlxBinary) and C++ (socket_macho_decompress).\n *\n * Core Fields (present in all implementations):\n * - version: Schema version (currently \"1.0.0\")\n * - cache_key: First 16 chars of SHA-512 hash (matches directory name)\n * - timestamp: Unix timestamp in milliseconds\n * - checksum: Full hash of cached binary (SHA-512 for C++, SHA-256 for TypeScript)\n * - checksum_algorithm: \"sha512\" or \"sha256\"\n * - platform: \"darwin\" | \"linux\" | \"win32\"\n * - arch: \"x64\" | \"arm64\"\n * - size: Size of cached binary in bytes\n * - source: Origin information\n * - type: \"download\" (from URL) or \"decompression\" (from embedded binary)\n * - url: Download URL (if type is \"download\")\n * - path: Source binary path (if type is \"decompression\")\n *\n * Extra Fields (implementation-specific):\n * - For C++ decompression:\n * - compressed_size: Size of compressed data in bytes\n * - compression_algorithm: Brotli level (numeric)\n * - compression_ratio: original_size / compressed_size\n *\n * Example (TypeScript download):\n * ```json\n * {\n * \"version\": \"1.0.0\",\n * \"cache_key\": \"a1b2c3d4e5f67890\",\n * \"timestamp\": 1730332800000,\n * \"checksum\": \"sha256-abc123...\",\n * \"checksum_algorithm\": \"sha256\",\n * \"platform\": \"darwin\",\n * \"arch\": \"arm64\",\n * \"size\": 15000000,\n * \"source\": {\n * \"type\": \"download\",\n * \"url\": \"https://example.com/binary\"\n * }\n * }\n * ```\n *\n * Example (C++ decompression):\n * ```json\n * {\n * \"version\": \"1.0.0\",\n * \"cache_key\": \"0123456789abcdef\",\n * \"timestamp\": 1730332800000,\n * \"checksum\": \"sha512-def456...\",\n * \"checksum_algorithm\": \"sha512\",\n * \"platform\": \"darwin\",\n * \"arch\": \"arm64\",\n * \"size\": 13000000,\n * \"source\": {\n * \"type\": \"decompression\",\n * \"path\": \"/usr/local/bin/socket\"\n * },\n * \"extra\": {\n * \"compressed_size\": 1700000,\n * \"compression_algorithm\": 3,\n * \"compression_ratio\": 7.647\n * }\n * }\n * ```\n *\n * @internal This interface documents the metadata file format.\n */\nexport interface DlxMetadata {\n version: string\n cache_key: string\n timestamp: number\n checksum: string\n checksum_algorithm: string\n platform: string\n arch: string\n size: number\n source?: {\n type: 'download' | 'decompression'\n url?: string\n path?: string\n }\n extra?: Record<string, unknown>\n}\n\n/**\n * Get metadata file path for a cached binary.\n */\nfunction getMetadataPath(cacheEntryPath: string): string {\n return path.join(cacheEntryPath, '.dlx-metadata.json')\n}\n\n/**\n * Check if a cached binary is still valid.\n */\nasync function isCacheValid(\n cacheEntryPath: string,\n cacheTtl: number,\n): Promise<boolean> {\n const fs = getFs()\n try {\n const metaPath = getMetadataPath(cacheEntryPath)\n if (!fs.existsSync(metaPath)) {\n return false\n }\n\n const metadata = await readJson(metaPath, { throws: false })\n if (!isObjectObject(metadata)) {\n return false\n }\n const now = Date.now()\n const timestamp = (metadata as Record<string, unknown>)['timestamp']\n // If timestamp is missing or invalid, cache is invalid\n if (typeof timestamp !== 'number' || timestamp <= 0) {\n return false\n }\n const age = now - timestamp\n\n return age < cacheTtl\n } catch {\n return false\n }\n}\n\n/**\n * Download a file from a URL with integrity checking and concurrent download protection.\n * Uses processLock to prevent multiple processes from downloading the same binary simultaneously.\n * Internal helper function for downloading binary files.\n */\nasync function downloadBinaryFile(\n url: string,\n destPath: string,\n checksum?: string | undefined,\n): Promise<string> {\n // Use process lock to prevent concurrent downloads.\n // Lock is placed in the cache entry directory as 'concurrency.lock'.\n const cacheEntryDir = path.dirname(destPath)\n const lockPath = path.join(cacheEntryDir, 'concurrency.lock')\n\n return await processLock.withLock(\n lockPath,\n async () => {\n const fs = getFs()\n // Check if file was downloaded while waiting for lock.\n if (fs.existsSync(destPath)) {\n const stats = await fs.promises.stat(destPath)\n if (stats.size > 0) {\n // File exists, compute and return checksum.\n const fileBuffer = await fs.promises.readFile(destPath)\n const hasher = createHash('sha256')\n hasher.update(fileBuffer)\n return hasher.digest('hex')\n }\n }\n\n // Download the file.\n try {\n await httpDownload(url, destPath)\n } catch (e) {\n throw new Error(\n `Failed to download binary from ${url}\\n` +\n `Destination: ${destPath}\\n` +\n 'Check your internet connection or verify the URL is accessible.',\n { cause: e },\n )\n }\n\n // Compute checksum of downloaded file.\n const fileBuffer = await fs.promises.readFile(destPath)\n const hasher = createHash('sha256')\n hasher.update(fileBuffer)\n const actualChecksum = hasher.digest('hex')\n\n // Verify checksum if provided.\n if (checksum && actualChecksum !== checksum) {\n // Clean up invalid file.\n await safeDelete(destPath)\n throw new Error(\n `Checksum mismatch: expected ${checksum}, got ${actualChecksum}`,\n )\n }\n\n // Make executable on POSIX systems.\n if (!WIN32) {\n await fs.promises.chmod(destPath, 0o755)\n }\n\n return actualChecksum\n },\n {\n // Align with npm npx locking strategy.\n staleMs: 5000,\n touchIntervalMs: 2000,\n },\n )\n}\n\n/**\n * Write metadata for a cached binary.\n * Uses unified schema shared with C++ decompressor and CLI dlxBinary.\n * Schema documentation: See DlxMetadata interface in this file (exported).\n * Core fields: version, cache_key, timestamp, checksum, checksum_algorithm, platform, arch, size, source\n * Note: This implementation uses SHA-256 checksums instead of SHA-512.\n */\nasync function writeMetadata(\n cacheEntryPath: string,\n cacheKey: string,\n url: string,\n checksum: string,\n size: number,\n): Promise<void> {\n const metaPath = getMetadataPath(cacheEntryPath)\n const metadata = {\n version: '1.0.0',\n cache_key: cacheKey,\n timestamp: Date.now(),\n checksum,\n checksum_algorithm: 'sha256',\n platform: os.platform(),\n arch: os.arch(),\n size,\n source: {\n type: 'download',\n url,\n },\n }\n const fs = getFs()\n await fs.promises.writeFile(metaPath, JSON.stringify(metadata, null, 2))\n}\n\n/**\n * Clean expired entries from the DLX cache.\n */\nexport async function cleanDlxCache(\n maxAge: number = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,\n): Promise<number> {\n const cacheDir = getDlxCachePath()\n const fs = getFs()\n\n if (!fs.existsSync(cacheDir)) {\n return 0\n }\n\n let cleaned = 0\n const now = Date.now()\n const entries = await fs.promises.readdir(cacheDir)\n\n for (const entry of entries) {\n const entryPath = path.join(cacheDir, entry)\n const metaPath = getMetadataPath(entryPath)\n\n try {\n // eslint-disable-next-line no-await-in-loop\n if (!(await isDir(entryPath))) {\n continue\n }\n\n // eslint-disable-next-line no-await-in-loop\n const metadata = await readJson(metaPath, { throws: false })\n if (\n !metadata ||\n typeof metadata !== 'object' ||\n Array.isArray(metadata)\n ) {\n continue\n }\n const timestamp = (metadata as Record<string, unknown>)['timestamp']\n // If timestamp is missing or invalid, treat as expired (age = infinity)\n const age =\n typeof timestamp === 'number' && timestamp > 0\n ? now - timestamp\n : Number.POSITIVE_INFINITY\n\n if (age > maxAge) {\n // Remove entire cache entry directory.\n // eslint-disable-next-line no-await-in-loop\n await safeDelete(entryPath, { force: true, recursive: true })\n cleaned += 1\n }\n } catch {\n // If we can't read metadata, check if directory is empty or corrupted.\n try {\n // eslint-disable-next-line no-await-in-loop\n const contents = await fs.promises.readdir(entryPath)\n if (!contents.length) {\n // Remove empty directory.\n // eslint-disable-next-line no-await-in-loop\n await safeDelete(entryPath)\n cleaned += 1\n }\n } catch {}\n }\n }\n\n return cleaned\n}\n\n/**\n * Download and execute a binary from a URL with caching.\n */\nexport async function dlxBinary(\n args: readonly string[] | string[],\n options?: DlxBinaryOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): Promise<DlxBinaryResult> {\n const {\n cacheTtl = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,\n checksum,\n force = false,\n name,\n spawnOptions,\n url,\n } = { __proto__: null, ...options } as DlxBinaryOptions\n\n // Generate cache paths similar to pnpm/npx structure.\n const cacheDir = getDlxCachePath()\n const binaryName = name || `binary-${process.platform}-${os.arch()}`\n // Create spec from URL and binary name for unique cache identity.\n const spec = `${url}:${binaryName}`\n const cacheKey = generateCacheKey(spec)\n const cacheEntryDir = path.join(cacheDir, cacheKey)\n const binaryPath = normalizePath(path.join(cacheEntryDir, binaryName))\n const fs = getFs()\n\n let downloaded = false\n let computedChecksum = checksum\n\n // Check if we need to download.\n if (\n !force &&\n fs.existsSync(cacheEntryDir) &&\n (await isCacheValid(cacheEntryDir, cacheTtl))\n ) {\n // Binary is cached and valid, read the checksum from metadata.\n try {\n const metaPath = getMetadataPath(cacheEntryDir)\n const metadata = await readJson(metaPath, { throws: false })\n if (\n metadata &&\n typeof metadata === 'object' &&\n !Array.isArray(metadata) &&\n typeof (metadata as Record<string, unknown>)['checksum'] === 'string'\n ) {\n computedChecksum = (metadata as Record<string, unknown>)[\n 'checksum'\n ] as string\n } else {\n // If metadata is invalid, re-download.\n downloaded = true\n }\n } catch {\n // If we can't read metadata, re-download.\n downloaded = true\n }\n } else {\n downloaded = true\n }\n\n if (downloaded) {\n // Ensure cache directory exists before downloading.\n try {\n await safeMkdir(cacheEntryDir, { recursive: true })\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code\n if (code === 'EACCES' || code === 'EPERM') {\n throw new Error(\n `Permission denied creating binary cache directory: ${cacheEntryDir}\\n` +\n 'Please check directory permissions or run with appropriate access.',\n { cause: e },\n )\n }\n if (code === 'EROFS') {\n throw new Error(\n `Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}\\n` +\n 'Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.',\n { cause: e },\n )\n }\n throw new Error(\n `Failed to create binary cache directory: ${cacheEntryDir}`,\n { cause: e },\n )\n }\n\n // Download the binary.\n computedChecksum = await downloadBinaryFile(url, binaryPath, checksum)\n\n // Get file size for metadata.\n const stats = await fs.promises.stat(binaryPath)\n await writeMetadata(\n cacheEntryDir,\n cacheKey,\n url,\n computedChecksum || '',\n stats.size,\n )\n }\n\n // Execute the binary.\n // On Windows, script files (.bat, .cmd, .ps1) require shell: true because\n // they are not executable on their own and must be run through cmd.exe.\n // Note: .exe files are actual binaries and don't need shell mode.\n const needsShell = WIN32 && /\\.(?:bat|cmd|ps1)$/i.test(binaryPath)\n // Windows cmd.exe PATH resolution behavior:\n // When shell: true on Windows with .cmd/.bat/.ps1 files, spawn will automatically\n // strip the full path down to just the basename without extension (e.g.,\n // C:\\cache\\test.cmd becomes just \"test\"). Windows cmd.exe then searches for \"test\"\n // in directories listed in PATH, trying each extension from PATHEXT environment\n // variable (.COM, .EXE, .BAT, .CMD, etc.) until it finds a match.\n //\n // Since our binaries are downloaded to a custom cache directory that's not in PATH\n // (unlike system package managers like npm/pnpm/yarn which are already in PATH),\n // we must prepend the cache directory to PATH so cmd.exe can locate the binary.\n //\n // This approach is consistent with how other tools handle Windows command execution:\n // - npm's promise-spawn: uses which.sync() to find commands in PATH\n // - cross-spawn: spawns cmd.exe with escaped arguments\n // - Node.js spawn with shell: true: delegates to cmd.exe which uses PATH\n const finalSpawnOptions = needsShell\n ? {\n ...spawnOptions,\n env: {\n ...spawnOptions?.env,\n PATH: `${cacheEntryDir}${path.delimiter}${process.env['PATH'] || ''}`,\n },\n shell: true,\n }\n : spawnOptions\n const spawnPromise = spawn(binaryPath, args, finalSpawnOptions, spawnExtra)\n\n return {\n binaryPath,\n downloaded,\n spawnPromise,\n }\n}\n\n/**\n * Download a binary from a URL with caching (without execution).\n * Similar to downloadPackage from dlx-package.\n *\n * @returns Object containing the path to the cached binary and whether it was downloaded\n */\nexport async function downloadBinary(\n options: Omit<DlxBinaryOptions, 'spawnOptions'>,\n): Promise<{ binaryPath: string; downloaded: boolean }> {\n const {\n cacheTtl = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,\n checksum,\n force = false,\n name,\n url,\n } = { __proto__: null, ...options } as DlxBinaryOptions\n\n // Generate cache paths similar to pnpm/npx structure.\n const cacheDir = getDlxCachePath()\n const binaryName = name || `binary-${process.platform}-${os.arch()}`\n // Create spec from URL and binary name for unique cache identity.\n const spec = `${url}:${binaryName}`\n const cacheKey = generateCacheKey(spec)\n const cacheEntryDir = path.join(cacheDir, cacheKey)\n const binaryPath = normalizePath(path.join(cacheEntryDir, binaryName))\n const fs = getFs()\n\n let downloaded = false\n\n // Check if we need to download.\n if (\n !force &&\n fs.existsSync(cacheEntryDir) &&\n (await isCacheValid(cacheEntryDir, cacheTtl))\n ) {\n // Binary is cached and valid.\n downloaded = false\n } else {\n // Ensure cache directory exists before downloading.\n try {\n await safeMkdir(cacheEntryDir, { recursive: true })\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code\n if (code === 'EACCES' || code === 'EPERM') {\n throw new Error(\n `Permission denied creating binary cache directory: ${cacheEntryDir}\\n` +\n 'Please check directory permissions or run with appropriate access.',\n { cause: e },\n )\n }\n if (code === 'EROFS') {\n throw new Error(\n `Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}\\n` +\n 'Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.',\n { cause: e },\n )\n }\n throw new Error(\n `Failed to create binary cache directory: ${cacheEntryDir}`,\n { cause: e },\n )\n }\n\n // Download the binary.\n const computedChecksum = await downloadBinaryFile(url, binaryPath, checksum)\n\n // Get file size for metadata.\n const stats = await fs.promises.stat(binaryPath)\n await writeMetadata(\n cacheEntryDir,\n cacheKey,\n url,\n computedChecksum || '',\n stats.size,\n )\n downloaded = true\n }\n\n return {\n binaryPath,\n downloaded,\n }\n}\n\n/**\n * Execute a cached binary without re-downloading.\n * Similar to executePackage from dlx-package.\n * Binary must have been previously downloaded via downloadBinary or dlxBinary.\n *\n * @param binaryPath Path to the cached binary (from downloadBinary result)\n * @param args Arguments to pass to the binary\n * @param spawnOptions Spawn options for execution\n * @param spawnExtra Extra spawn configuration\n * @returns The spawn promise for the running process\n */\nexport function executeBinary(\n binaryPath: string,\n args: readonly string[] | string[],\n spawnOptions?: SpawnOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): ReturnType<typeof spawn> {\n // On Windows, script files (.bat, .cmd, .ps1) require shell: true because\n // they are not executable on their own and must be run through cmd.exe.\n // Note: .exe files are actual binaries and don't need shell mode.\n const needsShell = WIN32 && /\\.(?:bat|cmd|ps1)$/i.test(binaryPath)\n\n // Windows cmd.exe PATH resolution behavior:\n // When shell: true on Windows with .cmd/.bat/.ps1 files, spawn will automatically\n // strip the full path down to just the basename without extension. Windows cmd.exe\n // then searches for the binary in directories listed in PATH.\n //\n // Since our binaries are downloaded to a custom cache directory that's not in PATH,\n // we must prepend the cache directory to PATH so cmd.exe can locate the binary.\n const cacheEntryDir = path.dirname(binaryPath)\n const finalSpawnOptions = needsShell\n ? {\n ...spawnOptions,\n env: {\n ...spawnOptions?.env,\n PATH: `${cacheEntryDir}${path.delimiter}${process.env['PATH'] || ''}`,\n },\n shell: true,\n }\n : spawnOptions\n\n return spawn(binaryPath, args, finalSpawnOptions, spawnExtra)\n}\n\n/**\n * Get the DLX binary cache directory path.\n * Returns normalized path for cross-platform compatibility.\n * Uses same directory as dlx-package for unified DLX storage.\n */\nexport function getDlxCachePath(): string {\n return getSocketDlxDir()\n}\n\n/**\n * Get information about cached binaries.\n */\nexport async function listDlxCache(): Promise<\n Array<{\n age: number\n arch: string\n checksum: string\n name: string\n platform: string\n size: number\n url: string\n }>\n> {\n const cacheDir = getDlxCachePath()\n const fs = getFs()\n\n if (!fs.existsSync(cacheDir)) {\n return []\n }\n\n const results = []\n const now = Date.now()\n const entries = await fs.promises.readdir(cacheDir)\n\n for (const entry of entries) {\n const entryPath = path.join(cacheDir, entry)\n try {\n // eslint-disable-next-line no-await-in-loop\n if (!(await isDir(entryPath))) {\n continue\n }\n\n const metaPath = getMetadataPath(entryPath)\n // eslint-disable-next-line no-await-in-loop\n const metadata = await readJson(metaPath, { throws: false })\n if (\n !metadata ||\n typeof metadata !== 'object' ||\n Array.isArray(metadata)\n ) {\n continue\n }\n\n const metaObj = metadata as Record<string, unknown>\n\n // Get URL from unified schema (source.url) or legacy schema (url).\n // Allow empty URL for backward compatibility with partial metadata.\n const source = metaObj['source'] as Record<string, unknown> | undefined\n const url =\n (source?.['url'] as string) || (metaObj['url'] as string) || ''\n\n // Find the binary file in the directory.\n // eslint-disable-next-line no-await-in-loop\n const files = await fs.promises.readdir(entryPath)\n const binaryFile = files.find(f => !f.startsWith('.'))\n\n if (binaryFile) {\n const binaryPath = path.join(entryPath, binaryFile)\n // eslint-disable-next-line no-await-in-loop\n const binaryStats = await fs.promises.stat(binaryPath)\n\n results.push({\n age: now - ((metaObj['timestamp'] as number) || 0),\n arch: (metaObj['arch'] as string) || 'unknown',\n checksum: (metaObj['checksum'] as string) || '',\n name: binaryFile,\n platform: (metaObj['platform'] as string) || 'unknown',\n size: binaryStats.size,\n url,\n })\n }\n } catch {}\n }\n\n return results\n}\n"],
|
|
5
|
-
"mappings": ";6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,mBAAAE,
|
|
6
|
-
"names": ["dlx_binary_exports", "__export", "cleanDlxCache", "dlxBinary", "downloadBinary", "executeBinary", "getDlxCachePath", "listDlxCache", "__toCommonJS", "
|
|
4
|
+
"sourcesContent": ["/** @fileoverview DLX binary execution utilities for Socket ecosystem. */\n\nimport { createHash } from 'crypto'\n\nimport os from 'os'\n\nimport path from 'path'\n\nimport { WIN32 } from '#constants/platform'\n\nimport { generateCacheKey } from './dlx'\nimport { httpDownload } from './http-request'\nimport { isDir, readJson, safeDelete, safeMkdir } from './fs'\nimport { isObjectObject } from './objects'\nimport { normalizePath } from './path'\nimport { getSocketDlxDir } from './paths'\nimport { processLock } from './process-lock'\nimport type { SpawnExtra, SpawnOptions } from './spawn'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n * Uses non-'node:' prefixed require to prevent Webpack bundling issues.\n *\n * @returns The Node.js fs module\n * @private\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 as typeof import('fs')\n}\n\nexport interface DlxBinaryOptions {\n /**\n * URL to download the binary from.\n */\n url: string\n\n /**\n * Optional name for the cached binary (defaults to URL hash).\n */\n name?: string | undefined\n\n /**\n * Expected checksum (sha256) for verification.\n */\n checksum?: string | undefined\n\n /**\n * Cache TTL in milliseconds (default: 7 days).\n */\n cacheTtl?: number | undefined\n\n /**\n * Force re-download even if cached.\n * Aligns with npm/npx --force flag.\n */\n force?: boolean | undefined\n\n /**\n * Skip confirmation prompts (auto-approve).\n * Aligns with npx --yes/-y flag.\n */\n yes?: boolean | undefined\n\n /**\n * Suppress output (quiet mode).\n * Aligns with npx --quiet/-q and pnpm --silent/-s flags.\n */\n quiet?: boolean | undefined\n\n /**\n * Additional spawn options.\n */\n spawnOptions?: SpawnOptions | undefined\n}\n\nexport interface DlxBinaryResult {\n /** Path to the cached binary. */\n binaryPath: string\n /** Whether the binary was newly downloaded. */\n downloaded: boolean\n /** The spawn promise for the running process. */\n spawnPromise: ReturnType<typeof spawn>\n}\n\n/**\n * Metadata structure for cached binaries (.dlx-metadata.json).\n * Unified schema shared across TypeScript (dlxBinary) and C++ (socket_macho_decompress).\n *\n * Core Fields (present in all implementations):\n * - version: Schema version (currently \"1.0.0\")\n * - cache_key: First 16 chars of SHA-512 hash (matches directory name)\n * - timestamp: Unix timestamp in milliseconds\n * - checksum: Full hash of cached binary (SHA-512 for C++, SHA-256 for TypeScript)\n * - checksum_algorithm: \"sha512\" or \"sha256\"\n * - platform: \"darwin\" | \"linux\" | \"win32\"\n * - arch: \"x64\" | \"arm64\"\n * - size: Size of cached binary in bytes\n * - source: Origin information\n * - type: \"download\" (from URL) or \"decompression\" (from embedded binary)\n * - url: Download URL (if type is \"download\")\n * - path: Source binary path (if type is \"decompression\")\n *\n * Extra Fields (implementation-specific):\n * - For C++ decompression:\n * - compressed_size: Size of compressed data in bytes\n * - compression_algorithm: Brotli level (numeric)\n * - compression_ratio: original_size / compressed_size\n *\n * Example (TypeScript download):\n * ```json\n * {\n * \"version\": \"1.0.0\",\n * \"cache_key\": \"a1b2c3d4e5f67890\",\n * \"timestamp\": 1730332800000,\n * \"checksum\": \"sha256-abc123...\",\n * \"checksum_algorithm\": \"sha256\",\n * \"platform\": \"darwin\",\n * \"arch\": \"arm64\",\n * \"size\": 15000000,\n * \"source\": {\n * \"type\": \"download\",\n * \"url\": \"https://example.com/binary\"\n * }\n * }\n * ```\n *\n * Example (C++ decompression):\n * ```json\n * {\n * \"version\": \"1.0.0\",\n * \"cache_key\": \"0123456789abcdef\",\n * \"timestamp\": 1730332800000,\n * \"checksum\": \"sha512-def456...\",\n * \"checksum_algorithm\": \"sha512\",\n * \"platform\": \"darwin\",\n * \"arch\": \"arm64\",\n * \"size\": 13000000,\n * \"source\": {\n * \"type\": \"decompression\",\n * \"path\": \"/usr/local/bin/socket\"\n * },\n * \"extra\": {\n * \"compressed_size\": 1700000,\n * \"compression_algorithm\": 3,\n * \"compression_ratio\": 7.647\n * }\n * }\n * ```\n *\n * @internal This interface documents the metadata file format.\n */\nexport interface DlxMetadata {\n version: string\n cache_key: string\n timestamp: number\n checksum: string\n checksum_algorithm: string\n platform: string\n arch: string\n size: number\n source?: {\n type: 'download' | 'decompression'\n url?: string\n path?: string\n }\n extra?: Record<string, unknown>\n}\n\n/**\n * Get metadata file path for a cached binary.\n */\nfunction getMetadataPath(cacheEntryPath: string): string {\n return path.join(cacheEntryPath, '.dlx-metadata.json')\n}\n\n/**\n * Check if a cached binary is still valid.\n */\nasync function isCacheValid(\n cacheEntryPath: string,\n cacheTtl: number,\n): Promise<boolean> {\n const fs = getFs()\n try {\n const metaPath = getMetadataPath(cacheEntryPath)\n if (!fs.existsSync(metaPath)) {\n return false\n }\n\n const metadata = await readJson(metaPath, { throws: false })\n if (!isObjectObject(metadata)) {\n return false\n }\n const now = Date.now()\n const timestamp = (metadata as Record<string, unknown>)['timestamp']\n // If timestamp is missing or invalid, cache is invalid\n if (typeof timestamp !== 'number' || timestamp <= 0) {\n return false\n }\n const age = now - timestamp\n\n return age < cacheTtl\n } catch {\n return false\n }\n}\n\n/**\n * Download a file from a URL with integrity checking and concurrent download protection.\n * Uses processLock to prevent multiple processes from downloading the same binary simultaneously.\n * Internal helper function for downloading binary files.\n */\nasync function downloadBinaryFile(\n url: string,\n destPath: string,\n checksum?: string | undefined,\n): Promise<string> {\n // Use process lock to prevent concurrent downloads.\n // Lock is placed in the cache entry directory as 'concurrency.lock'.\n const cacheEntryDir = path.dirname(destPath)\n const lockPath = path.join(cacheEntryDir, 'concurrency.lock')\n\n return await processLock.withLock(\n lockPath,\n async () => {\n const fs = getFs()\n // Check if file was downloaded while waiting for lock.\n if (fs.existsSync(destPath)) {\n const stats = await fs.promises.stat(destPath)\n if (stats.size > 0) {\n // File exists, compute and return checksum.\n const fileBuffer = await fs.promises.readFile(destPath)\n const hasher = createHash('sha256')\n hasher.update(fileBuffer)\n return hasher.digest('hex')\n }\n }\n\n // Download the file.\n try {\n await httpDownload(url, destPath)\n } catch (e) {\n throw new Error(\n `Failed to download binary from ${url}\\n` +\n `Destination: ${destPath}\\n` +\n 'Check your internet connection or verify the URL is accessible.',\n { cause: e },\n )\n }\n\n // Compute checksum of downloaded file.\n const fileBuffer = await fs.promises.readFile(destPath)\n const hasher = createHash('sha256')\n hasher.update(fileBuffer)\n const actualChecksum = hasher.digest('hex')\n\n // Verify checksum if provided.\n if (checksum && actualChecksum !== checksum) {\n // Clean up invalid file.\n await safeDelete(destPath)\n throw new Error(\n `Checksum mismatch: expected ${checksum}, got ${actualChecksum}`,\n )\n }\n\n // Make executable on POSIX systems.\n if (!WIN32) {\n await fs.promises.chmod(destPath, 0o755)\n }\n\n return actualChecksum\n },\n {\n // Align with npm npx locking strategy.\n staleMs: 5000,\n touchIntervalMs: 2000,\n },\n )\n}\n\n/**\n * Write metadata for a cached binary.\n * Uses unified schema shared with C++ decompressor and CLI dlxBinary.\n * Schema documentation: See DlxMetadata interface in this file (exported).\n * Core fields: version, cache_key, timestamp, checksum, checksum_algorithm, platform, arch, size, source\n * Note: This implementation uses SHA-256 checksums instead of SHA-512.\n */\nasync function writeMetadata(\n cacheEntryPath: string,\n cacheKey: string,\n url: string,\n checksum: string,\n size: number,\n): Promise<void> {\n const metaPath = getMetadataPath(cacheEntryPath)\n const metadata = {\n version: '1.0.0',\n cache_key: cacheKey,\n timestamp: Date.now(),\n checksum,\n checksum_algorithm: 'sha256',\n platform: os.platform(),\n arch: os.arch(),\n size,\n source: {\n type: 'download',\n url,\n },\n }\n const fs = getFs()\n await fs.promises.writeFile(metaPath, JSON.stringify(metadata, null, 2))\n}\n\n/**\n * Clean expired entries from the DLX cache.\n */\nexport async function cleanDlxCache(\n maxAge: number = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,\n): Promise<number> {\n const cacheDir = getDlxCachePath()\n const fs = getFs()\n\n if (!fs.existsSync(cacheDir)) {\n return 0\n }\n\n let cleaned = 0\n const now = Date.now()\n const entries = await fs.promises.readdir(cacheDir)\n\n for (const entry of entries) {\n const entryPath = path.join(cacheDir, entry)\n const metaPath = getMetadataPath(entryPath)\n\n try {\n // eslint-disable-next-line no-await-in-loop\n if (!(await isDir(entryPath))) {\n continue\n }\n\n // eslint-disable-next-line no-await-in-loop\n const metadata = await readJson(metaPath, { throws: false })\n if (\n !metadata ||\n typeof metadata !== 'object' ||\n Array.isArray(metadata)\n ) {\n continue\n }\n const timestamp = (metadata as Record<string, unknown>)['timestamp']\n // If timestamp is missing or invalid, treat as expired (age = infinity)\n const age =\n typeof timestamp === 'number' && timestamp > 0\n ? now - timestamp\n : Number.POSITIVE_INFINITY\n\n if (age > maxAge) {\n // Remove entire cache entry directory.\n // eslint-disable-next-line no-await-in-loop\n await safeDelete(entryPath, { force: true, recursive: true })\n cleaned += 1\n }\n } catch {\n // If we can't read metadata, check if directory is empty or corrupted.\n try {\n // eslint-disable-next-line no-await-in-loop\n const contents = await fs.promises.readdir(entryPath)\n if (!contents.length) {\n // Remove empty directory.\n // eslint-disable-next-line no-await-in-loop\n await safeDelete(entryPath)\n cleaned += 1\n }\n } catch {}\n }\n }\n\n return cleaned\n}\n\n/**\n * Download and execute a binary from a URL with caching.\n */\nexport async function dlxBinary(\n args: readonly string[] | string[],\n options?: DlxBinaryOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): Promise<DlxBinaryResult> {\n const {\n cacheTtl = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,\n checksum,\n force: userForce = false,\n name,\n spawnOptions,\n url,\n yes,\n } = { __proto__: null, ...options } as DlxBinaryOptions\n\n // Map --yes flag to force behavior (auto-approve/skip prompts)\n const force = yes === true ? true : userForce\n\n // Generate cache paths similar to pnpm/npx structure.\n const cacheDir = getDlxCachePath()\n const binaryName = name || `binary-${process.platform}-${os.arch()}`\n // Create spec from URL and binary name for unique cache identity.\n const spec = `${url}:${binaryName}`\n const cacheKey = generateCacheKey(spec)\n const cacheEntryDir = path.join(cacheDir, cacheKey)\n const binaryPath = normalizePath(path.join(cacheEntryDir, binaryName))\n const fs = getFs()\n\n let downloaded = false\n let computedChecksum = checksum\n\n // Check if we need to download.\n if (\n !force &&\n fs.existsSync(cacheEntryDir) &&\n (await isCacheValid(cacheEntryDir, cacheTtl))\n ) {\n // Binary is cached and valid, read the checksum from metadata.\n try {\n const metaPath = getMetadataPath(cacheEntryDir)\n const metadata = await readJson(metaPath, { throws: false })\n if (\n metadata &&\n typeof metadata === 'object' &&\n !Array.isArray(metadata) &&\n typeof (metadata as Record<string, unknown>)['checksum'] === 'string'\n ) {\n computedChecksum = (metadata as Record<string, unknown>)[\n 'checksum'\n ] as string\n } else {\n // If metadata is invalid, re-download.\n downloaded = true\n }\n } catch {\n // If we can't read metadata, re-download.\n downloaded = true\n }\n } else {\n downloaded = true\n }\n\n if (downloaded) {\n // Ensure cache directory exists before downloading.\n try {\n await safeMkdir(cacheEntryDir, { recursive: true })\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code\n if (code === 'EACCES' || code === 'EPERM') {\n throw new Error(\n `Permission denied creating binary cache directory: ${cacheEntryDir}\\n` +\n 'Please check directory permissions or run with appropriate access.',\n { cause: e },\n )\n }\n if (code === 'EROFS') {\n throw new Error(\n `Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}\\n` +\n 'Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.',\n { cause: e },\n )\n }\n throw new Error(\n `Failed to create binary cache directory: ${cacheEntryDir}`,\n { cause: e },\n )\n }\n\n // Download the binary.\n computedChecksum = await downloadBinaryFile(url, binaryPath, checksum)\n\n // Get file size for metadata.\n const stats = await fs.promises.stat(binaryPath)\n await writeMetadata(\n cacheEntryDir,\n cacheKey,\n url,\n computedChecksum || '',\n stats.size,\n )\n }\n\n // Execute the binary.\n // On Windows, script files (.bat, .cmd, .ps1) require shell: true because\n // they are not executable on their own and must be run through cmd.exe.\n // Note: .exe files are actual binaries and don't need shell mode.\n const needsShell = WIN32 && /\\.(?:bat|cmd|ps1)$/i.test(binaryPath)\n // Windows cmd.exe PATH resolution behavior:\n // When shell: true on Windows with .cmd/.bat/.ps1 files, spawn will automatically\n // strip the full path down to just the basename without extension (e.g.,\n // C:\\cache\\test.cmd becomes just \"test\"). Windows cmd.exe then searches for \"test\"\n // in directories listed in PATH, trying each extension from PATHEXT environment\n // variable (.COM, .EXE, .BAT, .CMD, etc.) until it finds a match.\n //\n // Since our binaries are downloaded to a custom cache directory that's not in PATH\n // (unlike system package managers like npm/pnpm/yarn which are already in PATH),\n // we must prepend the cache directory to PATH so cmd.exe can locate the binary.\n //\n // This approach is consistent with how other tools handle Windows command execution:\n // - npm's promise-spawn: uses which.sync() to find commands in PATH\n // - cross-spawn: spawns cmd.exe with escaped arguments\n // - Node.js spawn with shell: true: delegates to cmd.exe which uses PATH\n const finalSpawnOptions = needsShell\n ? {\n ...spawnOptions,\n env: {\n ...spawnOptions?.env,\n PATH: `${cacheEntryDir}${path.delimiter}${process.env['PATH'] || ''}`,\n },\n shell: true,\n }\n : spawnOptions\n const spawnPromise = spawn(binaryPath, args, finalSpawnOptions, spawnExtra)\n\n return {\n binaryPath,\n downloaded,\n spawnPromise,\n }\n}\n\n/**\n * Download a binary from a URL with caching (without execution).\n * Similar to downloadPackage from dlx-package.\n *\n * @returns Object containing the path to the cached binary and whether it was downloaded\n */\nexport async function downloadBinary(\n options: Omit<DlxBinaryOptions, 'spawnOptions'>,\n): Promise<{ binaryPath: string; downloaded: boolean }> {\n const {\n cacheTtl = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,\n checksum,\n force = false,\n name,\n url,\n } = { __proto__: null, ...options } as DlxBinaryOptions\n\n // Generate cache paths similar to pnpm/npx structure.\n const cacheDir = getDlxCachePath()\n const binaryName = name || `binary-${process.platform}-${os.arch()}`\n // Create spec from URL and binary name for unique cache identity.\n const spec = `${url}:${binaryName}`\n const cacheKey = generateCacheKey(spec)\n const cacheEntryDir = path.join(cacheDir, cacheKey)\n const binaryPath = normalizePath(path.join(cacheEntryDir, binaryName))\n const fs = getFs()\n\n let downloaded = false\n\n // Check if we need to download.\n if (\n !force &&\n fs.existsSync(cacheEntryDir) &&\n (await isCacheValid(cacheEntryDir, cacheTtl))\n ) {\n // Binary is cached and valid.\n downloaded = false\n } else {\n // Ensure cache directory exists before downloading.\n try {\n await safeMkdir(cacheEntryDir, { recursive: true })\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code\n if (code === 'EACCES' || code === 'EPERM') {\n throw new Error(\n `Permission denied creating binary cache directory: ${cacheEntryDir}\\n` +\n 'Please check directory permissions or run with appropriate access.',\n { cause: e },\n )\n }\n if (code === 'EROFS') {\n throw new Error(\n `Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}\\n` +\n 'Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.',\n { cause: e },\n )\n }\n throw new Error(\n `Failed to create binary cache directory: ${cacheEntryDir}`,\n { cause: e },\n )\n }\n\n // Download the binary.\n const computedChecksum = await downloadBinaryFile(url, binaryPath, checksum)\n\n // Get file size for metadata.\n const stats = await fs.promises.stat(binaryPath)\n await writeMetadata(\n cacheEntryDir,\n cacheKey,\n url,\n computedChecksum || '',\n stats.size,\n )\n downloaded = true\n }\n\n return {\n binaryPath,\n downloaded,\n }\n}\n\n/**\n * Execute a cached binary without re-downloading.\n * Similar to executePackage from dlx-package.\n * Binary must have been previously downloaded via downloadBinary or dlxBinary.\n *\n * @param binaryPath Path to the cached binary (from downloadBinary result)\n * @param args Arguments to pass to the binary\n * @param spawnOptions Spawn options for execution\n * @param spawnExtra Extra spawn configuration\n * @returns The spawn promise for the running process\n */\nexport function executeBinary(\n binaryPath: string,\n args: readonly string[] | string[],\n spawnOptions?: SpawnOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): ReturnType<typeof spawn> {\n // On Windows, script files (.bat, .cmd, .ps1) require shell: true because\n // they are not executable on their own and must be run through cmd.exe.\n // Note: .exe files are actual binaries and don't need shell mode.\n const needsShell = WIN32 && /\\.(?:bat|cmd|ps1)$/i.test(binaryPath)\n\n // Windows cmd.exe PATH resolution behavior:\n // When shell: true on Windows with .cmd/.bat/.ps1 files, spawn will automatically\n // strip the full path down to just the basename without extension. Windows cmd.exe\n // then searches for the binary in directories listed in PATH.\n //\n // Since our binaries are downloaded to a custom cache directory that's not in PATH,\n // we must prepend the cache directory to PATH so cmd.exe can locate the binary.\n const cacheEntryDir = path.dirname(binaryPath)\n const finalSpawnOptions = needsShell\n ? {\n ...spawnOptions,\n env: {\n ...spawnOptions?.env,\n PATH: `${cacheEntryDir}${path.delimiter}${process.env['PATH'] || ''}`,\n },\n shell: true,\n }\n : spawnOptions\n\n return spawn(binaryPath, args, finalSpawnOptions, spawnExtra)\n}\n\n/**\n * Get the DLX binary cache directory path.\n * Returns normalized path for cross-platform compatibility.\n * Uses same directory as dlx-package for unified DLX storage.\n */\nexport function getDlxCachePath(): string {\n return getSocketDlxDir()\n}\n\n/**\n * Get information about cached binaries.\n */\nexport async function listDlxCache(): Promise<\n Array<{\n age: number\n arch: string\n checksum: string\n name: string\n platform: string\n size: number\n url: string\n }>\n> {\n const cacheDir = getDlxCachePath()\n const fs = getFs()\n\n if (!fs.existsSync(cacheDir)) {\n return []\n }\n\n const results = []\n const now = Date.now()\n const entries = await fs.promises.readdir(cacheDir)\n\n for (const entry of entries) {\n const entryPath = path.join(cacheDir, entry)\n try {\n // eslint-disable-next-line no-await-in-loop\n if (!(await isDir(entryPath))) {\n continue\n }\n\n const metaPath = getMetadataPath(entryPath)\n // eslint-disable-next-line no-await-in-loop\n const metadata = await readJson(metaPath, { throws: false })\n if (\n !metadata ||\n typeof metadata !== 'object' ||\n Array.isArray(metadata)\n ) {\n continue\n }\n\n const metaObj = metadata as Record<string, unknown>\n\n // Get URL from unified schema (source.url) or legacy schema (url).\n // Allow empty URL for backward compatibility with partial metadata.\n const source = metaObj['source'] as Record<string, unknown> | undefined\n const url =\n (source?.['url'] as string) || (metaObj['url'] as string) || ''\n\n // Find the binary file in the directory.\n // eslint-disable-next-line no-await-in-loop\n const files = await fs.promises.readdir(entryPath)\n const binaryFile = files.find(f => !f.startsWith('.'))\n\n if (binaryFile) {\n const binaryPath = path.join(entryPath, binaryFile)\n // eslint-disable-next-line no-await-in-loop\n const binaryStats = await fs.promises.stat(binaryPath)\n\n results.push({\n age: now - ((metaObj['timestamp'] as number) || 0),\n arch: (metaObj['arch'] as string) || 'unknown',\n checksum: (metaObj['checksum'] as string) || '',\n name: binaryFile,\n platform: (metaObj['platform'] as string) || 'unknown',\n size: binaryStats.size,\n url,\n })\n }\n } catch {}\n }\n\n return results\n}\n"],
|
|
5
|
+
"mappings": ";6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,mBAA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EAAY,CACd,MAAMV,EAAa,EAAAtC,QAAK,KAAK2B,EAAWqB,CAAU,EAE5CE,EAAc,MAAM/C,EAAG,SAAS,KAAKmC,CAAU,EAErDQ,EAAQ,KAAK,CACX,IAAKxC,GAAQyC,EAAQ,WAA2B,GAChD,KAAOA,EAAQ,MAAsB,UACrC,SAAWA,EAAQ,UAA0B,GAC7C,KAAMC,EACN,SAAWD,EAAQ,UAA0B,UAC7C,KAAMG,EAAY,KAClB,IAAAzC,CACF,CAAC,CACH,CACF,MAAQ,CAAC,CACX,CAEA,OAAOqC,CACT",
|
|
6
|
+
"names": ["dlx_binary_exports", "__export", "cleanDlxCache", "dlxBinary", "downloadBinary", "executeBinary", "getDlxCachePath", "listDlxCache", "__toCommonJS", "import_crypto", "import_os", "import_path", "import_platform", "import_dlx", "import_http_request", "import_fs", "import_objects", "import_paths", "import_process_lock", "import_spawn", "_fs", "getFs", "getMetadataPath", "cacheEntryPath", "path", "isCacheValid", "cacheTtl", "fs", "metaPath", "metadata", "now", "timestamp", "downloadBinaryFile", "url", "destPath", "checksum", "cacheEntryDir", "lockPath", "fileBuffer", "hasher", "e", "actualChecksum", "writeMetadata", "cacheKey", "size", "os", "maxAge", "cacheDir", "cleaned", "entries", "entry", "entryPath", "args", "options", "spawnExtra", "userForce", "name", "spawnOptions", "yes", "force", "binaryName", "spec", "binaryPath", "downloaded", "computedChecksum", "code", "stats", "finalSpawnOptions", "spawnPromise", "needsShell", "results", "metaObj", "binaryFile", "f", "binaryStats"]
|
|
7
7
|
}
|
package/dist/dlx-package.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface DownloadPackageResult {
|
|
|
11
11
|
export interface DlxPackageOptions {
|
|
12
12
|
/**
|
|
13
13
|
* Package to install (e.g., '@cyclonedx/cdxgen@10.0.0').
|
|
14
|
+
* Aligns with npx --package flag.
|
|
14
15
|
*/
|
|
15
16
|
package: string;
|
|
16
17
|
/**
|
|
@@ -34,8 +35,19 @@ export interface DlxPackageOptions {
|
|
|
34
35
|
binaryName?: string | undefined;
|
|
35
36
|
/**
|
|
36
37
|
* Force reinstallation even if package exists.
|
|
38
|
+
* Aligns with npx --yes/-y flag behavior.
|
|
37
39
|
*/
|
|
38
40
|
force?: boolean | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Skip confirmation prompts (auto-approve).
|
|
43
|
+
* Aligns with npx --yes/-y flag.
|
|
44
|
+
*/
|
|
45
|
+
yes?: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Suppress output (quiet mode).
|
|
48
|
+
* Aligns with npx --quiet/-q and pnpm --silent/-s flags.
|
|
49
|
+
*/
|
|
50
|
+
quiet?: boolean | undefined;
|
|
39
51
|
/**
|
|
40
52
|
* Additional spawn options for the execution.
|
|
41
53
|
*/
|
|
@@ -88,9 +100,12 @@ export declare function dlxPackage(args: readonly string[] | string[], options?:
|
|
|
88
100
|
*/
|
|
89
101
|
export declare function downloadPackage(options: DlxPackageOptions): Promise<DownloadPackageResult>;
|
|
90
102
|
/**
|
|
91
|
-
* Execute a package's binary.
|
|
103
|
+
* Execute a package's binary with cross-platform shell handling.
|
|
92
104
|
* The package must already be installed (use downloadPackage first).
|
|
93
105
|
*
|
|
106
|
+
* On Windows, script files (.bat, .cmd, .ps1) require shell: true.
|
|
107
|
+
* Matches npm/npx execution behavior.
|
|
108
|
+
*
|
|
94
109
|
* @example
|
|
95
110
|
* ```typescript
|
|
96
111
|
* // Execute an already-installed package
|
package/dist/dlx-package.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
3
|
-
Please check directory permissions or run with appropriate access.`,{cause:
|
|
4
|
-
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,{cause:
|
|
2
|
+
var $=Object.create;var y=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var t in n)y(e,t,{get:n[t],enumerable:!0})},b=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of I(n))!A.call(e,r)&&r!==t&&y(e,r,{get:()=>n[r],enumerable:!(a=C(n,r))||a.enumerable});return e};var F=(e,n,t)=>(t=e!=null?$(T(e)):{},b(n||!e||!e.__esModule?y(t,"default",{value:e,enumerable:!0}):t,e)),J=e=>b(y({},"__esModule",{value:!0}),e);var W={};N(W,{dlxPackage:()=>U,downloadPackage:()=>v,executePackage:()=>_});module.exports=J(W);var d=F(require("path")),m=require("./constants/platform"),D=require("./constants/packages"),S=require("./dlx"),h=require("./fs"),g=require("./path"),O=require("./paths"),R=require("./process-lock"),j=require("./spawn");let w;function E(){return w===void 0&&(w=require("node:fs")),w}let P;function M(){return P===void 0&&(P=require("./external/npm-package-arg")),P}let x;function q(){return x===void 0&&(x=require("./external/pacote")),x}const K=/[~^><=xX* ]|\|\|/;function V(e){try{const t=M()(e),a=t.type==="tag"||t.type==="version"||t.type==="range"?t.fetchSpec:void 0;return{name:t.name||e,version:a}}catch{const n=e.lastIndexOf("@");return n===-1||e.startsWith("@")?{name:e,version:void 0}:{name:e.slice(0,n),version:e.slice(n+1)}}}async function B(e,n,t){const a=(0,S.generateCacheKey)(n),r=(0,g.normalizePath)(d.default.join((0,O.getSocketDlxDir)(),a)),p=(0,g.normalizePath)(d.default.join(r,"node_modules",e));try{await(0,h.safeMkdir)(r,{recursive:!0})}catch(o){const f=o.code;throw f==="EACCES"||f==="EPERM"?new Error(`Permission denied creating package directory: ${r}
|
|
3
|
+
Please check directory permissions or run with appropriate access.`,{cause:o}):f==="EROFS"?new Error(`Cannot create package directory on read-only filesystem: ${r}
|
|
4
|
+
Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,{cause:o}):new Error(`Failed to create package directory: ${r}`,{cause:o})}const s=d.default.join(r,"concurrency.lock");return await R.processLock.withLock(s,async()=>{const o=E();if(!t&&o.existsSync(p)){const i=d.default.join(p,"package.json");if(o.existsSync(i))return{installed:!1,packageDir:r}}const f=(0,D.getPacoteCachePath)();try{await q().extract(n,p,{cache:f||d.default.join(r,".cache")})}catch(i){const c=i.code;throw c==="E404"||c==="ETARGET"?new Error(`Package not found: ${n}
|
|
5
5
|
Verify the package exists on npm registry and check the version.
|
|
6
|
-
Visit https://www.npmjs.com/package/${
|
|
7
|
-
Check your internet connection and try again.`,{cause:
|
|
6
|
+
Visit https://www.npmjs.com/package/${e} to see available versions.`,{cause:i}):c==="ENOTFOUND"||c==="ETIMEDOUT"||c==="EAI_AGAIN"?new Error(`Network error installing ${n}
|
|
7
|
+
Check your internet connection and try again.`,{cause:i}):new Error(`Failed to install package: ${n}
|
|
8
8
|
Destination: ${p}
|
|
9
|
-
Check npm registry connectivity or package name.`,{cause:
|
|
9
|
+
Check npm registry connectivity or package name.`,{cause:i})}return{installed:!0,packageDir:r}},{staleMs:5e3,touchIntervalMs:2e3})}function L(e){const n=E();if(!m.WIN32)return e;const t=[".cmd",".bat",".ps1",".exe",""];for(const a of t){const r=e+a;if(n.existsSync(r))return r}return e}function G(e,n,t){const a=(0,g.normalizePath)(d.default.join(e,"node_modules",n)),r=d.default.join(a,"package.json"),s=(0,h.readJsonSync)(r).bin;let o;if(typeof s=="string")o=s;else if(typeof s=="object"&&s!==null){const i=s,c=Object.keys(i);if(c.length===1)o=i[c[0]];else{const k=n.split("/").pop(),u=[t,k,n.replace(/^@[^/]+\//,"")].filter(Boolean);for(const l of u)if(l&&i[l]){o=i[l];break}!o&&c.length>0&&(o=i[c[0]])}}if(!o)throw new Error(`No binary found for package "${n}"`);const f=(0,g.normalizePath)(d.default.join(a,o));return L(f)}async function U(e,n,t){const a=await v(n),r=_(a.binaryPath,e,n?.spawnOptions,t);return{...a,spawnPromise:r}}async function v(e){const n=E(),{binaryName:t,force:a,package:r,yes:p}={__proto__:null,...e},{name:s,version:o}=V(r),f=o!==void 0&&K.test(o),i=a!==void 0?a:p===!0?!0:f,c=o?`${s}@${o}`:s,{installed:k,packageDir:u}=await B(s,c,i),l=G(u,s,t);if(!m.WIN32&&n.existsSync(l))try{n.chmodSync(l,493)}catch{}return{binaryPath:l,installed:k,packageDir:u}}function _(e,n,t,a){const p=m.WIN32&&/\.(?:bat|cmd|ps1)$/i.test(e)?{...t,shell:!0}:t;return(0,j.spawn)(e,n,p,a)}0&&(module.exports={dlxPackage,downloadPackage,executePackage});
|
|
10
10
|
//# sourceMappingURL=dlx-package.js.map
|
package/dist/dlx-package.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dlx-package.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview DLX package execution - Install and execute npm packages.\n *\n * This module provides functionality to install and execute npm packages\n * in the ~/.socket/_dlx directory, similar to npx but with Socket's own cache.\n *\n * Uses content-addressed storage like npm's _npx:\n * - Hash is generated from package spec (name@version)\n * - Each unique spec gets its own directory: ~/.socket/_dlx/<hash>/\n * - Allows caching multiple versions of the same package\n *\n * Concurrency protection:\n * - Uses process-lock to prevent concurrent installation corruption\n * - Lock file created at ~/.socket/_dlx/<hash>/concurrency.lock\n * - Uses npm npx's concurrency.lock naming convention (5s stale, 2s touching)\n * - Prevents multiple processes from corrupting the same package installation\n *\n * Version range handling:\n * - Exact versions (1.0.0) use cache if available\n * - Range versions (^1.0.0, ~1.0.0) auto-force to get latest within range\n * - User can override with explicit force: false\n *\n * Key difference from dlx-binary.ts:\n * - dlx-binary.ts: Downloads standalone binaries from URLs\n * - dlx-package.ts: Installs npm packages from registries\n *\n * Implementation:\n * - Uses pacote for package installation (no npm CLI required)\n * - Split into downloadPackage() and executePackage() for flexibility\n * - dlxPackage() combines both for convenience\n */\n\nimport path from 'node:path'\n\nimport { WIN32 } from './constants/platform'\nimport { getPacoteCachePath } from './constants/packages'\nimport { generateCacheKey } from './dlx'\nimport { readJsonSync, safeMkdir } from './fs'\nimport { normalizePath } from './path'\nimport { getSocketDlxDir } from './paths'\nimport { processLock } from './process-lock'\nimport type { SpawnExtra, SpawnOptions } from './spawn'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n * Uses non-'node:' prefixed require to prevent Webpack bundling issues.\n *\n * @returns The Node.js fs module\n * @private\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 as typeof import('fs')\n}\n\nlet _npmPackageArg: typeof import('npm-package-arg') | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getNpmPackageArg() {\n if (_npmPackageArg === undefined) {\n _npmPackageArg = /*@__PURE__*/ require('./external/npm-package-arg')\n }\n return _npmPackageArg as typeof import('npm-package-arg')\n}\n\nlet _pacote: typeof import('pacote') | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPacote() {\n if (_pacote === undefined) {\n _pacote = /*@__PURE__*/ require('./external/pacote')\n }\n return _pacote as typeof import('pacote')\n}\n\n/**\n * Regex to check if a version string contains range operators.\n * Matches any version with range operators: ~, ^, >, <, =, x, X, *, spaces, or ||.\n */\nconst rangeOperatorsRegExp = /[~^><=xX* ]|\\|\\|/\n\nexport interface DownloadPackageResult {\n /** Path to the installed package directory. */\n packageDir: string\n /** Path to the binary. */\n binaryPath: string\n /** Whether the package was newly installed. */\n installed: boolean\n}\n\nexport interface DlxPackageOptions {\n /**\n * Package to install (e.g., '@cyclonedx/cdxgen@10.0.0').\n */\n package: string\n /**\n * Binary name to execute (optional - auto-detected in most cases).\n *\n * Auto-detection logic:\n * 1. If package has only one binary, uses it automatically\n * 2. Tries user-provided binaryName\n * 3. Tries last segment of package name (e.g., 'cli' from '@socketsecurity/cli')\n * 4. Falls back to first binary\n *\n * Only needed when package has multiple binaries and auto-detection fails.\n *\n * @example\n * // Auto-detected (single binary)\n * { package: '@socketsecurity/cli' } // Finds 'socket' binary automatically\n *\n * // Explicit (multiple binaries)\n * { package: 'some-tool', binaryName: 'specific-tool' }\n */\n binaryName?: string | undefined\n /**\n * Force reinstallation even if package exists.\n */\n force?: boolean | undefined\n /**\n * Additional spawn options for the execution.\n */\n spawnOptions?: SpawnOptions | undefined\n}\n\nexport interface DlxPackageResult {\n /** Path to the installed package directory. */\n packageDir: string\n /** Path to the binary that was executed. */\n binaryPath: string\n /** Whether the package was newly installed. */\n installed: boolean\n /** The spawn promise for the running process. */\n spawnPromise: ReturnType<typeof spawn>\n}\n\n/**\n * Parse package spec into name and version using npm-package-arg.\n * Examples:\n * - 'lodash@4.17.21' \u2192 { name: 'lodash', version: '4.17.21' }\n * - '@scope/pkg@1.0.0' \u2192 { name: '@scope/pkg', version: '1.0.0' }\n * - 'lodash' \u2192 { name: 'lodash', version: undefined }\n */\nfunction parsePackageSpec(spec: string): {\n name: string\n version: string | undefined\n} {\n try {\n const npa = getNpmPackageArg()\n const parsed = npa(spec)\n\n // Extract version from different types of specs.\n // For registry specs, use fetchSpec (the version/range).\n // For git/file/etc, version will be undefined.\n const version =\n parsed.type === 'tag'\n ? parsed.fetchSpec\n : parsed.type === 'version' || parsed.type === 'range'\n ? parsed.fetchSpec\n : undefined\n\n return {\n name: parsed.name || spec,\n version,\n }\n } catch {\n // Fallback to simple parsing if npm-package-arg fails.\n const atIndex = spec.lastIndexOf('@')\n if (atIndex === -1 || spec.startsWith('@')) {\n // No version or scoped package without version.\n return { name: spec, version: undefined }\n }\n return {\n name: spec.slice(0, atIndex),\n version: spec.slice(atIndex + 1),\n }\n }\n}\n\n/**\n * Install package to ~/.socket/_dlx/<hash>/ if not already installed.\n * Uses pacote for installation (no npm CLI required).\n * Protected by process lock to prevent concurrent installation corruption.\n */\nasync function ensurePackageInstalled(\n packageName: string,\n packageSpec: string,\n force: boolean,\n): Promise<{ installed: boolean; packageDir: string }> {\n const cacheKey = generateCacheKey(packageSpec)\n const packageDir = normalizePath(path.join(getSocketDlxDir(), cacheKey))\n const installedDir = normalizePath(\n path.join(packageDir, 'node_modules', packageName),\n )\n\n // Ensure package directory exists before creating lock.\n // The lock directory will be created inside this directory.\n try {\n await safeMkdir(packageDir, { recursive: true })\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code\n if (code === 'EACCES' || code === 'EPERM') {\n throw new Error(\n `Permission denied creating package directory: ${packageDir}\\n` +\n 'Please check directory permissions or run with appropriate access.',\n { cause: e },\n )\n }\n if (code === 'EROFS') {\n throw new Error(\n `Cannot create package directory on read-only filesystem: ${packageDir}\\n` +\n 'Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.',\n { cause: e },\n )\n }\n throw new Error(`Failed to create package directory: ${packageDir}`, {\n cause: e,\n })\n }\n\n // Use process lock to prevent concurrent installations.\n // Uses npm npx's concurrency.lock naming convention.\n const lockPath = path.join(packageDir, 'concurrency.lock')\n\n return await processLock.withLock(\n lockPath,\n async () => {\n const fs = getFs()\n // Double-check if already installed (unless force).\n // Another process may have installed while waiting for lock.\n if (!force && fs.existsSync(installedDir)) {\n // Verify package.json exists.\n const pkgJsonPath = path.join(installedDir, 'package.json')\n if (fs.existsSync(pkgJsonPath)) {\n return { installed: false, packageDir }\n }\n }\n\n // Use pacote to extract the package.\n // Pacote leverages npm cache when available but doesn't require npm CLI.\n const pacoteCachePath = getPacoteCachePath()\n try {\n await getPacote().extract(packageSpec, installedDir, {\n // Use consistent pacote cache path (respects npm cache locations when available).\n cache: pacoteCachePath || path.join(packageDir, '.cache'),\n })\n } catch (e) {\n const code = (e as any).code\n if (code === 'E404' || code === 'ETARGET') {\n throw new Error(\n `Package not found: ${packageSpec}\\n` +\n 'Verify the package exists on npm registry and check the version.\\n' +\n `Visit https://www.npmjs.com/package/${packageName} to see available versions.`,\n { cause: e },\n )\n }\n if (\n code === 'ENOTFOUND' ||\n code === 'ETIMEDOUT' ||\n code === 'EAI_AGAIN'\n ) {\n throw new Error(\n `Network error installing ${packageSpec}\\n` +\n 'Check your internet connection and try again.',\n { cause: e },\n )\n }\n throw new Error(\n `Failed to install package: ${packageSpec}\\n` +\n `Destination: ${installedDir}\\n` +\n 'Check npm registry connectivity or package name.',\n { cause: e },\n )\n }\n\n return { installed: true, packageDir }\n },\n {\n // Align with npm npx locking strategy.\n staleMs: 5000,\n touchIntervalMs: 2000,\n },\n )\n}\n\n/**\n * Find the binary path for an installed package.\n * Intelligently handles packages with single or multiple binaries.\n */\nfunction findBinaryPath(\n packageDir: string,\n packageName: string,\n binaryName?: string,\n): string {\n const installedDir = normalizePath(\n path.join(packageDir, 'node_modules', packageName),\n )\n const pkgJsonPath = path.join(installedDir, 'package.json')\n\n // Read package.json to find bin entry.\n const pkgJson = readJsonSync(pkgJsonPath) as Record<string, unknown>\n const bin = pkgJson['bin']\n\n let binPath: string | undefined\n\n if (typeof bin === 'string') {\n // Single binary - use it directly.\n binPath = bin\n } else if (typeof bin === 'object' && bin !== null) {\n const binObj = bin as Record<string, string>\n const binKeys = Object.keys(binObj)\n\n // If only one binary, use it regardless of name.\n if (binKeys.length === 1) {\n binPath = binObj[binKeys[0]!]\n } else {\n // Multiple binaries - try to find the right one:\n // 1. User-provided binaryName\n // 2. Last segment of package name (e.g., 'cli' from '@socketsecurity/cli')\n // 3. Full package name without scope (e.g., 'cli' from '@socketsecurity/cli')\n // 4. First binary as fallback\n const lastSegment = packageName.split('/').pop()\n const candidates = [\n binaryName,\n lastSegment,\n packageName.replace(/^@[^/]+\\//, ''),\n ].filter(Boolean)\n\n for (const candidate of candidates) {\n if (candidate && binObj[candidate]) {\n binPath = binObj[candidate]\n break\n }\n }\n\n // Fallback to first binary if nothing matched.\n if (!binPath && binKeys.length > 0) {\n binPath = binObj[binKeys[0]!]\n }\n }\n }\n\n if (!binPath) {\n throw new Error(`No binary found for package \"${packageName}\"`)\n }\n\n return normalizePath(path.join(installedDir, binPath))\n}\n\n/**\n * Execute a package via DLX - install if needed and run its binary.\n *\n * This is the Socket equivalent of npx/pnpm dlx/yarn dlx, but using\n * our own cache directory (~/.socket/_dlx) and installation logic.\n *\n * Auto-forces reinstall for version ranges to get latest within range.\n *\n * @example\n * ```typescript\n * // Download and execute cdxgen\n * const result = await dlxPackage(\n * ['--version'],\n * { package: '@cyclonedx/cdxgen@10.0.0' }\n * )\n * await result.spawnPromise\n * ```\n */\nexport async function dlxPackage(\n args: readonly string[] | string[],\n options?: DlxPackageOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): Promise<DlxPackageResult> {\n // Download the package.\n const downloadResult = await downloadPackage(options!)\n\n // Execute the binary.\n const spawnPromise = executePackage(\n downloadResult.binaryPath,\n args,\n options?.spawnOptions,\n spawnExtra,\n )\n\n return {\n ...downloadResult,\n spawnPromise,\n }\n}\n\n/**\n * Download and install a package without executing it.\n * This is useful for self-update or when you need the package files\n * but don't want to run the binary immediately.\n *\n * @example\n * ```typescript\n * // Install @socketsecurity/cli without running it\n * const result = await downloadPackage({\n * package: '@socketsecurity/cli@1.2.0',\n * force: true\n * })\n * console.log('Installed to:', result.packageDir)\n * console.log('Binary at:', result.binaryPath)\n * ```\n */\nexport async function downloadPackage(\n options: DlxPackageOptions,\n): Promise<DownloadPackageResult> {\n const fs = getFs()\n const {\n binaryName,\n force: userForce,\n package: packageSpec,\n } = {\n __proto__: null,\n ...options,\n } as DlxPackageOptions\n\n // Parse package spec.\n const { name: packageName, version: packageVersion } =\n parsePackageSpec(packageSpec)\n\n // Auto-force for version ranges to get latest within range.\n // User can still override with explicit force: false if they want cache.\n const isVersionRange =\n packageVersion !== undefined && rangeOperatorsRegExp.test(packageVersion)\n const force = userForce !== undefined ? userForce : isVersionRange\n\n // Build full package spec for installation.\n const fullPackageSpec = packageVersion\n ? `${packageName}@${packageVersion}`\n : packageName\n\n // Ensure package is installed.\n const { installed, packageDir } = await ensurePackageInstalled(\n packageName,\n fullPackageSpec,\n force,\n )\n\n // Find binary path.\n const binaryPath = findBinaryPath(packageDir, packageName, binaryName)\n\n // Make binary executable on Unix systems.\n if (!WIN32 && fs.existsSync(binaryPath)) {\n try {\n fs.chmodSync(binaryPath, 0o755)\n } catch {\n // Ignore chmod errors.\n }\n }\n\n return {\n binaryPath,\n installed,\n packageDir,\n }\n}\n\n/**\n * Execute a package's binary.\n * The package must already be installed (use downloadPackage first).\n *\n * @example\n * ```typescript\n * // Execute an already-installed package\n * const downloaded = await downloadPackage({ package: 'cowsay@1.5.0' })\n * const result = await executePackage(\n * downloaded.binaryPath,\n * ['Hello World'],\n * { stdio: 'inherit' }\n * )\n * ```\n */\nexport function executePackage(\n binaryPath: string,\n args: readonly string[] | string[],\n spawnOptions?: SpawnOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): ReturnType<typeof spawn> {\n return spawn(binaryPath, args, spawnOptions, spawnExtra)\n}\n"],
|
|
5
|
-
"mappings": ";6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,oBAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GAgCA,IAAAM,EAAiB,
|
|
6
|
-
"names": ["dlx_package_exports", "__export", "dlxPackage", "downloadPackage", "executePackage", "__toCommonJS", "
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview DLX package execution - Install and execute npm packages.\n *\n * This module provides functionality to install and execute npm packages\n * in the ~/.socket/_dlx directory, similar to npx but with Socket's own cache.\n *\n * Uses content-addressed storage like npm's _npx:\n * - Hash is generated from package spec (name@version)\n * - Each unique spec gets its own directory: ~/.socket/_dlx/<hash>/\n * - Allows caching multiple versions of the same package\n *\n * Concurrency protection:\n * - Uses process-lock to prevent concurrent installation corruption\n * - Lock file created at ~/.socket/_dlx/<hash>/concurrency.lock\n * - Uses npm npx's concurrency.lock naming convention (5s stale, 2s touching)\n * - Prevents multiple processes from corrupting the same package installation\n *\n * Version range handling:\n * - Exact versions (1.0.0) use cache if available\n * - Range versions (^1.0.0, ~1.0.0) auto-force to get latest within range\n * - User can override with explicit force: false\n *\n * Key difference from dlx-binary.ts:\n * - dlx-binary.ts: Downloads standalone binaries from URLs\n * - dlx-package.ts: Installs npm packages from registries\n *\n * Implementation:\n * - Uses pacote for package installation (no npm CLI required)\n * - Split into downloadPackage() and executePackage() for flexibility\n * - dlxPackage() combines both for convenience\n */\n\nimport path from 'path'\n\nimport { WIN32 } from './constants/platform'\nimport { getPacoteCachePath } from './constants/packages'\nimport { generateCacheKey } from './dlx'\nimport { readJsonSync, safeMkdir } from './fs'\nimport { normalizePath } from './path'\nimport { getSocketDlxDir } from './paths'\nimport { processLock } from './process-lock'\nimport type { SpawnExtra, SpawnOptions } from './spawn'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n * Uses non-'node:' prefixed require to prevent Webpack bundling issues.\n *\n * @returns The Node.js fs module\n * @private\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 as typeof import('fs')\n}\n\nlet _npmPackageArg: typeof import('npm-package-arg') | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getNpmPackageArg() {\n if (_npmPackageArg === undefined) {\n _npmPackageArg = /*@__PURE__*/ require('./external/npm-package-arg')\n }\n return _npmPackageArg as typeof import('npm-package-arg')\n}\n\nlet _pacote: typeof import('pacote') | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPacote() {\n if (_pacote === undefined) {\n _pacote = /*@__PURE__*/ require('./external/pacote')\n }\n return _pacote as typeof import('pacote')\n}\n\n/**\n * Regex to check if a version string contains range operators.\n * Matches any version with range operators: ~, ^, >, <, =, x, X, *, spaces, or ||.\n */\nconst rangeOperatorsRegExp = /[~^><=xX* ]|\\|\\|/\n\nexport interface DownloadPackageResult {\n /** Path to the installed package directory. */\n packageDir: string\n /** Path to the binary. */\n binaryPath: string\n /** Whether the package was newly installed. */\n installed: boolean\n}\n\nexport interface DlxPackageOptions {\n /**\n * Package to install (e.g., '@cyclonedx/cdxgen@10.0.0').\n * Aligns with npx --package flag.\n */\n package: string\n\n /**\n * Binary name to execute (optional - auto-detected in most cases).\n *\n * Auto-detection logic:\n * 1. If package has only one binary, uses it automatically\n * 2. Tries user-provided binaryName\n * 3. Tries last segment of package name (e.g., 'cli' from '@socketsecurity/cli')\n * 4. Falls back to first binary\n *\n * Only needed when package has multiple binaries and auto-detection fails.\n *\n * @example\n * // Auto-detected (single binary)\n * { package: '@socketsecurity/cli' } // Finds 'socket' binary automatically\n *\n * // Explicit (multiple binaries)\n * { package: 'some-tool', binaryName: 'specific-tool' }\n */\n binaryName?: string | undefined\n\n /**\n * Force reinstallation even if package exists.\n * Aligns with npx --yes/-y flag behavior.\n */\n force?: boolean | undefined\n\n /**\n * Skip confirmation prompts (auto-approve).\n * Aligns with npx --yes/-y flag.\n */\n yes?: boolean | undefined\n\n /**\n * Suppress output (quiet mode).\n * Aligns with npx --quiet/-q and pnpm --silent/-s flags.\n */\n quiet?: boolean | undefined\n\n /**\n * Additional spawn options for the execution.\n */\n spawnOptions?: SpawnOptions | undefined\n}\n\nexport interface DlxPackageResult {\n /** Path to the installed package directory. */\n packageDir: string\n /** Path to the binary that was executed. */\n binaryPath: string\n /** Whether the package was newly installed. */\n installed: boolean\n /** The spawn promise for the running process. */\n spawnPromise: ReturnType<typeof spawn>\n}\n\n/**\n * Parse package spec into name and version using npm-package-arg.\n * Examples:\n * - 'lodash@4.17.21' \u2192 { name: 'lodash', version: '4.17.21' }\n * - '@scope/pkg@1.0.0' \u2192 { name: '@scope/pkg', version: '1.0.0' }\n * - 'lodash' \u2192 { name: 'lodash', version: undefined }\n */\nfunction parsePackageSpec(spec: string): {\n name: string\n version: string | undefined\n} {\n try {\n const npa = getNpmPackageArg()\n const parsed = npa(spec)\n\n // Extract version from different types of specs.\n // For registry specs, use fetchSpec (the version/range).\n // For git/file/etc, version will be undefined.\n const version =\n parsed.type === 'tag'\n ? parsed.fetchSpec\n : parsed.type === 'version' || parsed.type === 'range'\n ? parsed.fetchSpec\n : undefined\n\n return {\n name: parsed.name || spec,\n version,\n }\n } catch {\n // Fallback to simple parsing if npm-package-arg fails.\n const atIndex = spec.lastIndexOf('@')\n if (atIndex === -1 || spec.startsWith('@')) {\n // No version or scoped package without version.\n return { name: spec, version: undefined }\n }\n return {\n name: spec.slice(0, atIndex),\n version: spec.slice(atIndex + 1),\n }\n }\n}\n\n/**\n * Install package to ~/.socket/_dlx/<hash>/ if not already installed.\n * Uses pacote for installation (no npm CLI required).\n * Protected by process lock to prevent concurrent installation corruption.\n */\nasync function ensurePackageInstalled(\n packageName: string,\n packageSpec: string,\n force: boolean,\n): Promise<{ installed: boolean; packageDir: string }> {\n const cacheKey = generateCacheKey(packageSpec)\n const packageDir = normalizePath(path.join(getSocketDlxDir(), cacheKey))\n const installedDir = normalizePath(\n path.join(packageDir, 'node_modules', packageName),\n )\n\n // Ensure package directory exists before creating lock.\n // The lock directory will be created inside this directory.\n try {\n await safeMkdir(packageDir, { recursive: true })\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code\n if (code === 'EACCES' || code === 'EPERM') {\n throw new Error(\n `Permission denied creating package directory: ${packageDir}\\n` +\n 'Please check directory permissions or run with appropriate access.',\n { cause: e },\n )\n }\n if (code === 'EROFS') {\n throw new Error(\n `Cannot create package directory on read-only filesystem: ${packageDir}\\n` +\n 'Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.',\n { cause: e },\n )\n }\n throw new Error(`Failed to create package directory: ${packageDir}`, {\n cause: e,\n })\n }\n\n // Use process lock to prevent concurrent installations.\n // Uses npm npx's concurrency.lock naming convention.\n const lockPath = path.join(packageDir, 'concurrency.lock')\n\n return await processLock.withLock(\n lockPath,\n async () => {\n const fs = getFs()\n // Double-check if already installed (unless force).\n // Another process may have installed while waiting for lock.\n if (!force && fs.existsSync(installedDir)) {\n // Verify package.json exists.\n const pkgJsonPath = path.join(installedDir, 'package.json')\n if (fs.existsSync(pkgJsonPath)) {\n return { installed: false, packageDir }\n }\n }\n\n // Use pacote to extract the package.\n // Pacote leverages npm cache when available but doesn't require npm CLI.\n const pacoteCachePath = getPacoteCachePath()\n try {\n await getPacote().extract(packageSpec, installedDir, {\n // Use consistent pacote cache path (respects npm cache locations when available).\n cache: pacoteCachePath || path.join(packageDir, '.cache'),\n })\n } catch (e) {\n const code = (e as any).code\n if (code === 'E404' || code === 'ETARGET') {\n throw new Error(\n `Package not found: ${packageSpec}\\n` +\n 'Verify the package exists on npm registry and check the version.\\n' +\n `Visit https://www.npmjs.com/package/${packageName} to see available versions.`,\n { cause: e },\n )\n }\n if (\n code === 'ENOTFOUND' ||\n code === 'ETIMEDOUT' ||\n code === 'EAI_AGAIN'\n ) {\n throw new Error(\n `Network error installing ${packageSpec}\\n` +\n 'Check your internet connection and try again.',\n { cause: e },\n )\n }\n throw new Error(\n `Failed to install package: ${packageSpec}\\n` +\n `Destination: ${installedDir}\\n` +\n 'Check npm registry connectivity or package name.',\n { cause: e },\n )\n }\n\n return { installed: true, packageDir }\n },\n {\n // Align with npm npx locking strategy.\n staleMs: 5000,\n touchIntervalMs: 2000,\n },\n )\n}\n\n/**\n * Resolve binary path with cross-platform wrapper support.\n * On Windows, checks for .cmd, .bat, .ps1, .exe wrappers in order.\n * On Unix, uses path directly.\n *\n * Aligns with npm/npx binary resolution strategy.\n */\nfunction resolveBinaryPath(basePath: string): string {\n const fs = getFs()\n\n if (!WIN32) {\n // Unix: use path directly\n return basePath\n }\n\n // Windows: check for wrappers in priority order\n // Order matches npm bin-links creation: .cmd, .ps1, .exe, then bare\n const extensions = ['.cmd', '.bat', '.ps1', '.exe', '']\n\n for (const ext of extensions) {\n const testPath = basePath + ext\n if (fs.existsSync(testPath)) {\n return testPath\n }\n }\n\n // Fallback to original path if no wrapper found\n return basePath\n}\n\n/**\n * Find the binary path for an installed package.\n * Intelligently handles packages with single or multiple binaries.\n * Resolves platform-specific wrappers (.cmd, .ps1, etc.) on Windows.\n */\nfunction findBinaryPath(\n packageDir: string,\n packageName: string,\n binaryName?: string,\n): string {\n const installedDir = normalizePath(\n path.join(packageDir, 'node_modules', packageName),\n )\n const pkgJsonPath = path.join(installedDir, 'package.json')\n\n // Read package.json to find bin entry.\n const pkgJson = readJsonSync(pkgJsonPath) as Record<string, unknown>\n const bin = pkgJson['bin']\n\n let binPath: string | undefined\n\n if (typeof bin === 'string') {\n // Single binary - use it directly.\n binPath = bin\n } else if (typeof bin === 'object' && bin !== null) {\n const binObj = bin as Record<string, string>\n const binKeys = Object.keys(binObj)\n\n // If only one binary, use it regardless of name.\n if (binKeys.length === 1) {\n binPath = binObj[binKeys[0]!]\n } else {\n // Multiple binaries - try to find the right one:\n // 1. User-provided binaryName\n // 2. Last segment of package name (e.g., 'cli' from '@socketsecurity/cli')\n // 3. Full package name without scope (e.g., 'cli' from '@socketsecurity/cli')\n // 4. First binary as fallback\n const lastSegment = packageName.split('/').pop()\n const candidates = [\n binaryName,\n lastSegment,\n packageName.replace(/^@[^/]+\\//, ''),\n ].filter(Boolean)\n\n for (const candidate of candidates) {\n if (candidate && binObj[candidate]) {\n binPath = binObj[candidate]\n break\n }\n }\n\n // Fallback to first binary if nothing matched.\n if (!binPath && binKeys.length > 0) {\n binPath = binObj[binKeys[0]!]\n }\n }\n }\n\n if (!binPath) {\n throw new Error(`No binary found for package \"${packageName}\"`)\n }\n\n const rawPath = normalizePath(path.join(installedDir, binPath))\n\n // Resolve platform-specific wrapper (Windows .cmd/.ps1/etc.)\n return resolveBinaryPath(rawPath)\n}\n\n/**\n * Execute a package via DLX - install if needed and run its binary.\n *\n * This is the Socket equivalent of npx/pnpm dlx/yarn dlx, but using\n * our own cache directory (~/.socket/_dlx) and installation logic.\n *\n * Auto-forces reinstall for version ranges to get latest within range.\n *\n * @example\n * ```typescript\n * // Download and execute cdxgen\n * const result = await dlxPackage(\n * ['--version'],\n * { package: '@cyclonedx/cdxgen@10.0.0' }\n * )\n * await result.spawnPromise\n * ```\n */\nexport async function dlxPackage(\n args: readonly string[] | string[],\n options?: DlxPackageOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): Promise<DlxPackageResult> {\n // Download the package.\n const downloadResult = await downloadPackage(options!)\n\n // Execute the binary.\n const spawnPromise = executePackage(\n downloadResult.binaryPath,\n args,\n options?.spawnOptions,\n spawnExtra,\n )\n\n return {\n ...downloadResult,\n spawnPromise,\n }\n}\n\n/**\n * Download and install a package without executing it.\n * This is useful for self-update or when you need the package files\n * but don't want to run the binary immediately.\n *\n * @example\n * ```typescript\n * // Install @socketsecurity/cli without running it\n * const result = await downloadPackage({\n * package: '@socketsecurity/cli@1.2.0',\n * force: true\n * })\n * console.log('Installed to:', result.packageDir)\n * console.log('Binary at:', result.binaryPath)\n * ```\n */\nexport async function downloadPackage(\n options: DlxPackageOptions,\n): Promise<DownloadPackageResult> {\n const fs = getFs()\n const {\n binaryName,\n force: userForce,\n package: packageSpec,\n yes,\n } = {\n __proto__: null,\n ...options,\n } as DlxPackageOptions\n\n // Parse package spec.\n const { name: packageName, version: packageVersion } =\n parsePackageSpec(packageSpec)\n\n // Determine force behavior:\n // 1. Explicit force takes precedence\n // 2. --yes flag implies force (auto-approve/skip prompts)\n // 3. Version ranges auto-force to get latest\n const isVersionRange =\n packageVersion !== undefined && rangeOperatorsRegExp.test(packageVersion)\n const force =\n userForce !== undefined ? userForce : yes === true ? true : isVersionRange\n\n // Build full package spec for installation.\n const fullPackageSpec = packageVersion\n ? `${packageName}@${packageVersion}`\n : packageName\n\n // Ensure package is installed.\n const { installed, packageDir } = await ensurePackageInstalled(\n packageName,\n fullPackageSpec,\n force,\n )\n\n // Find binary path.\n const binaryPath = findBinaryPath(packageDir, packageName, binaryName)\n\n // Make binary executable on Unix systems.\n if (!WIN32 && fs.existsSync(binaryPath)) {\n try {\n fs.chmodSync(binaryPath, 0o755)\n } catch {\n // Ignore chmod errors.\n }\n }\n\n return {\n binaryPath,\n installed,\n packageDir,\n }\n}\n\n/**\n * Execute a package's binary with cross-platform shell handling.\n * The package must already be installed (use downloadPackage first).\n *\n * On Windows, script files (.bat, .cmd, .ps1) require shell: true.\n * Matches npm/npx execution behavior.\n *\n * @example\n * ```typescript\n * // Execute an already-installed package\n * const downloaded = await downloadPackage({ package: 'cowsay@1.5.0' })\n * const result = await executePackage(\n * downloaded.binaryPath,\n * ['Hello World'],\n * { stdio: 'inherit' }\n * )\n * ```\n */\nexport function executePackage(\n binaryPath: string,\n args: readonly string[] | string[],\n spawnOptions?: SpawnOptions | undefined,\n spawnExtra?: SpawnExtra | undefined,\n): ReturnType<typeof spawn> {\n // On Windows, script files (.bat, .cmd, .ps1) require shell: true\n // because they are not executable on their own and must be run through cmd.exe.\n // .exe files are actual binaries and don't need shell mode.\n const needsShell = WIN32 && /\\.(?:bat|cmd|ps1)$/i.test(binaryPath)\n\n const finalOptions = needsShell\n ? {\n ...spawnOptions,\n shell: true,\n }\n : spawnOptions\n\n return spawn(binaryPath, args, finalOptions, spawnExtra)\n}\n"],
|
|
5
|
+
"mappings": ";6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,oBAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GAgCA,IAAAM,EAAiB,mBAEjBC,EAAsB,gCACtBC,EAAmC,gCACnCC,EAAiC,iBACjCC,EAAwC,gBACxCJ,EAA8B,kBAC9BK,EAAgC,mBAChCC,EAA4B,0BAE5BC,EAAsB,mBAEtB,IAAIC,EASJ,SAASC,GAAQ,CACf,OAAID,IAAQ,SAGVA,EAAoB,QAAQ,SAAS,GAEhCA,CACT,CAEA,IAAIE,EAEJ,SAASC,GAAmB,CAC1B,OAAID,IAAmB,SACrBA,EAA+B,QAAQ,4BAA4B,GAE9DA,CACT,CAEA,IAAIE,EAEJ,SAASC,GAAY,CACnB,OAAID,IAAY,SACdA,EAAwB,QAAQ,mBAAmB,GAE9CA,CACT,CAMA,MAAME,EAAuB,mBAgF7B,SAASC,EAAiBC,EAGxB,CACA,GA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E,UAAAsC,EAAW,WAAAlC,CAAW,EAAI,MAAML,EACtCC,EACAqC,EACAnC,CACF,EAGMqC,EAAarB,EAAed,EAAYJ,EAAamB,CAAU,EAGrE,GAAI,CAAC,SAAST,EAAG,WAAW6B,CAAU,EACpC,GAAI,CACF7B,EAAG,UAAU6B,EAAY,GAAK,CAChC,MAAQ,CAER,CAGF,MAAO,CACL,WAAAA,EACA,UAAAD,EACA,WAAAlC,CACF,CACF,CAoBO,SAAS3B,EACd8D,EACAX,EACAY,EACAV,EAC0B,CAM1B,MAAMW,EAFa,SAAS,sBAAsB,KAAKF,CAAU,EAG7D,CACE,GAAGC,EACH,MAAO,EACT,EACAA,EAEJ,SAAO,SAAMD,EAAYX,EAAMa,EAAcX,CAAU,CACzD",
|
|
6
|
+
"names": ["dlx_package_exports", "__export", "dlxPackage", "downloadPackage", "executePackage", "__toCommonJS", "import_path", "import_platform", "import_packages", "import_dlx", "import_fs", "import_paths", "import_process_lock", "import_spawn", "_fs", "getFs", "_npmPackageArg", "getNpmPackageArg", "_pacote", "getPacote", "rangeOperatorsRegExp", "parsePackageSpec", "spec", "parsed", "version", "atIndex", "ensurePackageInstalled", "packageName", "packageSpec", "force", "cacheKey", "packageDir", "path", "installedDir", "e", "code", "lockPath", "fs", "pkgJsonPath", "pacoteCachePath", "resolveBinaryPath", "basePath", "extensions", "ext", "testPath", "findBinaryPath", "binaryName", "bin", "binPath", "binObj", "binKeys", "lastSegment", "candidates", "candidate", "rawPath", "args", "options", "spawnExtra", "downloadResult", "spawnPromise", "userForce", "yes", "packageVersion", "isVersionRange", "fullPackageSpec", "installed", "binaryPath", "spawnOptions", "finalOptions"]
|
|
7
7
|
}
|