@socketsecurity/lib 5.0.2 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,30 @@ 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
+ ## [5.1.1](https://github.com/SocketDev/socket-lib/releases/tag/v5.1.1) - 2025-12-28
9
+
10
+ ### Added
11
+
12
+ - **paths**: Added `SOCKET_HOME` environment variable support to customize Socket base directory
13
+ - `getSocketUserDir()` now checks `SOCKET_HOME` before defaulting to `~/.socket`
14
+ - `getSocketDlxDir()` inherits `SOCKET_HOME` support (priority: `SOCKET_DLX_DIR` > `SOCKET_HOME/_dlx` > `~/.socket/_dlx`)
15
+ - Enables flexible directory configuration for restricted or custom environments
16
+
17
+ ### Changed
18
+
19
+ - **paths**: Enhanced directory resolution with temporary directory fallback
20
+ - `getUserHomeDir()` now falls back to `os.tmpdir()` when home directory is unavailable
21
+ - Improves resilience in containerized and restricted environments
22
+ - Priority order: `HOME` > `USERPROFILE` > `os.homedir()` > `os.tmpdir()`
23
+
24
+ ## [5.1.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.1.0) - 2025-12-17
25
+
26
+ ### Added
27
+
28
+ - **types**: Added `ALPM` and `VSCODE` to `PURL_Type` enum
29
+ - `ALPM`: Arch Linux Package Manager ecosystem
30
+ - `VSCODE`: Visual Studio Code extensions ecosystem
31
+
8
32
  ## [5.0.2](https://github.com/SocketDev/socket-lib/releases/tag/v5.0.2) - 2025-12-15
9
33
 
10
34
  ### Changed
@@ -15,7 +15,14 @@ export declare function getOsTmpDir(): string;
15
15
  export declare function getSocketHomePath(): string;
16
16
  /**
17
17
  * Get the Socket user directory (~/.socket).
18
- * Result is memoized for performance.
18
+ * Can be overridden with SOCKET_HOME environment variable or via setPath() for testing.
19
+ * Result is cached via getPathValue for performance.
20
+ *
21
+ * Priority order:
22
+ * 1. Test override via setPath('socket-user-dir', ...)
23
+ * 2. SOCKET_HOME - Base directory override
24
+ * 3. Default: $HOME/.socket
25
+ * 4. Fallback: /tmp/.socket (Unix) or %TEMP%\.socket (Windows)
19
26
  */
20
27
  export declare function getSocketUserDir(): string;
21
28
  /**
@@ -24,13 +31,24 @@ export declare function getSocketUserDir(): string;
24
31
  export declare function getSocketAppDir(appName: string): string;
25
32
  /**
26
33
  * Get the Socket cacache directory (~/.socket/_cacache).
27
- * Can be overridden with SOCKET_CACACHE_DIR environment variable for testing.
28
- * Result is memoized for performance.
34
+ * Can be overridden with SOCKET_CACACHE_DIR environment variable or via setPath() for testing.
35
+ * Result is cached via getPathValue for performance.
36
+ *
37
+ * Priority order:
38
+ * 1. Test override via setPath('socket-cacache-dir', ...)
39
+ * 2. SOCKET_CACACHE_DIR - Full override of cacache directory
40
+ * 3. Default: $SOCKET_HOME/_cacache or $HOME/.socket/_cacache
29
41
  */
30
42
  export declare function getSocketCacacheDir(): string;
31
43
  /**
32
44
  * Get the Socket DLX directory (~/.socket/_dlx).
33
- * Can be overridden with SOCKET_DLX_DIR environment variable for testing.
45
+ * Can be overridden with environment variables.
46
+ *
47
+ * Priority order:
48
+ * 1. SOCKET_DLX_DIR - Full override of DLX cache directory
49
+ * 2. SOCKET_HOME/_dlx - Base directory override (inherits from getSocketUserDir)
50
+ * 3. Default: $HOME/.socket/_dlx
51
+ * 4. Fallback: /tmp/.socket/_dlx (Unix) or %TEMP%\.socket\_dlx (Windows)
34
52
  */
