@socketsecurity/lib 3.4.0 → 4.0.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 +15 -0
- package/README.md +8 -8
- package/dist/agent.js +11 -24
- package/dist/bin.d.ts +97 -40
- package/dist/bin.js +129 -134
- package/dist/cacache.d.ts +5 -2
- package/dist/cacache.js +29 -18
- package/dist/cache-with-ttl.js +1 -1
- package/dist/constants/agents.d.ts +0 -4
- package/dist/constants/agents.js +13 -4
- package/dist/constants/node.d.ts +1 -0
- package/dist/constants/node.js +2 -5
- package/dist/constants/packages.js +22 -10
- package/dist/dlx-binary.js +9 -17
- package/dist/dlx-manifest.js +2 -2
- package/dist/dlx-package.js +22 -62
- package/dist/dlx.js +14 -14
- package/dist/fs.js +19 -24
- package/dist/git.d.ts +6 -6
- package/dist/git.js +11 -14
- package/dist/globs.js +16 -29
- package/dist/ipc.d.ts +4 -4
- package/dist/ipc.js +3 -3
- package/dist/logger.d.ts +0 -25
- package/dist/logger.js +0 -26
- package/dist/package-default-node-range.js +13 -3
- package/dist/package-extensions.d.ts +2 -1
- package/dist/package-extensions.js +12 -2
- package/dist/packages/editable.d.ts +0 -3
- package/dist/packages/editable.js +34 -24
- package/dist/packages/isolation.js +32 -32
- package/dist/packages/licenses.js +18 -32
- package/dist/packages/manifest.js +18 -33
- package/dist/packages/normalize.js +19 -43
- package/dist/packages/operations.js +33 -80
- package/dist/packages/provenance.js +14 -4
- package/dist/packages/specs.js +13 -12
- package/dist/packages/validation.js +12 -10
- package/dist/packages.d.ts +1 -1
- package/dist/packages.js +3 -3
- package/dist/paths/dirnames.d.ts +13 -0
- package/dist/paths/dirnames.js +50 -0
- package/dist/paths/exts.d.ts +18 -0
- package/dist/paths/exts.js +68 -0
- package/dist/paths/filenames.d.ts +16 -0
- package/dist/paths/filenames.js +62 -0
- package/dist/paths/globs.d.ts +10 -0
- package/dist/paths/globs.js +44 -0
- package/dist/{path.d.ts → paths/normalize.d.ts} +41 -0
- package/dist/{path.js → paths/normalize.js} +17 -4
- package/dist/{packages/paths.js → paths/packages.js} +8 -8
- package/dist/{paths.js → paths/socket.js} +29 -65
- package/dist/sea.js +2 -2
- package/dist/shadow.js +3 -3
- package/dist/sorts.js +12 -2
- package/dist/spawn.d.ts +15 -12
- package/dist/spawn.js +42 -30
- package/dist/spinner.d.ts +2 -6
- package/dist/spinner.js +6 -39
- package/dist/stdio/prompts.d.ts +8 -10
- package/dist/stdio/prompts.js +14 -12
- package/dist/streams.d.ts +0 -4
- package/dist/streams.js +3 -12
- package/dist/temporary-executor.js +3 -3
- package/dist/versions.js +31 -28
- package/package.json +28 -16
- package/dist/constants/paths.d.ts +0 -51
- package/dist/constants/paths.js +0 -152
- /package/dist/{packages/paths.d.ts → paths/packages.d.ts} +0 -0
- /package/dist/{paths.d.ts → paths/socket.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ 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
|
+
## [4.0.0](https://github.com/SocketDev/socket-lib/releases/tag/v4.0.0) - 2025-11-15
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **paths**: Reorganized path utilities into dedicated `paths/*` submodules for improved modularity
|
|
13
|
+
- **imports**: Converted lazy require() calls to ES6 static imports for better tree-shaking and bundler compatibility
|
|
14
|
+
|
|
15
|
+
## [3.5.0](https://github.com/SocketDev/socket-lib/releases/tag/v3.5.0) - 2025-11-14
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- **argv/quote**: New utilities for quoting command-line arguments when using `spawn()` with `shell: true`
|
|
20
|
+
- `posixQuote(arg)`: Quote arguments for POSIX shells (bash, sh, zsh) using single quotes
|
|
21
|
+
- `win32Quote(arg)`: Quote arguments for Windows cmd.exe using double quotes
|
|
22
|
+
|
|
8
23
|
## [3.4.0](https://github.com/SocketDev/socket-lib/releases/tag/v3.4.0) - 2025-11-14
|
|
9
24
|
|
|
10
25
|
### Added
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://socket.dev/npm/package/@socketsecurity/lib)
|
|
4
4
|
[](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml)
|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
[](https://twitter.com/SocketSecurity)
|
|
8
8
|
[](https://bsky.app/profile/socket.dev)
|
|
@@ -31,13 +31,13 @@ spinner.stop()
|
|
|
31
31
|
|
|
32
32
|
## What's Inside
|
|
33
33
|
|
|
34
|
-
- **Visual Effects** →
|
|
35
|
-
- **File System** → fs,
|
|
36
|
-
- **Package Management** → npm, pnpm, yarn
|
|
37
|
-
- **Process & Spawn** →
|
|
38
|
-
- **Environment** →
|
|
39
|
-
- **Constants** →
|
|
40
|
-
- **Utilities** →
|
|
34
|
+
- **Visual Effects** → logger, spinner, themes
|
|
35
|
+
- **File System** → fs, globs, paths
|
|
36
|
+
- **Package Management** → dlx, npm, pnpm, yarn
|
|
37
|
+
- **Process & Spawn** → process spawning
|
|
38
|
+
- **Environment** → env getters
|
|
39
|
+
- **Constants** → node, npm, platform
|
|
40
|
+
- **Utilities** → arrays, objects, promises, strings
|
|
41
41
|
|
|
42
42
|
## Development
|
|
43
43
|
|
package/dist/agent.js
CHANGED
|
@@ -34,8 +34,10 @@ __export(agent_exports, {
|
|
|
34
34
|
isPnpmLoglevelFlag: () => isPnpmLoglevelFlag
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(agent_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_agents = require("#constants/agents");
|
|
38
|
+
var import_node = require("#constants/node");
|
|
38
39
|
var import_platform = require("#constants/platform");
|
|
40
|
+
var import_ci = require("#env/ci");
|
|
39
41
|
var import_bin = require("./bin");
|
|
40
42
|
var import_debug = require("./debug");
|
|
41
43
|
var import_fs = require("./fs");
|
|
@@ -86,7 +88,7 @@ function execNpm(args, options) {
|
|
|
86
88
|
// one level quieter.
|
|
87
89
|
useDebug || npmArgs.some(isNpmLoglevelFlag) ? [] : ["--loglevel", "warn"]
|
|
88
90
|
);
|
|
89
|
-
const npmBin =
|
|
91
|
+
const npmBin = import_agents.NPM_BIN_PATH;
|
|
90
92
|
return (0, import_spawn.spawn)(
|
|
91
93
|
npmBin,
|
|
92
94
|
[
|
|
@@ -227,40 +229,25 @@ function execScript(scriptName, args, options) {
|
|
|
227
229
|
if (spawnOptions.shell === true) {
|
|
228
230
|
return (0, import_spawn.spawn)(scriptName, resolvedArgs, spawnOptions);
|
|
229
231
|
}
|
|
230
|
-
const useNodeRun = !prepost &&
|
|
232
|
+
const useNodeRun = !prepost && (0, import_node.supportsNodeRun)();
|
|
231
233
|
const cwd = (0, import_objects.getOwn)(spawnOptions, "cwd") ?? process.cwd();
|
|
232
|
-
const pnpmLockPath = (0, import_fs.findUpSync)(
|
|
233
|
-
/*@__INLINE__*/
|
|
234
|
-
require("#constants/agents").PNPM_LOCK_YAML,
|
|
235
|
-
{ cwd }
|
|
236
|
-
);
|
|
234
|
+
const pnpmLockPath = (0, import_fs.findUpSync)(import_agents.PNPM_LOCK_YAML, { cwd });
|
|
237
235
|
if (pnpmLockPath) {
|
|
238
236
|
return execPnpm(["run", scriptName, ...resolvedArgs], spawnOptions);
|
|
239
237
|
}
|
|
240
|
-
const packageLockPath = (0, import_fs.findUpSync)(
|
|
241
|
-
/*@__INLINE__*/
|
|
242
|
-
require("#constants/agents").PACKAGE_LOCK_JSON,
|
|
243
|
-
{ cwd }
|
|
244
|
-
);
|
|
238
|
+
const packageLockPath = (0, import_fs.findUpSync)(import_agents.PACKAGE_LOCK_JSON, { cwd });
|
|
245
239
|
if (packageLockPath) {
|
|
246
240
|
return execNpm(["run", scriptName, ...resolvedArgs], spawnOptions);
|
|
247
241
|
}
|
|
248
|
-
const yarnLockPath = (0, import_fs.findUpSync)(
|
|
249
|
-
/*@__INLINE__*/
|
|
250
|
-
require("#constants/agents").YARN_LOCK,
|
|
251
|
-
{ cwd }
|
|
252
|
-
);
|
|
242
|
+
const yarnLockPath = (0, import_fs.findUpSync)(import_agents.YARN_LOCK, { cwd });
|
|
253
243
|
if (yarnLockPath) {
|
|
254
244
|
return execYarn(["run", scriptName, ...resolvedArgs], spawnOptions);
|
|
255
245
|
}
|
|
256
246
|
return (0, import_spawn.spawn)(
|
|
257
|
-
|
|
247
|
+
(0, import_node.getExecPath)(),
|
|
258
248
|
[
|
|
259
|
-
|
|
260
|
-
...useNodeRun ? ["--run"] : [
|
|
261
|
-
require("#constants/agents").NPM_REAL_EXEC_PATH,
|
|
262
|
-
"run"
|
|
263
|
-
],
|
|
249
|
+
...(0, import_node.getNodeNoWarningsFlags)(),
|
|
250
|
+
...useNodeRun ? ["--run"] : [import_agents.NPM_REAL_EXEC_PATH, "run"],
|
|
264
251
|
scriptName,
|
|
265
252
|
...resolvedArgs
|
|
266
253
|
],
|
package/dist/bin.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
args: string[] | readonly string[];
|
|
8
|
-
code: number;
|
|
9
|
-
signal: NodeJS.Signals;
|
|
10
|
-
stdout: string | Buffer<ArrayBufferLike>;
|
|
11
|
-
stderr: string | Buffer<ArrayBufferLike>;
|
|
12
|
-
}>;
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Private Helper Functions
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Types and Interfaces
|
|
6
|
+
// ============================================================================
|
|
13
7
|
/**
|
|
14
8
|
* Options for the which function.
|
|
15
9
|
*/
|
|
@@ -24,54 +18,117 @@ export interface WhichOptions {
|
|
|
24
18
|
pathExt?: string | undefined;
|
|
25
19
|
/** Environment variables to use. */
|
|
26
20
|
env?: Record<string, string | undefined> | undefined;
|
|
21
|
+
/** Current working directory for resolving relative paths. */
|
|
22
|
+
cwd?: string | undefined;
|
|
27
23
|
}
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Public API (alphabetically sorted)
|
|
26
|
+
// ============================================================================
|
|
28
27
|
/**
|
|
29
|
-
*
|
|
30
|
-
* Wrapper around the which package for lazy loading.
|
|
28
|
+
* Execute a binary with the given arguments.
|
|
31
29
|
*/
|
|
32
|
-
|
|
33
|
-
export declare function
|
|
34
|
-
|
|
30
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
31
|
+
export declare function execBin(binPath: string, args?: string[], options?: import('./spawn').SpawnOptions): Promise<{
|
|
32
|
+
cmd: string;
|
|
33
|
+
args: string[] | readonly string[];
|
|
34
|
+
code: number;
|
|
35
|
+
signal: NodeJS.Signals;
|
|
36
|
+
stdout: string | Buffer<ArrayBufferLike>;
|
|
37
|
+
stderr: string | Buffer<ArrayBufferLike>;
|
|
38
|
+
}>;
|
|
35
39
|
/**
|
|
36
|
-
* Find
|
|
37
|
-
* Wrapper around the which package for lazy loading.
|
|
40
|
+
* Find the real executable for a binary, bypassing shadow bins.
|
|
38
41
|
*/
|
|
39
|
-
|
|
40
|
-
export declare function whichSync(binName: string, options?: WhichOptions): string | string[] | undefined;
|
|
41
|
-
/* c8 ignore stop */
|
|
42
|
+
export declare function findRealBin(binName: string, commonPaths?: string[]): string | undefined;
|
|
42
43
|
/**
|
|
43
|
-
* Find
|
|
44
|
-
* @throws {Error} If the binary is not found and nothrow is false.
|
|
44
|
+
* Find the real npm executable, bypassing any aliases and shadow bins.
|
|
45
45
|
*/
|
|
46
|
-
export declare function
|
|
46
|
+
export declare function findRealNpm(): string;
|
|
47
47
|
/**
|
|
48
|
-
* Find
|
|
49
|
-
* @throws {Error} If the binary is not found and nothrow is false.
|
|
48
|
+
* Find the real pnpm executable, bypassing any aliases and shadow bins.
|
|
50
49
|
*/
|
|
51
|
-
export declare function
|
|
50
|
+
export declare function findRealPnpm(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Find the real yarn executable, bypassing any aliases and shadow bins.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findRealYarn(): string;
|
|
52
55
|
/**
|
|
53
56
|
* Check if a directory path contains any shadow bin patterns.
|
|
54
57
|
*/
|
|
55
58
|
export declare function isShadowBinPath(dirPath: string | undefined): boolean;
|
|
59
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
56
60
|
/**
|
|
57
|
-
*
|
|
61
|
+
* Resolve a binary path to the real underlying script file.
|
|
62
|
+
* Handles Windows .cmd wrappers and Unix shell scripts, resolving them to the actual .js files they execute.
|
|
58
63
|
*/
|
|
59
|
-
export declare function
|
|
64
|
+
export declare function resolveRealBinSync(binPath: string): string;
|
|
60
65
|
/**
|
|
61
|
-
* Find
|
|
66
|
+
* Find an executable in the system PATH asynchronously.
|
|
67
|
+
*
|
|
68
|
+
* This function resolves binary names to their full paths by searching the system PATH.
|
|
69
|
+
* It should only be used for binary names (not paths). If the input is already a path
|
|
70
|
+
* (absolute or relative), it will be returned as-is without PATH resolution.
|
|
71
|
+
*
|
|
72
|
+
* Binary name vs. path detection:
|
|
73
|
+
* - Binary names: 'npm', 'git', 'node' - will be resolved via PATH
|
|
74
|
+
* - Absolute paths: '/usr/bin/node', 'C:\\Program Files\\nodejs\\node.exe' - returned as-is
|
|
75
|
+
* - Relative paths: './node', '../bin/npm' - returned as-is
|
|
76
|
+
*
|
|
77
|
+
* @param {string} binName - The binary name to resolve (e.g., 'npm', 'git')
|
|
78
|
+
* @param {WhichOptions | undefined} options - Options for resolution
|
|
79
|
+
* @returns {Promise<string | string[] | null>} Promise resolving to the full path, the original path, or null if not found
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Resolve binary names
|
|
84
|
+
* await which('node') // '/usr/local/bin/node'
|
|
85
|
+
* await which('npm') // '/usr/local/bin/npm'
|
|
86
|
+
* await which('nonexistent') // null
|
|
87
|
+
*
|
|
88
|
+
* // Paths are returned as-is
|
|
89
|
+
* await which('/usr/bin/node') // '/usr/bin/node'
|
|
90
|
+
* await which('./local-script') // './local-script'
|
|
91
|
+
* ```
|
|
62
92
|
*/
|
|
63
|
-
export declare function
|
|
93
|
+
export declare function which(binName: string, options?: WhichOptions): Promise<string | string[] | null>;
|
|
64
94
|
/**
|
|
65
|
-
* Find the
|
|
95
|
+
* Find a binary in the system PATH and resolve to the real underlying script asynchronously.
|
|
96
|
+
* Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the actual .js files they execute.
|
|
97
|
+
* @throws {Error} If the binary is not found and nothrow is false.
|
|
66
98
|
*/
|
|
67
|
-
export declare function
|
|
99
|
+
export declare function whichReal(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
|
|
68
100
|
/**
|
|
69
|
-
* Find the
|
|
101
|
+
* Find a binary in the system PATH and resolve to the real underlying script synchronously.
|
|
102
|
+
* Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the actual .js files they execute.
|
|
103
|
+
* @throws {Error} If the binary is not found and nothrow is false.
|
|
70
104
|
*/
|
|
71
|
-
export declare function
|
|
72
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
105
|
+
export declare function whichRealSync(binName: string, options?: WhichOptions): string | string[] | undefined;
|
|
73
106
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
107
|
+
* Find an executable in the system PATH synchronously.
|
|
108
|
+
*
|
|
109
|
+
* This function resolves binary names to their full paths by searching the system PATH.
|
|
110
|
+
* It should only be used for binary names (not paths). If the input is already a path
|
|
111
|
+
* (absolute or relative), it will be returned as-is without PATH resolution.
|
|
112
|
+
*
|
|
113
|
+
* Binary name vs. path detection:
|
|
114
|
+
* - Binary names: 'npm', 'git', 'node' - will be resolved via PATH
|
|
115
|
+
* - Absolute paths: '/usr/bin/node', 'C:\\Program Files\\nodejs\\node.exe' - returned as-is
|
|
116
|
+
* - Relative paths: './node', '../bin/npm' - returned as-is
|
|
117
|
+
*
|
|
118
|
+
* @param {string} binName - The binary name to resolve (e.g., 'npm', 'git')
|
|
119
|
+
* @param {WhichOptions | undefined} options - Options for resolution
|
|
120
|
+
* @returns {string | string[] | null} The full path to the binary, the original path if input is a path, or null if not found
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Resolve binary names
|
|
125
|
+
* whichSync('node') // '/usr/local/bin/node'
|
|
126
|
+
* whichSync('npm') // '/usr/local/bin/npm'
|
|
127
|
+
* whichSync('nonexistent') // null
|
|
128
|
+
*
|
|
129
|
+
* // Paths are returned as-is
|
|
130
|
+
* whichSync('/usr/bin/node') // '/usr/bin/node'
|
|
131
|
+
* whichSync('./local-script') // './local-script'
|
|
132
|
+
* ```
|
|
76
133
|
*/
|
|
77
|
-
export declare function
|
|
134
|
+
export declare function whichSync(binName: string, options?: WhichOptions): string | string[] | null;
|