@socketsecurity/lib 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/bin.d.ts +27 -4
- package/dist/bin.js +1 -1
- package/dist/bin.js.map +3 -3
- package/dist/dlx-binary.js +1 -1
- package/dist/dlx-binary.js.map +3 -3
- package/dist/download-lock.d.ts +2 -1
- package/dist/download-lock.js +1 -1
- package/dist/download-lock.js.map +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.4.0](https://github.com/SocketDev/socket-lib/releases/tag/v2.4.0) - 2025-10-28
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Download locking aligned with npm**: Reduced default `staleTimeout` in `downloadWithLock()` from 300 seconds to 10 seconds to align with npm's npx locking strategy
|
|
13
|
+
- Prevents stale locks from blocking downloads for extended periods
|
|
14
|
+
- Matches npm's battle-tested timeout range (5-10 seconds)
|
|
15
|
+
- Binary downloads now protected against concurrent corruption
|
|
16
|
+
- **Binary download protection**: `dlxBinary.downloadBinary()` now uses `downloadWithLock()` to prevent corruption when multiple processes download the same binary concurrently
|
|
17
|
+
- Eliminates race conditions during parallel binary downloads
|
|
18
|
+
- Maintains checksum verification and executable permissions
|
|
19
|
+
|
|
20
|
+
## [2.3.0](https://github.com/SocketDev/socket-lib/releases/tag/v2.3.0) - 2025-10-28
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- **Binary utility wrapper functions**: Added `which()` and `whichSync()` wrapper functions to `bin` module
|
|
25
|
+
- Cross-platform binary lookup that respects PATH environment variable
|
|
26
|
+
- Synchronous and asynchronous variants for different use cases
|
|
27
|
+
- Integrates with existing binary resolution utilities
|
|
28
|
+
|
|
8
29
|
## [2.2.1](https://github.com/SocketDev/socket-lib/releases/tag/v2.2.1) - 2025-10-28
|
|
9
30
|
|
|
10
31
|
### Fixed
|
package/dist/bin.d.ts
CHANGED
|
@@ -10,18 +10,41 @@ export declare function execBin(binPath: string, args?: string[], options?: impo
|
|
|
10
10
|
stdout: string | Buffer<ArrayBufferLike>;
|
|
11
11
|
stderr: string | Buffer<ArrayBufferLike>;
|
|
12
12
|
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Options for the which function.
|
|
15
|
+
*/
|
|
16
|
+
export interface WhichOptions {
|
|
17
|
+
/** If true, return all matches instead of just the first one. */
|
|
18
|
+
all?: boolean | undefined;
|
|
19
|
+
/** If true, return null instead of throwing when no match is found. */
|
|
20
|
+
nothrow?: boolean | undefined;
|
|
21
|
+
/** Path to search in. */
|
|
22
|
+
path?: string | undefined;
|
|
23
|
+
/** Path separator character. */
|
|
24
|
+
pathExt?: string | undefined;
|
|
25
|
+
/** Environment variables to use. */
|
|
26
|
+
env?: Record<string, string | undefined> | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Find an executable in the system PATH asynchronously.
|
|
30
|
+
* Wrapper around the which package for lazy loading.
|
|
31
|
+
*/
|
|
32
|
+
export declare function which(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Find an executable in the system PATH synchronously.
|
|
35
|
+
* Wrapper around the which package for lazy loading.
|
|
36
|
+
*/
|
|
37
|
+
export declare function whichSync(binName: string, options?: WhichOptions): string | string[] | undefined;
|
|
13
38
|
/**
|
|
14
39
|
* Find and resolve a binary in the system PATH asynchronously.
|
|
15
|
-
* @template {import('which').Options} T
|
|
16
40
|
* @throws {Error} If the binary is not found and nothrow is false.
|
|
17
41
|
*/
|
|
18
|
-
export declare function whichBin(binName: string, options?:
|
|
42
|
+
export declare function whichBin(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
|
|
19
43
|
/**
|
|
20
44
|
* Find and resolve a binary in the system PATH synchronously.
|
|
21
|
-
* @template {import('which').Options} T
|
|
22
45
|
* @throws {Error} If the binary is not found and nothrow is false.
|
|
23
46
|
*/
|
|
24
|
-
export declare function whichBinSync(binName: string, options?:
|
|
47
|
+
export declare function whichBinSync(binName: string, options?: WhichOptions): string | string[] | undefined;
|
|
25
48
|
/**
|
|
26
49
|
* Check if a directory path contains any shadow bin patterns.
|
|
27
50
|
*/
|
package/dist/bin.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var j=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var X=(n,e)=>{for(var i in e)j(n,i,{get:e[i],enumerable:!0})},k=(n,e,i,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of W(e))!F.call(n,s)&&s!==i&&j(n,s,{get:()=>e[s],enumerable:!(c=J(e,s))||c.enumerable});return n};var q=n=>k(j({},"__esModule",{value:!0}),n);var U={};X(U,{execBin:()=>M,findRealBin:()=>_,findRealNpm:()=>Y,findRealPnpm:()=>H,findRealYarn:()=>T,isShadowBinPath:()=>C,resolveBinPathSync:()=>g,which:()=>z,whichBin:()=>D,whichBinSync:()=>A,whichSync:()=>R});module.exports=q(U);var h=require("#env/home"),x=require("#env/windows"),O=require("#env/xdg"),$=require("#constants/platform"),B=require("./fs"),l=require("./path"),E=require("./spawn");let I;function P(){return I===void 0&&(I=require("node:fs")),I}let v;function y(){return v===void 0&&(v=require("node:path")),v}let N;function w(){return N===void 0&&(N=require("./external/which")),N}async function M(n,e,i){const c=(0,l.isPath)(n)?g(n):await D(n);if(!c){const r=new Error(`Binary not found: ${n}`);throw r.code="ENOENT",r}const s=Array.isArray(c)?c[0]:c;return await(0,E.spawn)(s,e??[],{shell:$.WIN32,...i})}async function z(n,e){return await w()(n,e)}function R(n,e){return w().sync(n,e)}async function D(n,e){const i=w(),c={nothrow:!0,...e},s=await i(n,c);if(c?.all){const r=Array.isArray(s)?s:typeof s=="string"?[s]:void 0;return r?.length?r.map(p=>g(p)):r}if(s)return g(s)}function A(n,e){const i={nothrow:!0,...e},c=R(n,i);if(i.all){const s=Array.isArray(c)?c:typeof c=="string"?[c]:void 0;return s?.length?s.map(r=>g(r)):s}if(c)return g(c)}function C(n){return n?n.replace(/\\/g,"/").includes("node_modules/.bin"):!1}function _(n,e=[]){const i=P(),c=y(),s=w();for(const p of e)if(i?.existsSync(p))return p;const r=s?.sync(n,{nothrow:!0});if(r){const p=c?.dirname(r);if(C(p)){const a=s?.sync(n,{all:!0,nothrow:!0})||[],d=Array.isArray(a)?a:typeof a=="string"?[a]:[];for(const m of d){const o=c?.dirname(m);if(!C(o))return m}}return r}}function Y(){const n=P(),e=y(),i=e?.dirname(process.execPath),c=e?.join(i,"npm");if(n?.existsSync(c))return c;const r=_("npm",["/usr/local/bin/npm","/usr/bin/npm"]);if(r&&n?.existsSync(r))return r;const p=A("npm",{nothrow:!0});return p&&typeof p=="string"&&n?.existsSync(p)?p:"npm"}function H(){const n=y(),e=$.WIN32?[n?.join((0,x.getAppdata)(),"npm","pnpm.cmd"),n?.join((0,x.getAppdata)(),"npm","pnpm"),n?.join((0,x.getLocalappdata)(),"pnpm","pnpm.cmd"),n?.join((0,x.getLocalappdata)(),"pnpm","pnpm"),"C:\\Program Files\\nodejs\\pnpm.cmd","C:\\Program Files\\nodejs\\pnpm"].filter(Boolean):["/usr/local/bin/pnpm","/usr/bin/pnpm",n?.join((0,O.getXdgDataHome)()||`${(0,h.getHome)()}/.local/share`,"pnpm/pnpm"),n?.join((0,h.getHome)(),".pnpm/pnpm")].filter(Boolean);return _("pnpm",e)??""}function T(){const n=y(),e=["/usr/local/bin/yarn","/usr/bin/yarn",n?.join((0,h.getHome)(),".yarn/bin/yarn"),n?.join((0,h.getHome)(),".config/yarn/global/node_modules/.bin/yarn")].filter(Boolean);return _("yarn",e)??""}function g(n){const e=P(),i=y();if(!i?.isAbsolute(n))try{const a=A(n);a&&(n=a)}catch{}if(n=(0,l.normalizePath)(n),n===".")return n;const c=i?.extname(n),s=c.toLowerCase(),r=i?.basename(n,c),p=r==="node"?-1:/(?<=\/)\.volta\//i.exec(n)?.index??-1;if(p!==-1){const a=n.slice(0,p),d=i?.join(a,"tools"),m=i?.join(d,"image"),o=i?.join(d,"user"),t=(0,B.readJsonSync)(i?.join(o,"platform.json"),{throws:!1}),u=t?.node?.runtime,L=t?.node?.npm;let f="";if(r==="npm"||r==="npx"){if(L){const S=`bin/${r}-cli.js`;f=i?.join(m,`npm/${L}/${S}`),u&&!e?.existsSync(f)&&(f=i?.join(m,`node/${u}/lib/node_modules/npm/${S}`),e?.existsSync(f)||(f=""))}}else{const S=i?.join(o,"bin"),b=(0,B.readJsonSync)(i?.join(S,`${r}.json`),{throws:!1})?.package;b&&(f=i?.join(m,`packages/${b}/bin/${r}`),e?.existsSync(f)||(f=`${f}.cmd`,e?.existsSync(f)||(f="")))}if(f){try{return(0,l.normalizePath)(e?.realpathSync.native(f))}catch{}return f}}if($.WIN32){const a=s===""||s===".cmd"||s===".exe"||s===".ps1",d=r==="npm"||r==="npx",m=r==="pnpm"||r==="yarn";if(a&&d){const t=i?.join(i?.dirname(n),`node_modules/npm/bin/${r}-cli.js`);if(e?.existsSync(t)){try{return e?.realpathSync.native(t)}catch{}return t}}let o="";if(a&&s!==".exe"&&e?.existsSync(n)){const t=e?.readFileSync(n,"utf8");d?s===".cmd"?o=r==="npm"?/(?<="NPM_CLI_JS=%~dp0\\).*(?=")/.exec(t)?.[0]||"":/(?<="NPX_CLI_JS=%~dp0\\).*(?=")/.exec(t)?.[0]||"":s===""?o=r==="npm"?/(?<=NPM_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(t)?.[0]||"":/(?<=NPX_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(t)?.[0]||"":s===".ps1"&&(o=r==="npm"?/(?<=\$NPM_CLI_JS="\$PSScriptRoot\/).*(?=")/.exec(t)?.[0]||"":/(?<=\$NPX_CLI_JS="\$PSScriptRoot\/).*(?=")/.exec(t)?.[0]||""):m?s===".cmd"?(o=/(?<=node\s+")%~dp0\\([^"]+)(?="\s+%\*)/.exec(t)?.[1]||"",o||(o=/(?<="%~dp0\\[^"]*node[^"]*"\s+")%~dp0\\([^"]+)(?="\s+%\*)/.exec(t)?.[1]||""),o||(o=/(?<="%dp0%\\).*(?=" %\*\r\n)/.exec(t)?.[0]||"")):s===""?(o=/(?<="\$basedir\/)\.tools\/pnpm\/[^"]+(?="\s+"\$@")/.exec(t)?.[0]||"",o||(o=/(?<=exec\s+node\s+"\$basedir\/)\.tools\/pnpm\/[^"]+(?="\s+"\$@")/.exec(t)?.[0]||""),o||(o=/(?<="\$basedir\/).*(?=" "\$@"\n)/.exec(t)?.[0]||"")):s===".ps1"&&(o=/(?<="\$basedir\/).*(?=" $args\n)/.exec(t)?.[0]||""):s===".cmd"?o=/(?<="%dp0%\\).*(?=" %\*\r\n)/.exec(t)?.[0]||"":s===""?o=/(?<="$basedir\/).*(?=" "\$@"\n)/.exec(t)?.[0]||"":s===".ps1"&&(o=/(?<="\$basedir\/).*(?=" $args\n)/.exec(t)?.[0]||""),o&&(n=(0,l.normalizePath)(i?.resolve(i?.dirname(n),o)))}}else{let a=s==="";const d=r==="pnpm"||r==="yarn",m=r==="npm"||r==="npx";if(d&&n.includes("/.bin/pnpm/bin/")){const o=n.indexOf("/.bin/pnpm");if(o!==-1){const t=n.slice(0,o+10);try{(e?.statSync(t)).isFile()&&(n=(0,l.normalizePath)(t),a=!i?.extname(n))}catch{}}}if(a&&(d||m)&&e?.existsSync(n)){const o=e?.readFileSync(n,"utf8");let t="";if(d){if(t=/(?<="\$basedir\/)\.tools\/[^"]+(?="\s+"\$@")/.exec(o)?.[0]||"",t||(t=/(?<="\$basedir\/)[^"]+(?="\s+"\$@")/.exec(o)?.[0]||""),!t){const u=/exec\s+node\s+"?\$basedir\/([^"]+)"?\s+"\$@"/.exec(o);u&&(t=u[1]||"")}t&&r==="pnpm"&&t.startsWith("pnpm/")&&(t=`../${t}`)}else m&&(t=r==="npm"?/(?<=NPM_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(o)?.[0]||"":/(?<=NPX_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(o)?.[0]||"");t&&(n=(0,l.normalizePath)(i?.resolve(i?.dirname(n),t)))}}try{const a=e?.realpathSync.native(n);return(0,l.normalizePath)(a)}catch{}return(0,l.normalizePath)(n)}0&&(module.exports={execBin,findRealBin,findRealNpm,findRealPnpm,findRealYarn,isShadowBinPath,resolveBinPathSync,which,whichBin,whichBinSync,whichSync});
|
|
3
3
|
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/bin.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Binary path resolution and execution utilities for package managers.\n * Provides cross-platform bin path lookup, command execution, and path normalization.\n */\n\nimport { getHome } from '#env/home'\nimport { getAppdata, getLocalappdata } from '#env/windows'\nimport { getXdgDataHome } from '#env/xdg'\n\nimport { WIN32 } from '#constants/platform'\nimport { readJsonSync } from './fs'\nimport { getOwn } from './objects'\nimport { isPath, normalizePath } from './path'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('node:fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getFs() {\n if (_fs === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _fs = /*@__PURE__*/ require('node:fs')\n }\n return _fs!\n}\n\nlet _path: typeof import('node:path') | undefined\n/**\n * Lazily load the path module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPath() {\n if (_path === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _path = /*@__PURE__*/ require('node:path')\n }\n return _path!\n}\n\nlet _which: typeof import('which') | undefined\n/**\n * Lazily load the which module for finding executables.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getWhich() {\n if (_which === undefined) {\n _which = /*@__PURE__*/ require('./external/which')\n }\n return _which!\n}\n\n/**\n * Execute a binary with the given arguments.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport async function execBin(\n binPath: string,\n args?: string[],\n options?: import('./spawn').SpawnOptions,\n) {\n // Resolve the binary path.\n const resolvedPath = isPath(binPath)\n ? resolveBinPathSync(binPath)\n : await whichBin(binPath)\n\n if (!resolvedPath) {\n const error = new Error(`Binary not found: ${binPath}`) as Error & {\n code: string\n }\n error.code = 'ENOENT'\n throw error\n }\n\n // Execute the binary directly.\n const binCommand = Array.isArray(resolvedPath)\n ? resolvedPath[0]!\n : resolvedPath\n // On Windows, binaries are often .cmd files that require shell to execute.\n return await spawn(binCommand, args ?? [], {\n shell: WIN32,\n ...options,\n })\n}\n\n/**\n * Find and resolve a binary in the system PATH asynchronously.\n * @template {import('which').Options} T\n * @throws {Error} If the binary is not found and nothrow is false.\n */\nexport async function whichBin(\n binName: string,\n options?: import('which').Options,\n): Promise<string | string[] | undefined> {\n const which = getWhich()\n // Default to nothrow: true if not specified to return undefined instead of throwing\n const opts = { nothrow: true, ...options }\n // Depending on options `which` may throw if `binName` is not found.\n // With nothrow: true, it returns null when `binName` is not found.\n const result = await which?.(binName, opts)\n\n // When 'all: true' is specified, ensure we always return an array.\n if (options?.all) {\n const paths = Array.isArray(result)\n ? result\n : typeof result === 'string'\n ? [result]\n : undefined\n // If all is true and we have paths, resolve each one.\n return paths?.length ? paths.map(p => resolveBinPathSync(p)) : paths\n }\n\n // If result is undefined (binary not found), return undefined\n if (!result) {\n return undefined\n }\n\n return resolveBinPathSync(result)\n}\n\n/**\n * Find and resolve a binary in the system PATH synchronously.\n * @template {import('which').Options} T\n * @throws {Error} If the binary is not found and nothrow is false.\n */\nexport function whichBinSync(\n binName: string,\n options?: import('which').Options,\n): string | string[] | undefined {\n // Default to nothrow: true if not specified to return undefined instead of throwing\n const opts = { nothrow: true, ...options }\n // Depending on options `which` may throw if `binName` is not found.\n // With nothrow: true, it returns null when `binName` is not found.\n const result = getWhich()?.sync(binName, opts)\n\n // When 'all: true' is specified, ensure we always return an array.\n if (getOwn(options, 'all')) {\n const paths = Array.isArray(result)\n ? result\n : typeof result === 'string'\n ? [result]\n : undefined\n // If all is true and we have paths, resolve each one.\n return paths?.length ? paths.map(p => resolveBinPathSync(p)) : paths\n }\n\n // If result is undefined (binary not found), return undefined\n if (!result) {\n return undefined\n }\n\n return resolveBinPathSync(result)\n}\n\n/**\n * Check if a directory path contains any shadow bin patterns.\n */\nexport function isShadowBinPath(dirPath: string | undefined): boolean {\n if (!dirPath) {\n return false\n }\n // Check for node_modules/.bin pattern (Unix and Windows)\n const normalized = dirPath.replace(/\\\\/g, '/')\n return normalized.includes('node_modules/.bin')\n}\n\n/**\n * Find the real executable for a binary, bypassing shadow bins.\n */\nexport function findRealBin(\n binName: string,\n commonPaths: string[] = [],\n): string | undefined {\n const fs = getFs()\n const path = getPath()\n const which = getWhich()\n\n // Try common locations first.\n for (const binPath of commonPaths) {\n if (fs?.existsSync(binPath)) {\n return binPath\n }\n }\n\n // Fall back to which.sync if no direct path found.\n const binPath = which?.sync(binName, { nothrow: true })\n if (binPath) {\n const binDir = path?.dirname(binPath)\n\n if (isShadowBinPath(binDir)) {\n // This is likely a shadowed binary, try to find the real one.\n const allPaths = which?.sync(binName, { all: true, nothrow: true }) || []\n // Ensure allPaths is an array.\n const pathsArray = Array.isArray(allPaths)\n ? allPaths\n : typeof allPaths === 'string'\n ? [allPaths]\n : []\n\n for (const altPath of pathsArray) {\n const altDir = path?.dirname(altPath)\n if (!isShadowBinPath(altDir)) {\n return altPath\n }\n }\n }\n return binPath\n }\n // If all else fails, return undefined to indicate binary not found.\n return undefined\n}\n\n/**\n * Find the real npm executable, bypassing any aliases and shadow bins.\n */\nexport function findRealNpm(): string {\n const fs = getFs()\n const path = getPath()\n\n // Try to find npm in the same directory as the node executable.\n const nodeDir = path?.dirname(process.execPath)\n const npmInNodeDir = path?.join(nodeDir, 'npm')\n\n if (fs?.existsSync(npmInNodeDir)) {\n return npmInNodeDir\n }\n\n // Try common npm locations.\n const commonPaths = ['/usr/local/bin/npm', '/usr/bin/npm']\n const result = findRealBin('npm', commonPaths)\n\n // If we found a valid path, return it.\n if (result && fs?.existsSync(result)) {\n return result\n }\n\n // As a last resort, try to use whichBinSync to find npm.\n // This handles cases where npm is installed in non-standard locations.\n const npmPath = whichBinSync('npm', { nothrow: true })\n if (npmPath && typeof npmPath === 'string' && fs?.existsSync(npmPath)) {\n return npmPath\n }\n\n // Return the basic 'npm' and let the system resolve it.\n return 'npm'\n}\n\n/**\n * Find the real pnpm executable, bypassing any aliases and shadow bins.\n */\nexport function findRealPnpm(): string {\n const path = getPath()\n\n // Try common pnpm locations.\n const commonPaths = WIN32\n ? [\n // Windows common paths.\n path?.join(getAppdata() as string, 'npm', 'pnpm.cmd'),\n path?.join(getAppdata() as string, 'npm', 'pnpm'),\n path?.join(getLocalappdata() as string, 'pnpm', 'pnpm.cmd'),\n path?.join(getLocalappdata() as string, 'pnpm', 'pnpm'),\n 'C:\\\\Program Files\\\\nodejs\\\\pnpm.cmd',\n 'C:\\\\Program Files\\\\nodejs\\\\pnpm',\n ].filter(Boolean)\n : [\n // Unix common paths.\n '/usr/local/bin/pnpm',\n '/usr/bin/pnpm',\n path?.join(\n (getXdgDataHome() as string) || `${getHome() as string}/.local/share`,\n 'pnpm/pnpm',\n ),\n path?.join(getHome() as string, '.pnpm/pnpm'),\n ].filter(Boolean)\n\n return findRealBin('pnpm', commonPaths) ?? ''\n}\n\n/**\n * Find the real yarn executable, bypassing any aliases and shadow bins.\n */\nexport function findRealYarn(): string {\n const path = getPath()\n\n // Try common yarn locations.\n const commonPaths = [\n '/usr/local/bin/yarn',\n '/usr/bin/yarn',\n path?.join(getHome() as string, '.yarn/bin/yarn'),\n path?.join(\n getHome() as string,\n '.config/yarn/global/node_modules/.bin/yarn',\n ),\n ].filter(Boolean)\n\n return findRealBin('yarn', commonPaths) ?? ''\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n/**\n * Resolve a binary path to its actual executable file.\n * Handles Windows .cmd wrappers and Unix shell scripts.\n */\nexport function resolveBinPathSync(binPath: string): string {\n const fs = getFs()\n const path = getPath()\n\n // If it's not an absolute path, try to find it in PATH first\n if (!path?.isAbsolute(binPath)) {\n try {\n const resolved = whichBinSync(binPath)\n if (resolved) {\n binPath = resolved as string\n }\n } catch {}\n }\n\n // Normalize the path once for consistent pattern matching.\n binPath = normalizePath(binPath)\n\n // Handle empty string that normalized to '.' (current directory)\n if (binPath === '.') {\n return binPath\n }\n\n const ext = path?.extname(binPath)\n const extLowered = ext.toLowerCase()\n const basename = path?.basename(binPath, ext)\n const voltaIndex =\n basename === 'node' ? -1 : (/(?<=\\/)\\.volta\\//i.exec(binPath)?.index ?? -1)\n if (voltaIndex !== -1) {\n const voltaPath = binPath.slice(0, voltaIndex)\n const voltaToolsPath = path?.join(voltaPath, 'tools')\n const voltaImagePath = path?.join(voltaToolsPath, 'image')\n const voltaUserPath = path?.join(voltaToolsPath, 'user')\n const voltaPlatform = readJsonSync(\n path?.join(voltaUserPath, 'platform.json'),\n { throws: false },\n ) as any\n const voltaNodeVersion = voltaPlatform?.node?.runtime\n const voltaNpmVersion = voltaPlatform?.node?.npm\n let voltaBinPath = ''\n if (basename === 'npm' || basename === 'npx') {\n if (voltaNpmVersion) {\n const relCliPath = `bin/${basename}-cli.js`\n voltaBinPath = path?.join(\n voltaImagePath,\n `npm/${voltaNpmVersion}/${relCliPath}`,\n )\n if (voltaNodeVersion && !fs?.existsSync(voltaBinPath)) {\n voltaBinPath = path?.join(\n voltaImagePath,\n `node/${voltaNodeVersion}/lib/node_modules/npm/${relCliPath}`,\n )\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = ''\n }\n }\n }\n } else {\n const voltaUserBinPath = path?.join(voltaUserPath, 'bin')\n const binInfo = readJsonSync(\n path?.join(voltaUserBinPath, `${basename}.json`),\n { throws: false },\n ) as any\n const binPackage = binInfo?.package\n if (binPackage) {\n voltaBinPath = path?.join(\n voltaImagePath,\n `packages/${binPackage}/bin/${basename}`,\n )\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = `${voltaBinPath}.cmd`\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = ''\n }\n }\n }\n }\n if (voltaBinPath) {\n try {\n return normalizePath(fs?.realpathSync.native(voltaBinPath))\n } catch {}\n return voltaBinPath\n }\n }\n if (WIN32) {\n const hasKnownExt =\n extLowered === '' ||\n extLowered === '.cmd' ||\n extLowered === '.exe' ||\n extLowered === '.ps1'\n const isNpmOrNpx = basename === 'npm' || basename === 'npx'\n const isPnpmOrYarn = basename === 'pnpm' || basename === 'yarn'\n if (hasKnownExt && isNpmOrNpx) {\n // The quick route assumes a bin path like: C:\\Program Files\\nodejs\\npm.cmd\n const quickPath = path?.join(\n path?.dirname(binPath),\n `node_modules/npm/bin/${basename}-cli.js`,\n )\n if (fs?.existsSync(quickPath)) {\n try {\n return fs?.realpathSync.native(quickPath)\n } catch {}\n return quickPath\n }\n }\n let relPath = ''\n if (\n hasKnownExt &&\n // Only parse shell scripts and batch files, not actual executables.\n // .exe files are already executables and don't need path resolution from wrapper scripts.\n extLowered !== '.exe' &&\n // Check if file exists before attempting to read it to avoid ENOENT errors.\n fs?.existsSync(binPath)\n ) {\n const source = fs?.readFileSync(binPath, 'utf8')\n if (isNpmOrNpx) {\n if (extLowered === '.cmd') {\n // \"npm.cmd\" and \"npx.cmd\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm.cmd\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx.cmd\n relPath =\n basename === 'npm'\n ? /(?<=\"NPM_CLI_JS=%~dp0\\\\).*(?=\")/.exec(source)?.[0] || ''\n : /(?<=\"NPX_CLI_JS=%~dp0\\\\).*(?=\")/.exec(source)?.[0] || ''\n } else if (extLowered === '') {\n // Extensionless \"npm\" and \"npx\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx\n relPath =\n basename === 'npm'\n ? /(?<=NPM_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] ||\n ''\n : /(?<=NPX_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] ||\n ''\n } else if (extLowered === '.ps1') {\n // \"npm.ps1\" and \"npx.ps1\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm.ps1\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx.ps1\n relPath =\n basename === 'npm'\n ? /(?<=\\$NPM_CLI_JS=\"\\$PSScriptRoot\\/).*(?=\")/.exec(\n source,\n )?.[0] || ''\n : /(?<=\\$NPX_CLI_JS=\"\\$PSScriptRoot\\/).*(?=\")/.exec(\n source,\n )?.[0] || ''\n }\n } else if (isPnpmOrYarn) {\n if (extLowered === '.cmd') {\n // pnpm.cmd and yarn.cmd can have different formats depending on installation method\n // Common formats include:\n // 1. Setup-pnpm action format: node \"%~dp0\\..\\pnpm\\bin\\pnpm.cjs\" %*\n // 2. npm install -g pnpm format: similar to cmd-shim\n // 3. Standalone installer format: various patterns\n\n // Try setup-pnpm/setup-yarn action format first\n relPath =\n /(?<=node\\s+\")%~dp0\\\\([^\"]+)(?=\"\\s+%\\*)/.exec(source)?.[1] || ''\n\n // Try alternative format: \"%~dp0\\node.exe\" \"%~dp0\\..\\package\\bin\\binary.js\" %*\n if (!relPath) {\n relPath =\n /(?<=\"%~dp0\\\\[^\"]*node[^\"]*\"\\s+\")%~dp0\\\\([^\"]+)(?=\"\\s+%\\*)/.exec(\n source,\n )?.[1] || ''\n }\n\n // Try cmd-shim format as fallback\n if (!relPath) {\n relPath = /(?<=\"%dp0%\\\\).*(?=\" %\\*\\r\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '') {\n // Extensionless pnpm/yarn - try common shebang formats\n // Handle pnpm installed via standalone installer or global install\n // Format: exec \"$basedir/node\" \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n // Note: may have multiple spaces between arguments\n relPath =\n /(?<=\"\\$basedir\\/)\\.tools\\/pnpm\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(\n source,\n )?.[0] || ''\n if (!relPath) {\n // Also try: exec node \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n relPath =\n /(?<=exec\\s+node\\s+\"\\$basedir\\/)\\.tools\\/pnpm\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(\n source,\n )?.[0] || ''\n }\n if (!relPath) {\n // Try standard cmd-shim format: exec node \"$basedir/../package/bin/binary.js\" \"$@\"\n relPath = /(?<=\"\\$basedir\\/).*(?=\" \"\\$@\"\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '.ps1') {\n // PowerShell format\n relPath = /(?<=\"\\$basedir\\/).*(?=\" $args\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '.cmd') {\n // \"bin.CMD\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L98:\n //\n // @ECHO off\n // GOTO start\n // :find_dp0\n // SET dp0=%~dp0\n // EXIT /b\n // :start\n // SETLOCAL\n // CALL :find_dp0\n //\n // IF EXIST \"%dp0%\\node.exe\" (\n // SET \"_prog=%dp0%\\node.exe\"\n // ) ELSE (\n // SET \"_prog=node\"\n // SET PATHEXT=%PATHEXT:;.JS;=;%\n // )\n //\n // endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & \"%_prog%\" \"%dp0%\\..\\<PACKAGE_NAME>\\path\\to\\bin.js\" %*\n relPath = /(?<=\"%dp0%\\\\).*(?=\" %\\*\\r\\n)/.exec(source)?.[0] || ''\n } else if (extLowered === '') {\n // Extensionless \"bin\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L138:\n //\n // #!/bin/sh\n // basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n //\n // case `uname` in\n // *CYGWIN*|*MINGW*|*MSYS*)\n // if command -v cygpath > /dev/null 2>&1; then\n // basedir=`cygpath -w \"$basedir\"`\n // fi\n // ;;\n // esac\n //\n // if [ -x \"$basedir/node\" ]; then\n // exec \"$basedir/node\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" \"$@\"\n // else\n // exec node \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" \"$@\"\n // fi\n relPath = /(?<=\"$basedir\\/).*(?=\" \"\\$@\"\\n)/.exec(source)?.[0] || ''\n } else if (extLowered === '.ps1') {\n // \"bin.PS1\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L192:\n //\n // #!/usr/bin/env pwsh\n // $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n //\n // $exe=\"\"\n // if ($PSVersionTable.PSVersion -lt \"6.0\" -or $IsWindows) {\n // # Fix case when both the Windows and Linux builds of Node\n // # are installed in the same directory\n // $exe=\".exe\"\n // }\n // $ret=0\n // if (Test-Path \"$basedir/node$exe\") {\n // # Support pipeline input\n // if ($MyInvocation.ExpectingInput) {\n // $input | & \"$basedir/node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // } else {\n // & \"$basedir/node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // }\n // $ret=$LASTEXITCODE\n // } else {\n // # Support pipeline input\n // if ($MyInvocation.ExpectingInput) {\n // $input | & \"node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // } else {\n // & \"node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // }\n // $ret=$LASTEXITCODE\n // }\n // exit $ret\n relPath = /(?<=\"\\$basedir\\/).*(?=\" $args\\n)/.exec(source)?.[0] || ''\n }\n if (relPath) {\n binPath = normalizePath(path?.resolve(path?.dirname(binPath), relPath))\n }\n }\n } else {\n // Handle Unix shell scripts (non-Windows platforms)\n let hasNoExt = extLowered === ''\n const isPnpmOrYarn = basename === 'pnpm' || basename === 'yarn'\n const isNpmOrNpx = basename === 'npm' || basename === 'npx'\n\n // Handle special case where pnpm path in CI has extra segments.\n // In setup-pnpm GitHub Action, the path might be malformed like:\n // /home/user/setup-pnpm/node_modules/.bin/pnpm/bin/pnpm.cjs\n // This happens when the shell script contains a relative path that\n // when resolved, creates an invalid nested structure.\n if (isPnpmOrYarn && binPath.includes('/.bin/pnpm/bin/')) {\n // Extract the correct pnpm bin path.\n const binIndex = binPath.indexOf('/.bin/pnpm')\n if (binIndex !== -1) {\n // Get the base path up to /.bin/pnpm.\n const baseBinPath = binPath.slice(0, binIndex + '/.bin/pnpm'.length)\n // Check if the original shell script exists.\n try {\n const stats = fs?.statSync(baseBinPath)\n // Only use this path if it's a file (the shell script).\n if (stats.isFile()) {\n binPath = normalizePath(baseBinPath)\n // Recompute hasNoExt since we changed the path.\n hasNoExt = !path?.extname(binPath)\n }\n } catch {\n // If stat fails, continue with the original path.\n }\n }\n }\n\n if (\n hasNoExt &&\n (isPnpmOrYarn || isNpmOrNpx) &&\n // For extensionless files (Unix shell scripts), verify existence before reading.\n // This prevents ENOENT errors when the bin path doesn't exist.\n fs?.existsSync(binPath)\n ) {\n const source = fs?.readFileSync(binPath, 'utf8')\n let relPath = ''\n\n if (isPnpmOrYarn) {\n // Handle pnpm/yarn Unix shell scripts.\n // Format: exec \"$basedir/node\" \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n // or: exec node \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n relPath =\n /(?<=\"\\$basedir\\/)\\.tools\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(source)?.[0] || ''\n if (!relPath) {\n // Try standard cmd-shim format: exec node \"$basedir/../package/bin/binary.js\" \"$@\"\n // Example: exec node \"$basedir/../pnpm/bin/pnpm.cjs\" \"$@\"\n // ^^^^^^^^^^^^^^^^^^^^^ captures this part\n // This regex needs to be more careful to not match \"$@\" at the end.\n relPath =\n /(?<=\"\\$basedir\\/)[^\"]+(?=\"\\s+\"\\$@\")/.exec(source)?.[0] || ''\n }\n // Special case for setup-pnpm GitHub Action which may use a different format.\n // The setup-pnpm action creates a shell script that references ../pnpm/bin/pnpm.cjs\n if (!relPath) {\n // Try to match: exec node \"$basedir/../pnpm/bin/pnpm.cjs\" \"$@\"\n const match = /exec\\s+node\\s+\"?\\$basedir\\/([^\"]+)\"?\\s+\"\\$@\"/.exec(\n source,\n )\n if (match) {\n relPath = match[1] || ''\n }\n }\n // Check if the extracted path looks wrong (e.g., pnpm/bin/pnpm.cjs without ../).\n // This happens with setup-pnpm action when it creates a malformed shell script.\n if (relPath && basename === 'pnpm' && relPath.startsWith('pnpm/')) {\n // The path should be ../pnpm/... not pnpm/...\n // Prepend ../ to fix the relative path.\n relPath = `../${relPath}`\n }\n } else if (isNpmOrNpx) {\n // Handle npm/npx Unix shell scripts\n relPath =\n basename === 'npm'\n ? /(?<=NPM_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] || ''\n : /(?<=NPX_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] || ''\n }\n\n if (relPath) {\n // Resolve the relative path to handle .. segments properly.\n binPath = normalizePath(path?.resolve(path?.dirname(binPath), relPath))\n }\n }\n }\n try {\n const realPath = fs?.realpathSync.native(binPath)\n return normalizePath(realPath)\n } catch {}\n // Return normalized path even if realpath fails.\n return normalizePath(binPath)\n}\n"],
|
|
5
|
-
"mappings": ";4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,gBAAAC,EAAA,gBAAAC,EAAA,iBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,EAAA,uBAAAC,EAAA,aAAAC,EAAA,iBAAAC,IAAA,eAAAC,
|
|
6
|
-
"names": ["bin_exports", "__export", "execBin", "findRealBin", "findRealNpm", "findRealPnpm", "findRealYarn", "isShadowBinPath", "resolveBinPathSync", "whichBin", "whichBinSync", "__toCommonJS", "import_home", "import_windows", "import_xdg", "import_platform", "import_fs", "
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Binary path resolution and execution utilities for package managers.\n * Provides cross-platform bin path lookup, command execution, and path normalization.\n */\n\nimport { getHome } from '#env/home'\nimport { getAppdata, getLocalappdata } from '#env/windows'\nimport { getXdgDataHome } from '#env/xdg'\n\nimport { WIN32 } from '#constants/platform'\nimport { readJsonSync } from './fs'\nimport { isPath, normalizePath } from './path'\nimport { spawn } from './spawn'\n\nlet _fs: typeof import('node:fs') | undefined\n/**\n * Lazily load the fs module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getFs() {\n if (_fs === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _fs = /*@__PURE__*/ require('node:fs')\n }\n return _fs!\n}\n\nlet _path: typeof import('node:path') | undefined\n/**\n * Lazily load the path module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPath() {\n if (_path === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _path = /*@__PURE__*/ require('node:path')\n }\n return _path!\n}\n\nlet _which: typeof import('which') | undefined\n/**\n * Lazily load the which module for finding executables.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getWhich() {\n if (_which === undefined) {\n _which = /*@__PURE__*/ require('./external/which')\n }\n return _which!\n}\n\n/**\n * Execute a binary with the given arguments.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport async function execBin(\n binPath: string,\n args?: string[],\n options?: import('./spawn').SpawnOptions,\n) {\n // Resolve the binary path.\n const resolvedPath = isPath(binPath)\n ? resolveBinPathSync(binPath)\n : await whichBin(binPath)\n\n if (!resolvedPath) {\n const error = new Error(`Binary not found: ${binPath}`) as Error & {\n code: string\n }\n error.code = 'ENOENT'\n throw error\n }\n\n // Execute the binary directly.\n const binCommand = Array.isArray(resolvedPath)\n ? resolvedPath[0]!\n : resolvedPath\n // On Windows, binaries are often .cmd files that require shell to execute.\n return await spawn(binCommand, args ?? [], {\n shell: WIN32,\n ...options,\n })\n}\n\n/**\n * Options for the which function.\n */\nexport interface WhichOptions {\n /** If true, return all matches instead of just the first one. */\n all?: boolean | undefined\n /** If true, return null instead of throwing when no match is found. */\n nothrow?: boolean | undefined\n /** Path to search in. */\n path?: string | undefined\n /** Path separator character. */\n pathExt?: string | undefined\n /** Environment variables to use. */\n env?: Record<string, string | undefined> | undefined\n}\n\n/**\n * Find an executable in the system PATH asynchronously.\n * Wrapper around the which package for lazy loading.\n */\nexport async function which(\n binName: string,\n options?: WhichOptions,\n): Promise<string | string[] | undefined> {\n return await getWhich()(binName, options)\n}\n\n/**\n * Find an executable in the system PATH synchronously.\n * Wrapper around the which package for lazy loading.\n */\nexport function whichSync(\n binName: string,\n options?: WhichOptions,\n): string | string[] | undefined {\n return getWhich().sync(binName, options)\n}\n\n/**\n * Find and resolve a binary in the system PATH asynchronously.\n * @throws {Error} If the binary is not found and nothrow is false.\n */\nexport async function whichBin(\n binName: string,\n options?: WhichOptions,\n): Promise<string | string[] | undefined> {\n const which = getWhich()\n // Default to nothrow: true if not specified to return undefined instead of throwing\n const opts = { nothrow: true, ...options }\n // Depending on options `which` may throw if `binName` is not found.\n // With nothrow: true, it returns null when `binName` is not found.\n const result = await which(binName, opts)\n\n // When 'all: true' is specified, ensure we always return an array.\n if (opts?.all) {\n const paths = Array.isArray(result)\n ? result\n : typeof result === 'string'\n ? [result]\n : undefined\n // If all is true and we have paths, resolve each one.\n return paths?.length ? paths.map(p => resolveBinPathSync(p)) : paths\n }\n\n // If result is undefined (binary not found), return undefined\n if (!result) {\n return undefined\n }\n\n return resolveBinPathSync(result)\n}\n\n/**\n * Find and resolve a binary in the system PATH synchronously.\n * @throws {Error} If the binary is not found and nothrow is false.\n */\nexport function whichBinSync(\n binName: string,\n options?: WhichOptions,\n): string | string[] | undefined {\n // Default to nothrow: true if not specified to return undefined instead of throwing\n const opts = { nothrow: true, ...options }\n // Depending on options `which` may throw if `binName` is not found.\n // With nothrow: true, it returns null when `binName` is not found.\n const result = whichSync(binName, opts)\n\n // When 'all: true' is specified, ensure we always return an array.\n if (opts.all) {\n const paths = Array.isArray(result)\n ? result\n : typeof result === 'string'\n ? [result]\n : undefined\n // If all is true and we have paths, resolve each one.\n return paths?.length ? paths.map(p => resolveBinPathSync(p)) : paths\n }\n\n // If result is undefined (binary not found), return undefined\n if (!result) {\n return undefined\n }\n\n return resolveBinPathSync(result as string)\n}\n\n/**\n * Check if a directory path contains any shadow bin patterns.\n */\nexport function isShadowBinPath(dirPath: string | undefined): boolean {\n if (!dirPath) {\n return false\n }\n // Check for node_modules/.bin pattern (Unix and Windows)\n const normalized = dirPath.replace(/\\\\/g, '/')\n return normalized.includes('node_modules/.bin')\n}\n\n/**\n * Find the real executable for a binary, bypassing shadow bins.\n */\nexport function findRealBin(\n binName: string,\n commonPaths: string[] = [],\n): string | undefined {\n const fs = getFs()\n const path = getPath()\n const which = getWhich()\n\n // Try common locations first.\n for (const binPath of commonPaths) {\n if (fs?.existsSync(binPath)) {\n return binPath\n }\n }\n\n // Fall back to which.sync if no direct path found.\n const binPath = which?.sync(binName, { nothrow: true })\n if (binPath) {\n const binDir = path?.dirname(binPath)\n\n if (isShadowBinPath(binDir)) {\n // This is likely a shadowed binary, try to find the real one.\n const allPaths = which?.sync(binName, { all: true, nothrow: true }) || []\n // Ensure allPaths is an array.\n const pathsArray = Array.isArray(allPaths)\n ? allPaths\n : typeof allPaths === 'string'\n ? [allPaths]\n : []\n\n for (const altPath of pathsArray) {\n const altDir = path?.dirname(altPath)\n if (!isShadowBinPath(altDir)) {\n return altPath\n }\n }\n }\n return binPath\n }\n // If all else fails, return undefined to indicate binary not found.\n return undefined\n}\n\n/**\n * Find the real npm executable, bypassing any aliases and shadow bins.\n */\nexport function findRealNpm(): string {\n const fs = getFs()\n const path = getPath()\n\n // Try to find npm in the same directory as the node executable.\n const nodeDir = path?.dirname(process.execPath)\n const npmInNodeDir = path?.join(nodeDir, 'npm')\n\n if (fs?.existsSync(npmInNodeDir)) {\n return npmInNodeDir\n }\n\n // Try common npm locations.\n const commonPaths = ['/usr/local/bin/npm', '/usr/bin/npm']\n const result = findRealBin('npm', commonPaths)\n\n // If we found a valid path, return it.\n if (result && fs?.existsSync(result)) {\n return result\n }\n\n // As a last resort, try to use whichBinSync to find npm.\n // This handles cases where npm is installed in non-standard locations.\n const npmPath = whichBinSync('npm', { nothrow: true })\n if (npmPath && typeof npmPath === 'string' && fs?.existsSync(npmPath)) {\n return npmPath\n }\n\n // Return the basic 'npm' and let the system resolve it.\n return 'npm'\n}\n\n/**\n * Find the real pnpm executable, bypassing any aliases and shadow bins.\n */\nexport function findRealPnpm(): string {\n const path = getPath()\n\n // Try common pnpm locations.\n const commonPaths = WIN32\n ? [\n // Windows common paths.\n path?.join(getAppdata() as string, 'npm', 'pnpm.cmd'),\n path?.join(getAppdata() as string, 'npm', 'pnpm'),\n path?.join(getLocalappdata() as string, 'pnpm', 'pnpm.cmd'),\n path?.join(getLocalappdata() as string, 'pnpm', 'pnpm'),\n 'C:\\\\Program Files\\\\nodejs\\\\pnpm.cmd',\n 'C:\\\\Program Files\\\\nodejs\\\\pnpm',\n ].filter(Boolean)\n : [\n // Unix common paths.\n '/usr/local/bin/pnpm',\n '/usr/bin/pnpm',\n path?.join(\n (getXdgDataHome() as string) || `${getHome() as string}/.local/share`,\n 'pnpm/pnpm',\n ),\n path?.join(getHome() as string, '.pnpm/pnpm'),\n ].filter(Boolean)\n\n return findRealBin('pnpm', commonPaths) ?? ''\n}\n\n/**\n * Find the real yarn executable, bypassing any aliases and shadow bins.\n */\nexport function findRealYarn(): string {\n const path = getPath()\n\n // Try common yarn locations.\n const commonPaths = [\n '/usr/local/bin/yarn',\n '/usr/bin/yarn',\n path?.join(getHome() as string, '.yarn/bin/yarn'),\n path?.join(\n getHome() as string,\n '.config/yarn/global/node_modules/.bin/yarn',\n ),\n ].filter(Boolean)\n\n return findRealBin('yarn', commonPaths) ?? ''\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n/**\n * Resolve a binary path to its actual executable file.\n * Handles Windows .cmd wrappers and Unix shell scripts.\n */\nexport function resolveBinPathSync(binPath: string): string {\n const fs = getFs()\n const path = getPath()\n\n // If it's not an absolute path, try to find it in PATH first\n if (!path?.isAbsolute(binPath)) {\n try {\n const resolved = whichBinSync(binPath)\n if (resolved) {\n binPath = resolved as string\n }\n } catch {}\n }\n\n // Normalize the path once for consistent pattern matching.\n binPath = normalizePath(binPath)\n\n // Handle empty string that normalized to '.' (current directory)\n if (binPath === '.') {\n return binPath\n }\n\n const ext = path?.extname(binPath)\n const extLowered = ext.toLowerCase()\n const basename = path?.basename(binPath, ext)\n const voltaIndex =\n basename === 'node' ? -1 : (/(?<=\\/)\\.volta\\//i.exec(binPath)?.index ?? -1)\n if (voltaIndex !== -1) {\n const voltaPath = binPath.slice(0, voltaIndex)\n const voltaToolsPath = path?.join(voltaPath, 'tools')\n const voltaImagePath = path?.join(voltaToolsPath, 'image')\n const voltaUserPath = path?.join(voltaToolsPath, 'user')\n const voltaPlatform = readJsonSync(\n path?.join(voltaUserPath, 'platform.json'),\n { throws: false },\n ) as any\n const voltaNodeVersion = voltaPlatform?.node?.runtime\n const voltaNpmVersion = voltaPlatform?.node?.npm\n let voltaBinPath = ''\n if (basename === 'npm' || basename === 'npx') {\n if (voltaNpmVersion) {\n const relCliPath = `bin/${basename}-cli.js`\n voltaBinPath = path?.join(\n voltaImagePath,\n `npm/${voltaNpmVersion}/${relCliPath}`,\n )\n if (voltaNodeVersion && !fs?.existsSync(voltaBinPath)) {\n voltaBinPath = path?.join(\n voltaImagePath,\n `node/${voltaNodeVersion}/lib/node_modules/npm/${relCliPath}`,\n )\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = ''\n }\n }\n }\n } else {\n const voltaUserBinPath = path?.join(voltaUserPath, 'bin')\n const binInfo = readJsonSync(\n path?.join(voltaUserBinPath, `${basename}.json`),\n { throws: false },\n ) as any\n const binPackage = binInfo?.package\n if (binPackage) {\n voltaBinPath = path?.join(\n voltaImagePath,\n `packages/${binPackage}/bin/${basename}`,\n )\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = `${voltaBinPath}.cmd`\n if (!fs?.existsSync(voltaBinPath)) {\n voltaBinPath = ''\n }\n }\n }\n }\n if (voltaBinPath) {\n try {\n return normalizePath(fs?.realpathSync.native(voltaBinPath))\n } catch {}\n return voltaBinPath\n }\n }\n if (WIN32) {\n const hasKnownExt =\n extLowered === '' ||\n extLowered === '.cmd' ||\n extLowered === '.exe' ||\n extLowered === '.ps1'\n const isNpmOrNpx = basename === 'npm' || basename === 'npx'\n const isPnpmOrYarn = basename === 'pnpm' || basename === 'yarn'\n if (hasKnownExt && isNpmOrNpx) {\n // The quick route assumes a bin path like: C:\\Program Files\\nodejs\\npm.cmd\n const quickPath = path?.join(\n path?.dirname(binPath),\n `node_modules/npm/bin/${basename}-cli.js`,\n )\n if (fs?.existsSync(quickPath)) {\n try {\n return fs?.realpathSync.native(quickPath)\n } catch {}\n return quickPath\n }\n }\n let relPath = ''\n if (\n hasKnownExt &&\n // Only parse shell scripts and batch files, not actual executables.\n // .exe files are already executables and don't need path resolution from wrapper scripts.\n extLowered !== '.exe' &&\n // Check if file exists before attempting to read it to avoid ENOENT errors.\n fs?.existsSync(binPath)\n ) {\n const source = fs?.readFileSync(binPath, 'utf8')\n if (isNpmOrNpx) {\n if (extLowered === '.cmd') {\n // \"npm.cmd\" and \"npx.cmd\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm.cmd\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx.cmd\n relPath =\n basename === 'npm'\n ? /(?<=\"NPM_CLI_JS=%~dp0\\\\).*(?=\")/.exec(source)?.[0] || ''\n : /(?<=\"NPX_CLI_JS=%~dp0\\\\).*(?=\")/.exec(source)?.[0] || ''\n } else if (extLowered === '') {\n // Extensionless \"npm\" and \"npx\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx\n relPath =\n basename === 'npm'\n ? /(?<=NPM_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] ||\n ''\n : /(?<=NPX_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] ||\n ''\n } else if (extLowered === '.ps1') {\n // \"npm.ps1\" and \"npx.ps1\" defined by\n // https://github.com/npm/cli/blob/v11.4.2/bin/npm.ps1\n // https://github.com/npm/cli/blob/v11.4.2/bin/npx.ps1\n relPath =\n basename === 'npm'\n ? /(?<=\\$NPM_CLI_JS=\"\\$PSScriptRoot\\/).*(?=\")/.exec(\n source,\n )?.[0] || ''\n : /(?<=\\$NPX_CLI_JS=\"\\$PSScriptRoot\\/).*(?=\")/.exec(\n source,\n )?.[0] || ''\n }\n } else if (isPnpmOrYarn) {\n if (extLowered === '.cmd') {\n // pnpm.cmd and yarn.cmd can have different formats depending on installation method\n // Common formats include:\n // 1. Setup-pnpm action format: node \"%~dp0\\..\\pnpm\\bin\\pnpm.cjs\" %*\n // 2. npm install -g pnpm format: similar to cmd-shim\n // 3. Standalone installer format: various patterns\n\n // Try setup-pnpm/setup-yarn action format first\n relPath =\n /(?<=node\\s+\")%~dp0\\\\([^\"]+)(?=\"\\s+%\\*)/.exec(source)?.[1] || ''\n\n // Try alternative format: \"%~dp0\\node.exe\" \"%~dp0\\..\\package\\bin\\binary.js\" %*\n if (!relPath) {\n relPath =\n /(?<=\"%~dp0\\\\[^\"]*node[^\"]*\"\\s+\")%~dp0\\\\([^\"]+)(?=\"\\s+%\\*)/.exec(\n source,\n )?.[1] || ''\n }\n\n // Try cmd-shim format as fallback\n if (!relPath) {\n relPath = /(?<=\"%dp0%\\\\).*(?=\" %\\*\\r\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '') {\n // Extensionless pnpm/yarn - try common shebang formats\n // Handle pnpm installed via standalone installer or global install\n // Format: exec \"$basedir/node\" \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n // Note: may have multiple spaces between arguments\n relPath =\n /(?<=\"\\$basedir\\/)\\.tools\\/pnpm\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(\n source,\n )?.[0] || ''\n if (!relPath) {\n // Also try: exec node \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n relPath =\n /(?<=exec\\s+node\\s+\"\\$basedir\\/)\\.tools\\/pnpm\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(\n source,\n )?.[0] || ''\n }\n if (!relPath) {\n // Try standard cmd-shim format: exec node \"$basedir/../package/bin/binary.js\" \"$@\"\n relPath = /(?<=\"\\$basedir\\/).*(?=\" \"\\$@\"\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '.ps1') {\n // PowerShell format\n relPath = /(?<=\"\\$basedir\\/).*(?=\" $args\\n)/.exec(source)?.[0] || ''\n }\n } else if (extLowered === '.cmd') {\n // \"bin.CMD\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L98:\n //\n // @ECHO off\n // GOTO start\n // :find_dp0\n // SET dp0=%~dp0\n // EXIT /b\n // :start\n // SETLOCAL\n // CALL :find_dp0\n //\n // IF EXIST \"%dp0%\\node.exe\" (\n // SET \"_prog=%dp0%\\node.exe\"\n // ) ELSE (\n // SET \"_prog=node\"\n // SET PATHEXT=%PATHEXT:;.JS;=;%\n // )\n //\n // endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & \"%_prog%\" \"%dp0%\\..\\<PACKAGE_NAME>\\path\\to\\bin.js\" %*\n relPath = /(?<=\"%dp0%\\\\).*(?=\" %\\*\\r\\n)/.exec(source)?.[0] || ''\n } else if (extLowered === '') {\n // Extensionless \"bin\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L138:\n //\n // #!/bin/sh\n // basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n //\n // case `uname` in\n // *CYGWIN*|*MINGW*|*MSYS*)\n // if command -v cygpath > /dev/null 2>&1; then\n // basedir=`cygpath -w \"$basedir\"`\n // fi\n // ;;\n // esac\n //\n // if [ -x \"$basedir/node\" ]; then\n // exec \"$basedir/node\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" \"$@\"\n // else\n // exec node \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" \"$@\"\n // fi\n relPath = /(?<=\"$basedir\\/).*(?=\" \"\\$@\"\\n)/.exec(source)?.[0] || ''\n } else if (extLowered === '.ps1') {\n // \"bin.PS1\" generated by\n // https://github.com/npm/cmd-shim/blob/v7.0.0/lib/index.js#L192:\n //\n // #!/usr/bin/env pwsh\n // $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n //\n // $exe=\"\"\n // if ($PSVersionTable.PSVersion -lt \"6.0\" -or $IsWindows) {\n // # Fix case when both the Windows and Linux builds of Node\n // # are installed in the same directory\n // $exe=\".exe\"\n // }\n // $ret=0\n // if (Test-Path \"$basedir/node$exe\") {\n // # Support pipeline input\n // if ($MyInvocation.ExpectingInput) {\n // $input | & \"$basedir/node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // } else {\n // & \"$basedir/node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // }\n // $ret=$LASTEXITCODE\n // } else {\n // # Support pipeline input\n // if ($MyInvocation.ExpectingInput) {\n // $input | & \"node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // } else {\n // & \"node$exe\" \"$basedir/../<PACKAGE_NAME>/path/to/bin.js\" $args\n // }\n // $ret=$LASTEXITCODE\n // }\n // exit $ret\n relPath = /(?<=\"\\$basedir\\/).*(?=\" $args\\n)/.exec(source)?.[0] || ''\n }\n if (relPath) {\n binPath = normalizePath(path?.resolve(path?.dirname(binPath), relPath))\n }\n }\n } else {\n // Handle Unix shell scripts (non-Windows platforms)\n let hasNoExt = extLowered === ''\n const isPnpmOrYarn = basename === 'pnpm' || basename === 'yarn'\n const isNpmOrNpx = basename === 'npm' || basename === 'npx'\n\n // Handle special case where pnpm path in CI has extra segments.\n // In setup-pnpm GitHub Action, the path might be malformed like:\n // /home/user/setup-pnpm/node_modules/.bin/pnpm/bin/pnpm.cjs\n // This happens when the shell script contains a relative path that\n // when resolved, creates an invalid nested structure.\n if (isPnpmOrYarn && binPath.includes('/.bin/pnpm/bin/')) {\n // Extract the correct pnpm bin path.\n const binIndex = binPath.indexOf('/.bin/pnpm')\n if (binIndex !== -1) {\n // Get the base path up to /.bin/pnpm.\n const baseBinPath = binPath.slice(0, binIndex + '/.bin/pnpm'.length)\n // Check if the original shell script exists.\n try {\n const stats = fs?.statSync(baseBinPath)\n // Only use this path if it's a file (the shell script).\n if (stats.isFile()) {\n binPath = normalizePath(baseBinPath)\n // Recompute hasNoExt since we changed the path.\n hasNoExt = !path?.extname(binPath)\n }\n } catch {\n // If stat fails, continue with the original path.\n }\n }\n }\n\n if (\n hasNoExt &&\n (isPnpmOrYarn || isNpmOrNpx) &&\n // For extensionless files (Unix shell scripts), verify existence before reading.\n // This prevents ENOENT errors when the bin path doesn't exist.\n fs?.existsSync(binPath)\n ) {\n const source = fs?.readFileSync(binPath, 'utf8')\n let relPath = ''\n\n if (isPnpmOrYarn) {\n // Handle pnpm/yarn Unix shell scripts.\n // Format: exec \"$basedir/node\" \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n // or: exec node \"$basedir/.tools/pnpm/VERSION/...\" \"$@\"\n relPath =\n /(?<=\"\\$basedir\\/)\\.tools\\/[^\"]+(?=\"\\s+\"\\$@\")/.exec(source)?.[0] || ''\n if (!relPath) {\n // Try standard cmd-shim format: exec node \"$basedir/../package/bin/binary.js\" \"$@\"\n // Example: exec node \"$basedir/../pnpm/bin/pnpm.cjs\" \"$@\"\n // ^^^^^^^^^^^^^^^^^^^^^ captures this part\n // This regex needs to be more careful to not match \"$@\" at the end.\n relPath =\n /(?<=\"\\$basedir\\/)[^\"]+(?=\"\\s+\"\\$@\")/.exec(source)?.[0] || ''\n }\n // Special case for setup-pnpm GitHub Action which may use a different format.\n // The setup-pnpm action creates a shell script that references ../pnpm/bin/pnpm.cjs\n if (!relPath) {\n // Try to match: exec node \"$basedir/../pnpm/bin/pnpm.cjs\" \"$@\"\n const match = /exec\\s+node\\s+\"?\\$basedir\\/([^\"]+)\"?\\s+\"\\$@\"/.exec(\n source,\n )\n if (match) {\n relPath = match[1] || ''\n }\n }\n // Check if the extracted path looks wrong (e.g., pnpm/bin/pnpm.cjs without ../).\n // This happens with setup-pnpm action when it creates a malformed shell script.\n if (relPath && basename === 'pnpm' && relPath.startsWith('pnpm/')) {\n // The path should be ../pnpm/... not pnpm/...\n // Prepend ../ to fix the relative path.\n relPath = `../${relPath}`\n }\n } else if (isNpmOrNpx) {\n // Handle npm/npx Unix shell scripts\n relPath =\n basename === 'npm'\n ? /(?<=NPM_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] || ''\n : /(?<=NPX_CLI_JS=\"\\$CLI_BASEDIR\\/).*(?=\")/.exec(source)?.[0] || ''\n }\n\n if (relPath) {\n // Resolve the relative path to handle .. segments properly.\n binPath = normalizePath(path?.resolve(path?.dirname(binPath), relPath))\n }\n }\n }\n try {\n const realPath = fs?.realpathSync.native(binPath)\n return normalizePath(realPath)\n } catch {}\n // Return normalized path even if realpath fails.\n return normalizePath(binPath)\n}\n"],
|
|
5
|
+
"mappings": ";4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,gBAAAC,EAAA,gBAAAC,EAAA,iBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,EAAA,uBAAAC,EAAA,UAAAC,EAA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,CAAO,EAErC,MAAQ,CAER,CACF,CACF,CAEA,GACE6C,IACCJ,GAAgBD,IAGjB3B,GAAI,WAAWb,CAAO,EACtB,CACA,MAAM4C,EAAS/B,GAAI,aAAab,EAAS,MAAM,EAC/C,IAAI2C,EAAU,GAEd,GAAIF,EAAc,CAgBhB,GAZAE,EACE,+CAA+C,KAAKC,CAAM,IAAI,CAAC,GAAK,GACjED,IAKHA,EACE,sCAAsC,KAAKC,CAAM,IAAI,CAAC,GAAK,IAI3D,CAACD,EAAS,CAEZ,MAAMK,EAAQ,+CAA+C,KAC3DJ,CACF,EACII,IACFL,EAAUK,EAAM,CAAC,GAAK,GAE1B,CAGIL,GAAWjB,IAAa,QAAUiB,EAAQ,WAAW,OAAO,IAG9DA,EAAU,MAAMA,CAAO,GAE3B,MAAWH,IAETG,EACEjB,IAAa,MACT,0CAA0C,KAAKkB,CAAM,IAAI,CAAC,GAAK,GAC/D,0CAA0C,KAAKA,CAAM,IAAI,CAAC,GAAK,IAGnED,IAEF3C,KAAU,iBAAcc,GAAM,QAAQA,GAAM,QAAQd,CAAO,EAAG2C,CAAO,CAAC,EAE1E,CACF,CACA,GAAI,CACF,MAAMM,EAAWpC,GAAI,aAAa,OAAOb,CAAO,EAChD,SAAO,iBAAciD,CAAQ,CAC/B,MAAQ,CAAC,CAET,SAAO,iBAAcjD,CAAO,CAC9B",
|
|
6
|
+
"names": ["bin_exports", "__export", "execBin", "findRealBin", "findRealNpm", "findRealPnpm", "findRealYarn", "isShadowBinPath", "resolveBinPathSync", "which", "whichBin", "whichBinSync", "whichSync", "__toCommonJS", "import_home", "import_windows", "import_xdg", "import_platform", "import_fs", "import_path", "import_spawn", "_fs", "getFs", "_path", "getPath", "_which", "getWhich", "binPath", "args", "options", "resolvedPath", "error", "binCommand", "binName", "opts", "result", "paths", "p", "dirPath", "commonPaths", "fs", "path", "binDir", "allPaths", "pathsArray", "altPath", "altDir", "nodeDir", "npmInNodeDir", "npmPath", "resolved", "ext", "extLowered", "basename", "voltaIndex", "voltaPath", "voltaToolsPath", "voltaImagePath", "voltaUserPath", "voltaPlatform", "voltaNodeVersion", "voltaNpmVersion", "voltaBinPath", "relCliPath", "voltaUserBinPath", "binPackage", "hasKnownExt", "isNpmOrNpx", "isPnpmOrYarn", "quickPath", "relPath", "source", "hasNoExt", "binIndex", "baseBinPath", "match", "realPath"]
|
|
7
7
|
}
|
package/dist/dlx-binary.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var v=Object.create;var b=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var F=(t,n)=>{for(var e in n)b(t,e,{get:n[e],enumerable:!0})},O=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of H(n))!z.call(t,r)&&r!==e&&b(t,r,{get:()=>n[r],enumerable:!(i=E(n,r))||i.enumerable});return t};var T=(t,n,e)=>(e=t!=null?v(L(t)):{},O(n||!t||!t.__esModule?b(e,"default",{value:t,enumerable:!0}):e,t)),W=t=>O(b({},"__esModule",{value:!0}),t);var G={};F(G,{cleanDlxCache:()=>M,dlxBinary:()=>V,getDlxCachePath:()=>D,listDlxCache:()=>X});module.exports=W(G);var j=require("node:crypto"),s=require("node:fs"),x=T(require("node:os")),p=T(require("node:path")),A=require("#constants/platform"),_=require("./download-lock"),c=require("./fs"),C=require("./objects"),S=require("./path"),B=require("./paths"),R=require("./spawn");function Y(t,n){return(0,j.createHash)("sha256").update(`${t}:${n}`).digest("hex")}function g(t){return p.default.join(t,".dlx-metadata.json")}async function q(t,n){try{const e=g(t);if(!(0,s.existsSync)(e))return!1;const i=await(0,c.readJson)(e,{throws:!1});if(!(0,C.isObjectObject)(i))return!1;const r=Date.now(),a=i.timestamp;return typeof a!="number"||a<=0?!1:r-a<n}catch{return!1}}async function J(t,n,e){await(0,_.downloadWithLock)(t,n,{staleTimeout:1e4,lockTimeout:12e4});const i=await s.promises.readFile(n),r=(0,j.createHash)("sha256");r.update(i);const a=r.digest("hex");if(e&&a!==e)throw await(0,c.safeDelete)(n),new Error(`Checksum mismatch: expected ${e}, got ${a}`);return A.WIN32||await s.promises.chmod(n,493),a}async function K(t,n,e){const i=g(t),r={arch:x.default.arch(),checksum:e,platform:x.default.platform(),timestamp:Date.now(),url:n,version:"1.0.0"};await s.promises.writeFile(i,JSON.stringify(r,null,2))}async function M(t=require("#constants/time").DLX_BINARY_CACHE_TTL){const n=D();if(!(0,s.existsSync)(n))return 0;let e=0;const i=Date.now(),r=await s.promises.readdir(n);for(const a of r){const m=p.default.join(n,a),u=g(m);try{if(!await(0,c.isDir)(m))continue;const f=await(0,c.readJson)(u,{throws:!1});if(!f||typeof f!="object"||Array.isArray(f))continue;const l=f.timestamp;(typeof l=="number"&&l>0?i-l:Number.POSITIVE_INFINITY)>t&&(await(0,c.safeDelete)(m,{force:!0,recursive:!0}),e+=1)}catch{try{(await s.promises.readdir(m)).length||(await(0,c.safeDelete)(m),e+=1)}catch{}}}return e}async function V(t,n,e){const{cacheTtl:i=require("#constants/time").DLX_BINARY_CACHE_TTL,checksum:r,force:a=!1,name:m,spawnOptions:u,url:f}={__proto__:null,...n},l=D(),d=m||`binary-${process.platform}-${x.default.arch()}`,P=Y(f,d),o=p.default.join(l,P),y=(0,S.normalizePath)(p.default.join(o,d));let h=!1,k=r;if(!a&&(0,s.existsSync)(o)&&await q(o,i))try{const N=g(o),w=await(0,c.readJson)(N,{throws:!1});w&&typeof w=="object"&&!Array.isArray(w)&&typeof w.checksum=="string"?k=w.checksum:h=!0}catch{h=!0}else h=!0;h&&(await s.promises.mkdir(o,{recursive:!0}),k=await J(f,y,r),await K(o,f,k||""));const $=A.WIN32&&/\.(?:bat|cmd|ps1)$/i.test(y)?{...u,env:{...u?.env,PATH:`${o}${p.default.delimiter}${process.env.PATH||""}`},shell:!0}:u,I=(0,R.spawn)(y,t,$,e);return{binaryPath:y,downloaded:h,spawnPromise:I}}function D(){return(0,B.getSocketDlxDir)()}async function X(){const t=D();if(!(0,s.existsSync)(t))return[];const n=[],e=Date.now(),i=await s.promises.readdir(t);for(const r of i){const a=p.default.join(t,r);try{if(!await(0,c.isDir)(a))continue;const m=g(a),u=await(0,c.readJson)(m,{throws:!1});if(!u||typeof u!="object"||Array.isArray(u))continue;const l=(await s.promises.readdir(a)).find(d=>!d.startsWith("."));if(l){const d=p.default.join(a,l),P=await s.promises.stat(d),o=u;n.push({age:e-(o.timestamp||0),arch:o.arch||"unknown",checksum:o.checksum||"",name:l,platform:o.platform||"unknown",size:P.size,url:o.url||""})}}catch{}}return n}0&&(module.exports={cleanDlxCache,dlxBinary,getDlxCachePath,listDlxCache});
|
|
3
3
|
//# 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'\nimport { existsSync, promises as fs } from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\n\nimport { WIN32 } from '#constants/platform'\n\nimport { isDir, readJson, safeDelete } from './fs'\nimport { httpRequest } from './http-request'\nimport { isObjectObject } from './objects'\nimport { normalizePath } from './path'\nimport { getSocketDlxDir } from './paths'\nimport type { SpawnExtra, SpawnOptions } from './spawn'\nimport { spawn } from './spawn'\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 * Generate a cache directory name from URL and binary name.\n * Uses SHA256 hash to create content-addressed storage.\n * Includes binary name to prevent collisions when multiple binaries\n * are downloaded from the same URL with different names.\n */\nfunction generateCacheKey(url: string, name: string): string {\n return createHash('sha256').update(`${url}:${name}`).digest('hex')\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 try {\n const metaPath = getMetadataPath(cacheEntryPath)\n if (!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.\n */\nasync function downloadBinary(\n url: string,\n destPath: string,\n checksum?: string | undefined,\n): Promise<string> {\n const response = await httpRequest(url)\n if (!response.ok) {\n throw new Error(\n `Failed to download binary: ${response.status} ${response.statusText}`,\n )\n }\n\n // Create a temporary file first.\n const tempPath = `${destPath}.download`\n const hasher = createHash('sha256')\n\n try {\n // Ensure directory exists.\n await fs.mkdir(path.dirname(destPath), { recursive: true })\n\n // Get the response as a buffer and compute hash.\n const buffer = response.body\n\n // Compute hash.\n hasher.update(buffer)\n const actualChecksum = hasher.digest('hex')\n\n // Verify checksum if provided.\n if (checksum && actualChecksum !== checksum) {\n throw new Error(\n `Checksum mismatch: expected ${checksum}, got ${actualChecksum}`,\n )\n }\n\n // Write to temp file.\n await fs.writeFile(tempPath, buffer)\n\n // Make executable on POSIX systems.\n if (!WIN32) {\n await fs.chmod(tempPath, 0o755)\n }\n\n // Move temp file to final location.\n await fs.rename(tempPath, destPath)\n\n return actualChecksum\n } catch (e) {\n // Clean up temp file on error.\n try {\n await safeDelete(tempPath)\n } catch {\n // Ignore cleanup errors.\n }\n throw e\n }\n}\n\n/**\n * Write metadata for a cached binary.\n */\nasync function writeMetadata(\n cacheEntryPath: string,\n url: string,\n checksum: string,\n): Promise<void> {\n const metaPath = getMetadataPath(cacheEntryPath)\n const metadata = {\n arch: os.arch(),\n checksum,\n platform: os.platform(),\n timestamp: Date.now(),\n url,\n version: '1.0.0',\n }\n await fs.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\n if (!existsSync(cacheDir)) {\n return 0\n }\n\n let cleaned = 0\n const now = Date.now()\n const entries = await fs.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.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 const cacheKey = generateCacheKey(url, binaryName)\n const cacheEntryDir = path.join(cacheDir, cacheKey)\n const binaryPath = normalizePath(path.join(cacheEntryDir, binaryName))\n\n let downloaded = false\n let computedChecksum = checksum\n\n // Check if we need to download.\n if (\n !force &&\n 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.\n await fs.mkdir(cacheEntryDir, { recursive: true })\n\n // Download the binary.\n computedChecksum = await downloadBinary(url, binaryPath, checksum)\n await writeMetadata(cacheEntryDir, url, computedChecksum || '')\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 * 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\n if (!existsSync(cacheDir)) {\n return []\n }\n\n const results = []\n const now = Date.now()\n const entries = await fs.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 // Find the binary file in the directory.\n // eslint-disable-next-line no-await-in-loop\n const files = await fs.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.stat(binaryPath)\n\n const metaObj = metadata as Record<string, unknown>\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: (metaObj['url'] as string) || '',\n })\n }\n } catch {}\n }\n\n return results\n}\n"],
|
|
5
|
-
"mappings": ";6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,cAAAC,EAAA,oBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAN,GAEA,IAAAO,EAA2B,uBAC3BC,EAA2C,mBAC3CC,EAAe,sBACfC,EAAiB,wBAEjBC,EAAsB,+BAEtBC,EAA4C,gBAC5CC,
|
|
6
|
-
"names": ["dlx_binary_exports", "__export", "cleanDlxCache", "dlxBinary", "getDlxCachePath", "listDlxCache", "__toCommonJS", "import_node_crypto", "import_node_fs", "import_node_os", "import_node_path", "import_platform", "
|
|
4
|
+
"sourcesContent": ["/** @fileoverview DLX binary execution utilities for Socket ecosystem. */\n\nimport { createHash } from 'node:crypto'\nimport { existsSync, promises as fs } from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\n\nimport { WIN32 } from '#constants/platform'\n\nimport { downloadWithLock } from './download-lock'\nimport { isDir, readJson, safeDelete } from './fs'\nimport { isObjectObject } from './objects'\nimport { normalizePath } from './path'\nimport { getSocketDlxDir } from './paths'\nimport type { SpawnExtra, SpawnOptions } from './spawn'\nimport { spawn } from './spawn'\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 * Generate a cache directory name from URL and binary name.\n * Uses SHA256 hash to create content-addressed storage.\n * Includes binary name to prevent collisions when multiple binaries\n * are downloaded from the same URL with different names.\n */\nfunction generateCacheKey(url: string, name: string): string {\n return createHash('sha256').update(`${url}:${name}`).digest('hex')\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 try {\n const metaPath = getMetadataPath(cacheEntryPath)\n if (!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 downloadWithLock to prevent multiple processes from downloading the same binary simultaneously.\n */\nasync function downloadBinary(\n url: string,\n destPath: string,\n checksum?: string | undefined,\n): Promise<string> {\n // Use downloadWithLock to handle concurrent download protection.\n // This prevents corruption when multiple processes try to download the same binary.\n await downloadWithLock(url, destPath, {\n // Align with npm's npx locking strategy.\n staleTimeout: 10_000,\n // Allow up to 2 minutes for large binary downloads.\n lockTimeout: 120_000,\n })\n\n // Compute checksum of downloaded file.\n const fileBuffer = await fs.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.chmod(destPath, 0o755)\n }\n\n return actualChecksum\n}\n\n/**\n * Write metadata for a cached binary.\n */\nasync function writeMetadata(\n cacheEntryPath: string,\n url: string,\n checksum: string,\n): Promise<void> {\n const metaPath = getMetadataPath(cacheEntryPath)\n const metadata = {\n arch: os.arch(),\n checksum,\n platform: os.platform(),\n timestamp: Date.now(),\n url,\n version: '1.0.0',\n }\n await fs.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\n if (!existsSync(cacheDir)) {\n return 0\n }\n\n let cleaned = 0\n const now = Date.now()\n const entries = await fs.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.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 const cacheKey = generateCacheKey(url, binaryName)\n const cacheEntryDir = path.join(cacheDir, cacheKey)\n const binaryPath = normalizePath(path.join(cacheEntryDir, binaryName))\n\n let downloaded = false\n let computedChecksum = checksum\n\n // Check if we need to download.\n if (\n !force &&\n 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.\n await fs.mkdir(cacheEntryDir, { recursive: true })\n\n // Download the binary.\n computedChecksum = await downloadBinary(url, binaryPath, checksum)\n await writeMetadata(cacheEntryDir, url, computedChecksum || '')\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 * 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\n if (!existsSync(cacheDir)) {\n return []\n }\n\n const results = []\n const now = Date.now()\n const entries = await fs.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 // Find the binary file in the directory.\n // eslint-disable-next-line no-await-in-loop\n const files = await fs.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.stat(binaryPath)\n\n const metaObj = metadata as Record<string, unknown>\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: (metaObj['url'] as string) || '',\n })\n }\n } catch {}\n }\n\n return results\n}\n"],
|
|
5
|
+
"mappings": ";6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,cAAAC,EAAA,oBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAN,GAEA,IAAAO,EAA2B,uBAC3BC,EAA2C,mBAC3CC,EAAe,sBACfC,EAAiB,wBAEjBC,EAAsB,+BAEtBC,EAAiC,2BACjCC,EAA4C,gBA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,EAAgB,EAEjC,GAAI,IAAC,cAAWoC,CAAQ,EACtB,MAAO,CAAC,EAGV,MAAMkB,EAAU,CAAC,EACX9B,EAAM,KAAK,IAAI,EACfc,EAAU,MAAM,EAAAR,SAAG,QAAQM,CAAQ,EAEzC,UAAWG,KAASD,EAAS,CAC3B,MAAME,EAAY,EAAArB,QAAK,KAAKiB,EAAUG,CAAK,EAC3C,GAAI,CAEF,GAAI,CAAE,QAAM,SAAMC,CAAS,EACzB,SAGF,MAAMlB,EAAWL,EAAgBuB,CAAS,EAEpCjB,EAAW,QAAM,YAASD,EAAU,CAAE,OAAQ,EAAM,CAAC,EAC3D,GACE,CAACC,GACD,OAAOA,GAAa,UACpB,MAAM,QAAQA,CAAQ,EAEtB,SAMF,MAAMgC,GADQ,MAAM,EAAAzB,SAAG,QAAQU,CAAS,GACf,KAAKgB,GAAK,CAACA,EAAE,WAAW,GAAG,CAAC,EAErD,GAAID,EAAY,CACd,MAAMN,EAAa,EAAA9B,QAAK,KAAKqB,EAAWe,CAAU,EAE5CE,EAAc,MAAM,EAAA3B,SAAG,KAAKmB,CAAU,EAEtCS,EAAUnC,EAChB+B,EAAQ,KAAK,CACX,IAAK9B,GAAQkC,EAAQ,WAA2B,GAChD,KAAOA,EAAQ,MAAsB,UACrC,SAAWA,EAAQ,UAA0B,GAC7C,KAAMH,EACN,SAAWG,EAAQ,UAA0B,UAC7C,KAAMD,EAAY,KAClB,IAAMC,EAAQ,KAAqB,EACrC,CAAC,CACH,CACF,MAAQ,CAAC,CACX,CAEA,OAAOJ,CACT",
|
|
6
|
+
"names": ["dlx_binary_exports", "__export", "cleanDlxCache", "dlxBinary", "getDlxCachePath", "listDlxCache", "__toCommonJS", "import_node_crypto", "import_node_fs", "import_node_os", "import_node_path", "import_platform", "import_download_lock", "import_fs", "import_objects", "import_path", "import_paths", "import_spawn", "generateCacheKey", "url", "name", "getMetadataPath", "cacheEntryPath", "path", "isCacheValid", "cacheTtl", "metaPath", "metadata", "now", "timestamp", "downloadBinary", "destPath", "checksum", "fileBuffer", "fs", "hasher", "actualChecksum", "writeMetadata", "os", "maxAge", "cacheDir", "cleaned", "entries", "entry", "entryPath", "args", "options", "spawnExtra", "force", "spawnOptions", "binaryName", "cacheKey", "cacheEntryDir", "binaryPath", "downloaded", "computedChecksum", "finalSpawnOptions", "spawnPromise", "results", "binaryFile", "f", "binaryStats", "metaObj"]
|
|
7
7
|
}
|
package/dist/download-lock.d.ts
CHANGED
|
@@ -22,7 +22,8 @@ export interface DownloadWithLockOptions extends HttpDownloadOptions {
|
|
|
22
22
|
pollInterval?: number | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* Maximum age of a lock before it's considered stale in milliseconds.
|
|
25
|
-
*
|
|
25
|
+
* Aligned with npm's npx locking strategy (5-10 seconds).
|
|
26
|
+
* @default 10000 (10 seconds)
|
|
26
27
|
*/
|
|
27
28
|
staleTimeout?: number | undefined;
|
|
28
29
|
}
|
package/dist/download-lock.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var d=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var y=(o,t)=>{for(var n in t)d(o,n,{get:t[n],enumerable:!0})},b=(o,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!h.call(o,r)&&r!==n&&d(o,r,{get:()=>t[r],enumerable:!(i=T(t,r))||i.enumerable});return o};var I=o=>b(d({},"__esModule",{value:!0}),o);var E={};y(E,{downloadWithLock:()=>z});module.exports=I(E);var m=require("node:fs"),e=require("node:fs/promises"),l=require("node:path"),D=require("./http-request");function O(o,t){const n=t||`${(0,l.dirname)(o)}/.locks`,i=`${o.replace(/[^\w.-]/g,"_")}.lock`;return(0,l.join)(n,i)}function x(o,t){if(Date.now()-o.startTime>t)return!0;try{return process.kill(o.pid,0),!1}catch{return!0}}async function _(o,t,n){const{lockTimeout:i,locksDir:r,pollInterval:u,staleTimeout:f}=n,a=O(o,r),w=(0,l.dirname)(a);await(0,e.mkdir)(w,{recursive:!0});const c=Date.now();for(;;)try{if((0,m.existsSync)(a)){const p=await(0,e.readFile)(a,"utf8"),k=JSON.parse(p);if(x(k,f))await(0,e.rm)(a,{force:!0});else{if(Date.now()-c>i)throw new Error(`Lock acquisition timed out after ${i}ms (held by PID ${k.pid})`);await new Promise(g=>setTimeout(g,u));continue}}const s={pid:process.pid,startTime:Date.now(),url:t};return await(0,e.writeFile)(a,JSON.stringify(s,null,2),{flag:"wx"}),a}catch(s){if(s.code==="EEXIST"){if(Date.now()-c>i)throw new Error(`Lock acquisition timed out after ${i}ms`);await new Promise(p=>setTimeout(p,u));continue}throw s}}async function v(o){try{await(0,e.rm)(o,{force:!0})}catch{}}async function z(o,t,n){const{lockTimeout:i=6e4,locksDir:r,pollInterval:u=1e3,staleTimeout:f=
|
|
2
|
+
var d=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var y=(o,t)=>{for(var n in t)d(o,n,{get:t[n],enumerable:!0})},b=(o,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!h.call(o,r)&&r!==n&&d(o,r,{get:()=>t[r],enumerable:!(i=T(t,r))||i.enumerable});return o};var I=o=>b(d({},"__esModule",{value:!0}),o);var E={};y(E,{downloadWithLock:()=>z});module.exports=I(E);var m=require("node:fs"),e=require("node:fs/promises"),l=require("node:path"),D=require("./http-request");function O(o,t){const n=t||`${(0,l.dirname)(o)}/.locks`,i=`${o.replace(/[^\w.-]/g,"_")}.lock`;return(0,l.join)(n,i)}function x(o,t){if(Date.now()-o.startTime>t)return!0;try{return process.kill(o.pid,0),!1}catch{return!0}}async function _(o,t,n){const{lockTimeout:i,locksDir:r,pollInterval:u,staleTimeout:f}=n,a=O(o,r),w=(0,l.dirname)(a);await(0,e.mkdir)(w,{recursive:!0});const c=Date.now();for(;;)try{if((0,m.existsSync)(a)){const p=await(0,e.readFile)(a,"utf8"),k=JSON.parse(p);if(x(k,f))await(0,e.rm)(a,{force:!0});else{if(Date.now()-c>i)throw new Error(`Lock acquisition timed out after ${i}ms (held by PID ${k.pid})`);await new Promise(g=>setTimeout(g,u));continue}}const s={pid:process.pid,startTime:Date.now(),url:t};return await(0,e.writeFile)(a,JSON.stringify(s,null,2),{flag:"wx"}),a}catch(s){if(s.code==="EEXIST"){if(Date.now()-c>i)throw new Error(`Lock acquisition timed out after ${i}ms`);await new Promise(p=>setTimeout(p,u));continue}throw s}}async function v(o){try{await(0,e.rm)(o,{force:!0})}catch{}}async function z(o,t,n){const{lockTimeout:i=6e4,locksDir:r,pollInterval:u=1e3,staleTimeout:f=1e4,...a}={__proto__:null,...n};if((0,m.existsSync)(t)){const c=await(0,e.stat)(t).catch(()=>null);if(c&&c.size>0)return{path:t,size:c.size}}const w=await _(t,o,{lockTimeout:i,locksDir:r,pollInterval:u,staleTimeout:f});try{if((0,m.existsSync)(t)){const s=await(0,e.stat)(t).catch(()=>null);if(s&&s.size>0)return{path:t,size:s.size}}return await(0,D.httpDownload)(o,t,a)}finally{await v(w)}}0&&(module.exports={downloadWithLock});
|
|
3
3
|
//# sourceMappingURL=download-lock.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/download-lock.ts"],
|
|
4
|
-
"sourcesContent": ["/** @fileoverview Download locking utilities to prevent concurrent downloads of the same resource. Uses file-based locking for cross-process synchronization. */\n\nimport { existsSync } from 'node:fs'\nimport { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport type { HttpDownloadOptions, HttpDownloadResult } from './http-request'\nimport { httpDownload } from './http-request'\n\nexport interface DownloadLockInfo {\n pid: number\n startTime: number\n url: string\n}\n\nexport interface DownloadWithLockOptions extends HttpDownloadOptions {\n /**\n * Maximum time to wait for lock acquisition in milliseconds.\n * @default 60000 (1 minute)\n */\n lockTimeout?: number | undefined\n /**\n * Directory where lock files are stored.\n * @default '<destPath>.locks'\n */\n locksDir?: string | undefined\n /**\n * Interval for checking stale locks in milliseconds.\n * @default 1000 (1 second)\n */\n pollInterval?: number | undefined\n /**\n * Maximum age of a lock before it's considered stale in milliseconds.\n * @default
|
|
5
|
-
"mappings": ";4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAA2B,mBAC3BC,EAAqD,4BACrDC,EAA8B,qBAE9BC,EAA6B,
|
|
4
|
+
"sourcesContent": ["/** @fileoverview Download locking utilities to prevent concurrent downloads of the same resource. Uses file-based locking for cross-process synchronization. */\n\nimport { existsSync } from 'node:fs'\nimport { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport type { HttpDownloadOptions, HttpDownloadResult } from './http-request'\nimport { httpDownload } from './http-request'\n\nexport interface DownloadLockInfo {\n pid: number\n startTime: number\n url: string\n}\n\nexport interface DownloadWithLockOptions extends HttpDownloadOptions {\n /**\n * Maximum time to wait for lock acquisition in milliseconds.\n * @default 60000 (1 minute)\n */\n lockTimeout?: number | undefined\n /**\n * Directory where lock files are stored.\n * @default '<destPath>.locks'\n */\n locksDir?: string | undefined\n /**\n * Interval for checking stale locks in milliseconds.\n * @default 1000 (1 second)\n */\n pollInterval?: number | undefined\n /**\n * Maximum age of a lock before it's considered stale in milliseconds.\n * Aligned with npm's npx locking strategy (5-10 seconds).\n * @default 10000 (10 seconds)\n */\n staleTimeout?: number | undefined\n}\n\n/**\n * Get the path to the lock file for a destination path.\n */\nfunction getLockFilePath(destPath: string, locksDir?: string): string {\n const dir = locksDir || `${dirname(destPath)}/.locks`\n const filename = `${destPath.replace(/[^\\w.-]/g, '_')}.lock`\n return join(dir, filename)\n}\n\n/**\n * Check if a lock is stale (process no longer exists or too old).\n */\nfunction isLockStale(\n lockInfo: DownloadLockInfo,\n staleTimeout: number,\n): boolean {\n // Check if lock is too old\n const age = Date.now() - lockInfo.startTime\n if (age > staleTimeout) {\n return true\n }\n\n // Check if process still exists (Node.js specific)\n try {\n // process.kill(pid, 0) doesn't actually kill the process\n // It just checks if the process exists\n process.kill(lockInfo.pid, 0)\n return false\n } catch {\n // Process doesn't exist\n return true\n }\n}\n\n/**\n * Acquire a lock for downloading to a destination path.\n * @throws {Error} When lock cannot be acquired within timeout.\n */\nasync function acquireLock(\n destPath: string,\n url: string,\n options: {\n lockTimeout: number\n locksDir?: string | undefined\n pollInterval: number\n staleTimeout: number\n },\n): Promise<string> {\n const { lockTimeout, locksDir, pollInterval, staleTimeout } = options\n const lockPath = getLockFilePath(destPath, locksDir)\n const lockDir = dirname(lockPath)\n\n // Ensure lock directory exists\n await mkdir(lockDir, { recursive: true })\n\n const startTime = Date.now()\n\n while (true) {\n try {\n // Try to read existing lock\n if (existsSync(lockPath)) {\n // eslint-disable-next-line no-await-in-loop\n const lockContent = await readFile(lockPath, 'utf8')\n const lockInfo: DownloadLockInfo = JSON.parse(lockContent)\n\n // Check if lock is stale\n if (isLockStale(lockInfo, staleTimeout)) {\n // Remove stale lock\n // eslint-disable-next-line no-await-in-loop\n await rm(lockPath, { force: true })\n } else {\n // Lock is valid, check timeout\n if (Date.now() - startTime > lockTimeout) {\n throw new Error(\n `Lock acquisition timed out after ${lockTimeout}ms (held by PID ${lockInfo.pid})`,\n )\n }\n\n // Wait and retry\n // eslint-disable-next-line no-await-in-loop\n await new Promise(resolve => setTimeout(resolve, pollInterval))\n continue\n }\n }\n\n // Try to create lock file\n const lockInfo: DownloadLockInfo = {\n pid: process.pid,\n startTime: Date.now(),\n url,\n }\n\n // eslint-disable-next-line no-await-in-loop\n await writeFile(lockPath, JSON.stringify(lockInfo, null, 2), {\n // Use 'wx' flag to fail if file exists (atomic operation)\n flag: 'wx',\n })\n\n // Successfully acquired lock\n return lockPath\n } catch (e) {\n // If file already exists, another process created it first\n if ((e as NodeJS.ErrnoException).code === 'EEXIST') {\n if (Date.now() - startTime > lockTimeout) {\n throw new Error(`Lock acquisition timed out after ${lockTimeout}ms`)\n }\n // eslint-disable-next-line no-await-in-loop\n await new Promise(resolve => setTimeout(resolve, pollInterval))\n continue\n }\n\n // Other error\n throw e\n }\n }\n}\n\n/**\n * Release a lock by removing the lock file.\n */\nasync function releaseLock(lockPath: string): Promise<void> {\n try {\n await rm(lockPath, { force: true })\n } catch {\n // Ignore errors when releasing lock\n }\n}\n\n/**\n * Download a file with locking to prevent concurrent downloads of the same resource.\n * If another process is already downloading to the same destination, this will wait\n * for the download to complete (up to lockTimeout) before proceeding.\n *\n * @throws {Error} When download fails or lock cannot be acquired.\n *\n * @example\n * ```typescript\n * const result = await downloadWithLock(\n * 'https://example.com/file.tar.gz',\n * '/tmp/downloads/file.tar.gz',\n * {\n * retries: 3,\n * lockTimeout: 60000, // Wait up to 1 minute for other downloads\n * }\n * )\n * ```\n */\nexport async function downloadWithLock(\n url: string,\n destPath: string,\n options?: DownloadWithLockOptions | undefined,\n): Promise<HttpDownloadResult> {\n const {\n lockTimeout = 60_000,\n locksDir,\n pollInterval = 1000,\n // Aligned with npm's npx locking (5-10s range).\n staleTimeout = 10_000,\n ...downloadOptions\n } = { __proto__: null, ...options } as DownloadWithLockOptions\n\n // If file already exists and has content, return immediately\n if (existsSync(destPath)) {\n const statResult = await stat(destPath).catch(() => null)\n if (statResult && statResult.size > 0) {\n return {\n path: destPath,\n size: statResult.size,\n }\n }\n }\n\n // Acquire lock\n const lockPath = await acquireLock(destPath, url, {\n lockTimeout,\n locksDir,\n pollInterval,\n staleTimeout,\n })\n\n try {\n // Check again if file was created while we were waiting for lock\n if (existsSync(destPath)) {\n const statResult = await stat(destPath).catch(() => null)\n if (statResult && statResult.size > 0) {\n return {\n path: destPath,\n size: statResult.size,\n }\n }\n }\n\n // Perform download\n const result = await httpDownload(url, destPath, downloadOptions)\n\n return result\n } finally {\n // Always release lock\n await releaseLock(lockPath)\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MAAMD,EAAYN,CAAQ,CAC5B,CACF",
|
|
6
6
|
"names": ["download_lock_exports", "__export", "downloadWithLock", "__toCommonJS", "import_node_fs", "import_promises", "import_node_path", "import_http_request", "getLockFilePath", "destPath", "locksDir", "dir", "filename", "isLockStale", "lockInfo", "staleTimeout", "acquireLock", "url", "options", "lockTimeout", "pollInterval", "lockPath", "lockDir", "startTime", "lockContent", "resolve", "e", "releaseLock", "downloadOptions", "statResult"]
|
|
7
7
|
}
|