35
53
  export declare function getSocketDlxDir(): string;
36
54
  /**
@@ -56,13 +74,12 @@ export declare function getSocketRegistryGithubCacheDir(): string;
56
74
  /**
57
75
  * Get the user's home directory.
58
76
  * Uses environment variables directly to support test mocking.
59
- * Falls back to os.homedir() if env vars not set.
60
- */
61
- export declare function getUserHomeDir(): string;
62
- /**
63
- * Invalidate all cached path values.
64
- * Called automatically by the paths/rewire module when setPath/clearPath/resetPaths are used.
77
+ * Falls back to temporary directory if home is not available.
65
78
  *
66
- * @internal Used for test rewiring
79
+ * Priority order:
80
+ * 1. HOME environment variable (Unix)
81
+ * 2. USERPROFILE environment variable (Windows)
82
+ * 3. os.homedir()
83
+ * 4. Fallback: os.tmpdir() (rarely used, for restricted environments)
67
84
  */
68
- export declare function invalidateCache(): void;
85
+ export declare function getUserHomeDir(): string;
@@ -41,8 +41,7 @@ __export(socket_exports, {
41
41
  getSocketRegistryDir: () => getSocketRegistryDir,
42
42
  getSocketRegistryGithubCacheDir: () => getSocketRegistryGithubCacheDir,
43
43
  getSocketUserDir: () => getSocketUserDir,
44
- getUserHomeDir: () => getUserHomeDir,
45
- invalidateCache: () => invalidateCache
44
+ getUserHomeDir: () => getUserHomeDir
46
45
  });
47
46
  module.exports = __toCommonJS(socket_exports);
48
47
  var os = __toESM(require("os"));
@@ -64,34 +63,29 @@ function getOsTmpDir() {
64
63
  function getSocketHomePath() {
65
64
  return getSocketUserDir();
66
65
  }
67
- let _cachedSocketUserDir;
68
66
  function getSocketUserDir() {
69
- if (_cachedSocketUserDir === void 0) {
70
- _cachedSocketUserDir = (0, import_normalize.normalizePath)(
71
- path.join(getUserHomeDir(), import_dirnames.DOT_SOCKET_DIR)
72
- );
73
- }
74
- return _cachedSocketUserDir;
67
+ return (0, import_rewire.getPathValue)("socket-user-dir", () => {
68
+ const socketHome = (0, import_socket2.getSocketHome)();
69
+ if (socketHome) {
70
+ return (0, import_normalize.normalizePath)(socketHome);
71
+ }
72
+ return (0, import_normalize.normalizePath)(path.join(getUserHomeDir(), import_dirnames.DOT_SOCKET_DIR));
73
+ });
75
74
  }
76
75
  function getSocketAppDir(appName) {
77
76
  return (0, import_normalize.normalizePath)(
78
77
  path.join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}${appName}`)
79
78
  );
80
79
  }
81
- let _cachedSocketCacacheDir;
82
80
  function getSocketCacacheDir() {
83
- if (_cachedSocketCacacheDir === void 0) {
81
+ return (0, import_rewire.getPathValue)("socket-cacache-dir", () => {
84
82
  if ((0, import_socket2.getSocketCacacheDir)()) {
85
- _cachedSocketCacacheDir = (0, import_normalize.normalizePath)(
86
- (0, import_socket2.getSocketCacacheDir)()
87
- );
88
- } else {
89
- _cachedSocketCacacheDir = (0, import_normalize.normalizePath)(
90
- path.join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}cacache`)
91
- );
83
+ return (0, import_normalize.normalizePath)((0, import_socket2.getSocketCacacheDir)());
92
84
  }
