@socketsecurity/lib 3.5.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +8 -8
  3. package/dist/agent.js +12 -25
  4. package/dist/bin.d.ts +97 -40
  5. package/dist/bin.js +133 -138
  6. package/dist/cacache.d.ts +5 -2
  7. package/dist/cacache.js +29 -18
  8. package/dist/cache-with-ttl.js +1 -1
  9. package/dist/constants/agents.d.ts +0 -4
  10. package/dist/constants/agents.js +13 -4
  11. package/dist/constants/node.d.ts +1 -0
  12. package/dist/constants/node.js +2 -5
  13. package/dist/constants/packages.js +23 -11
  14. package/dist/constants/process.d.ts +1 -1
  15. package/dist/constants/process.js +2 -2
  16. package/dist/debug.js +3 -3
  17. package/dist/dlx-binary.js +10 -18
  18. package/dist/dlx-manifest.js +2 -2
  19. package/dist/dlx-package.js +22 -62
  20. package/dist/dlx.js +14 -14
  21. package/dist/effects/text-shimmer.js +1 -1
  22. package/dist/env/ci.js +2 -2
  23. package/dist/env/debug.js +1 -1
  24. package/dist/env/github.js +1 -1
  25. package/dist/env/home.js +1 -1
  26. package/dist/env/locale.js +1 -1
  27. package/dist/env/node-auth-token.js +1 -1
  28. package/dist/env/node-env.js +1 -1
  29. package/dist/env/npm.js +1 -1
  30. package/dist/env/package-manager.js +1 -1
  31. package/dist/env/path.js +1 -1
  32. package/dist/env/pre-commit.js +2 -2
  33. package/dist/env/rewire.d.ts +7 -7
  34. package/dist/env/rewire.js +1 -1
  35. package/dist/env/shell.js +1 -1
  36. package/dist/env/socket-cli-shadow.js +2 -2
  37. package/dist/env/socket-cli.js +2 -2
  38. package/dist/env/socket.js +2 -2
  39. package/dist/env/temp-dir.js +1 -1
  40. package/dist/env/term.js +1 -1
  41. package/dist/env/test.js +3 -3
  42. package/dist/env/windows.js +1 -1
  43. package/dist/env/xdg.js +1 -1
  44. package/dist/fs.js +20 -25
  45. package/dist/git.d.ts +6 -6
  46. package/dist/git.js +11 -14
  47. package/dist/github.js +2 -2
  48. package/dist/globs.js +16 -29
  49. package/dist/ipc.d.ts +4 -4
  50. package/dist/ipc.js +3 -3
  51. package/dist/logger.d.ts +0 -25
  52. package/dist/logger.js +0 -26
  53. package/dist/objects.js +1 -1
  54. package/dist/package-default-node-range.js +13 -3
  55. package/dist/package-extensions.d.ts +2 -1
  56. package/dist/package-extensions.js +12 -2
  57. package/dist/packages/editable.d.ts +0 -3
  58. package/dist/packages/editable.js +34 -24
  59. package/dist/packages/exports.js +1 -1
  60. package/dist/packages/isolation.js +33 -33
  61. package/dist/packages/licenses.js +20 -34
  62. package/dist/packages/manifest.js +21 -36
  63. package/dist/packages/normalize.js +20 -52
  64. package/dist/packages/operations.js +39 -103
  65. package/dist/packages/provenance.js +15 -5
  66. package/dist/packages/specs.js +13 -12
  67. package/dist/packages/validation.js +12 -10
  68. package/dist/packages.d.ts +2 -2
  69. package/dist/packages.js +3 -3
  70. package/dist/paths/dirnames.d.ts +13 -0
  71. package/dist/paths/dirnames.js +50 -0
  72. package/dist/paths/exts.d.ts +18 -0
  73. package/dist/paths/exts.js +68 -0
  74. package/dist/paths/filenames.d.ts +16 -0
  75. package/dist/paths/filenames.js +62 -0
  76. package/dist/paths/globs.d.ts +10 -0
  77. package/dist/{argv/quote.js → paths/globs.js} +21 -19
  78. package/dist/{path.d.ts → paths/normalize.d.ts} +41 -0
  79. package/dist/{path.js → paths/normalize.js} +18 -5
  80. package/dist/{packages/paths.js → paths/packages.js} +8 -8
  81. package/dist/paths/rewire.d.ts +1 -1
  82. package/dist/{paths.js → paths/socket.js} +31 -67
  83. package/dist/promises.js +2 -2
  84. package/dist/sea.js +2 -2
  85. package/dist/shadow.js +3 -3
  86. package/dist/sorts.js +12 -2
  87. package/dist/spawn.d.ts +15 -12
  88. package/dist/spawn.js +43 -31
  89. package/dist/spinner.d.ts +2 -6
  90. package/dist/spinner.js +9 -41
  91. package/dist/stdio/prompts.d.ts +8 -10
  92. package/dist/stdio/prompts.js +15 -13
  93. package/dist/streams.d.ts +0 -4
  94. package/dist/streams.js +3 -12
  95. package/dist/temporary-executor.js +4 -4
  96. package/dist/versions.js +31 -28
  97. package/package.json +28 -29
  98. package/dist/argv/quote.d.ts +0 -49
  99. package/dist/constants/paths.d.ts +0 -51
  100. package/dist/constants/paths.js +0 -152
  101. /package/dist/{packages/paths.d.ts → paths/packages.d.ts} +0 -0
  102. /package/dist/{paths.d.ts → paths/socket.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ 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.1](https://github.com/SocketDev/socket-lib/releases/tag/v4.0.1) - 2025-11-17
9
+
10
+ ### Changed
11
+
12
+ - Removed # path imports and replaced with relative paths
13
+
14
+ ## [4.0.0](https://github.com/SocketDev/socket-lib/releases/tag/v4.0.0) - 2025-11-15
15
+
16
+ ### Changed
17
+
18
+ - **paths**: Reorganized path utilities into dedicated `paths/*` submodules for improved modularity
19
+ - **imports**: Converted lazy require() calls to ES6 static imports for better tree-shaking and bundler compatibility
20
+
8
21
  ## [3.5.0](https://github.com/SocketDev/socket-lib/releases/tag/v3.5.0) - 2025-11-14
9
22
 
10
23
  ### Added
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Socket Badge](https://socket.dev/api/badge/npm/package/@socketsecurity/lib)](https://socket.dev/npm/package/@socketsecurity/lib)
4
4
  [![CI](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml/badge.svg)](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml)
5
- ![Coverage](https://img.shields.io/badge/coverage-83.06%25-brightgreen)
5
+ ![Coverage](https://img.shields.io/badge/coverage-83.95%25-brightgreen)
6
6
 
7
7
  [![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](https://twitter.com/SocketSecurity)
8
8
  [![Follow @socket.dev on Bluesky](https://img.shields.io/badge/Follow-@socket.dev-1DA1F2?style=social&logo=bluesky)](https://bsky.app/profile/socket.dev)
@@ -31,13 +31,13 @@ spinner.stop()
31
31
 
32
32
  ## What's Inside
33
33
 
34
- - **Visual Effects** → Spinners, themes, logger
35
- - **File System** → fs, paths, globs
36
- - **Package Management** → npm, pnpm, yarn, dlx
37
- - **Process & Spawn** → Safe process spawning
38
- - **Environment** → 68 typed env getters
39
- - **Constants** → Node.js, npm, platform
40
- - **Utilities** → Arrays, objects, strings, promises
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 import_ci = require("#env/ci");
38
- var import_platform = require("#constants/platform");
37
+ var import_agents = require("./constants/agents");
38
+ var import_node = require("./constants/node");
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 = require("#constants/agents").NPM_BIN_PATH;
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 && /* @__PURE__ */ require("#constants/node").supportsNodeRun();
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
- /* @__PURE__ */ require("#constants/node").getExecPath(),
247
+ (0, import_node.getExecPath)(),
258
248
  [
259
- .../* @__PURE__ */ require("#constants/node").getNodeNoWarningsFlags(),
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
- * Execute a binary with the given arguments.
3
- */
4
- /*@__NO_SIDE_EFFECTS__*/
5
- export declare function execBin(binPath: string, args?: string[], options?: import('./spawn').SpawnOptions): Promise<{
6
- cmd: string;
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
- * Find an executable in the system PATH asynchronously.
30
- * Wrapper around the which package for lazy loading.
28
+ * Execute a binary with the given arguments.
31
29
  */
32
- /* c8 ignore start */
33
- export declare function which(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
34
- /* c8 ignore stop */
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 an executable in the system PATH synchronously.
37
- * Wrapper around the which package for lazy loading.
40
+ * Find the real executable for a binary, bypassing shadow bins.
38
41
  */
39
- /* c8 ignore start */
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 and resolve a binary in the system PATH asynchronously.
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 whichBin(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
46
+ export declare function findRealNpm(): string;
47
47
  /**
48
- * Find and resolve a binary in the system PATH synchronously.
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 whichBinSync(binName: string, options?: WhichOptions): string | string[] | undefined;
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
- * Find the real executable for a binary, bypassing shadow bins.
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 findRealBin(binName: string, commonPaths?: string[]): string | undefined;
64
+ export declare function resolveRealBinSync(binPath: string): string;
60
65
  /**
61
- * Find the real npm executable, bypassing any aliases and shadow bins.
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 findRealNpm(): string;
93
+ export declare function which(binName: string, options?: WhichOptions): Promise<string | string[] | null>;
64
94
  /**
65
- * Find the real pnpm executable, bypassing any aliases and shadow bins.
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 findRealPnpm(): string;
99
+ export declare function whichReal(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
68
100
  /**
69
- * Find the real yarn executable, bypassing any aliases and shadow bins.
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 findRealYarn(): string;
72
- /*@__NO_SIDE_EFFECTS__*/
105
+ export declare function whichRealSync(binName: string, options?: WhichOptions): string | string[] | undefined;
73
106
  /**
74
- * Resolve a binary path to its actual executable file.
75
- * Handles Windows .cmd wrappers and Unix shell scripts.
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 resolveBinPathSync(binPath: string): string;
134
+ export declare function whichSync(binName: string, options?: WhichOptions): string | string[] | null;