93
- }
94
- return _cachedSocketCacacheDir;
85
+ return (0, import_normalize.normalizePath)(
86
+ path.join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}cacache`)
87
+ );
88
+ });
95
89
  }
96
90
  function getSocketDlxDir() {
97
91
  if ((0, import_socket2.getSocketDlxDirEnv)()) {
@@ -130,13 +124,15 @@ function getUserHomeDir() {
130
124
  if (userProfile) {
131
125
  return userProfile;
132
126
  }
133
- return getOsHomeDir();
134
- }
135
- function invalidateCache() {
136
- _cachedSocketUserDir = void 0;
137
- _cachedSocketCacacheDir = void 0;
127
+ try {
128
+ const osHome = getOsHomeDir();
129
+ if (osHome) {
130
+ return osHome;
131
+ }
132
+ } catch {
133
+ }
134
+ return getOsTmpDir();
138
135
  }
139
- (0, import_rewire.registerCacheInvalidation)(invalidateCache);
140
136
  // Annotate the CommonJS export names for ESM import in node:
141
137
  0 && (module.exports = {
142
138
  getOsHomeDir,
@@ -151,6 +147,5 @@ function invalidateCache() {
151
147
  getSocketRegistryDir,
152
148
  getSocketRegistryGithubCacheDir,
153
149
  getSocketUserDir,
154
- getUserHomeDir,
155
- invalidateCache
150
+ getUserHomeDir
156
151
  });
package/dist/types.d.ts CHANGED
@@ -17,6 +17,7 @@ declare enum Interop {
17
17
  export type InteropString = `${Interop}`;
18
18
  // Based on SocketPURL_Type from socket-sdk-js
19
19
  export declare enum PURL_Type {
20
+ ALPM = "alpm",
20
21
  APK = "apk",
21
22
  BITBUCKET = "bitbucket",
22
23
  COCOAPODS = "cocoapods",
@@ -46,7 +47,8 @@ export declare enum PURL_Type {
46
47
  RPM = "rpm",
47
48
  SWID = "swid",
48
49
  SWIFT = "swift",
49
- VCS = "vcs"
50
+ VCS = "vcs",
51
+ VSCODE = "vscode"
50
52
  }
51
53
  export type PURLString = `${PURL_Type}`;
52
54
  // Alias for backward compatibility and semantic clarity
package/dist/types.js CHANGED
@@ -23,6 +23,7 @@ __export(types_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(types_exports);
25
25
  var PURL_Type = /* @__PURE__ */ ((PURL_Type2) => {
26
+ PURL_Type2["ALPM"] = "alpm";
26
27
  PURL_Type2["APK"] = "apk";
27
28
  PURL_Type2["BITBUCKET"] = "bitbucket";
28
29
  PURL_Type2["COCOAPODS"] = "cocoapods";
@@ -53,6 +54,7 @@ var PURL_Type = /* @__PURE__ */ ((PURL_Type2) => {
53
54
  PURL_Type2["SWID"] = "swid";
54
55
  PURL_Type2["SWIFT"] = "swift";
55
56
  PURL_Type2["VCS"] = "vcs";
57
+ PURL_Type2["VSCODE"] = "vscode";
56
58
  return PURL_Type2;
57
59
  })(PURL_Type || {});
58
60
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "5.0.2",
4
- "packageManager": "pnpm@10.26.0",
3
+ "version": "5.1.1",
4
+ "packageManager": "pnpm@10.26.2",
5
5
  "license": "MIT",
6
6
  "description": "Core utilities and infrastructure for Socket.dev security tools",
7
7
  "keywords": [
@@ -714,7 +714,7 @@
714
714
  "@socketregistry/is-unicode-supported": "1.0.5",
715
715
  "@socketregistry/packageurl-js": "1.3.5",
716
716
  "@socketregistry/yocto-spinner": "1.0.25",
717
- "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.0.1",
717
+ "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.1.0",
718
718
  "@types/node": "24.9.2",
719
719
  "@typescript/native-preview": "7.0.0-dev.20250920.1",
720
720
  "@vitest/coverage-v8": "4.0.3",