@socketsecurity/lib 5.27.0 → 5.28.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.
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var compression_exports = {};
32
+ __export(compression_exports, {
33
+ BROTLI_EXTS: () => BROTLI_EXTS,
34
+ GZIP_EXTS: () => GZIP_EXTS,
35
+ compressBrotli: () => compressBrotli,
36
+ compressBrotliFile: () => compressBrotliFile,
37
+ compressGzip: () => compressGzip,
38
+ compressGzipFile: () => compressGzipFile,
39
+ createBrotliCompressor: () => createBrotliCompressor,
40
+ createBrotliDecompressor: () => createBrotliDecompressor,
41
+ createGzipCompressor: () => createGzipCompressor,
42
+ createGzipDecompressor: () => createGzipDecompressor,
43
+ decompressBrotli: () => decompressBrotli,
44
+ decompressBrotliFile: () => decompressBrotliFile,
45
+ decompressGzip: () => decompressGzip,
46
+ decompressGzipFile: () => decompressGzipFile,
47
+ hasBrotliExt: () => hasBrotliExt,
48
+ hasGzipExt: () => hasGzipExt,
49
+ isBrotliCompressed: () => isBrotliCompressed,
50
+ isGzipCompressed: () => isGzipCompressed,
51
+ resolveBrotliOptions: () => resolveBrotliOptions,
52
+ resolveGzipOptions: () => resolveGzipOptions,
53
+ stripExt: () => stripExt
54
+ });
55
+ module.exports = __toCommonJS(compression_exports);
56
+ var import_node_buffer = require("node:buffer");
57
+ var import_node_fs = require("node:fs");
58
+ var import_node_path = __toESM(require("node:path"));
59
+ var import_promises = require("node:stream/promises");
60
+ var import_node_zlib = require("node:zlib");
61
+ var import_node_util = require("node:util");
62
+ var import_fs = require("./fs");
63
+ var import_primordials = require("./primordials");
64
+ const brotliCompressAsync = (0, import_node_util.promisify)(import_node_zlib.brotliCompress);
65
+ const brotliDecompressAsync = (0, import_node_util.promisify)(import_node_zlib.brotliDecompress);
66
+ const gzipAsync = (0, import_node_util.promisify)(import_node_zlib.gzip);
67
+ const gunzipAsync = (0, import_node_util.promisify)(import_node_zlib.gunzip);
68
+ function resolveBrotliOptions(options) {
69
+ const level = options?.level ?? 11;
70
+ const params = {
71
+ [import_node_zlib.constants.BROTLI_PARAM_QUALITY]: level
72
+ };
73
+ if (options?.size !== void 0 && options.size > 0) {
74
+ params[import_node_zlib.constants.BROTLI_PARAM_SIZE_HINT] = options.size;
75
+ }
76
+ return { params };
77
+ }
78
+ function resolveGzipOptions(options) {
79
+ const level = options?.level;
80
+ if (level === void 0) {
81
+ return { __proto__: null };
82
+ }
83
+ return { __proto__: null, level };
84
+ }
85
+ async function compressBrotli(input, options) {
86
+ const buf = typeof input === "string" ? import_node_buffer.Buffer.from(input, "utf8") : input;
87
+ const opts = resolveBrotliOptions(options);
88
+ if (opts.params[import_node_zlib.constants.BROTLI_PARAM_SIZE_HINT] === void 0) {
89
+ opts.params[import_node_zlib.constants.BROTLI_PARAM_SIZE_HINT] = buf.byteLength;
90
+ }
91
+ return await brotliCompressAsync(buf, opts);
92
+ }
93
+ async function decompressBrotli(input) {
94
+ return await brotliDecompressAsync(input);
95
+ }
96
+ async function compressBrotliFile(srcPath, destOrOptions, maybeOptions) {
97
+ const { destPath, options, inPlace } = resolveFileArgs(
98
+ "compressBrotliFile",
99
+ srcPath,
100
+ destOrOptions,
101
+ maybeOptions,
102
+ (p) => `${p}.br`
103
+ );
104
+ await (0, import_promises.pipeline)(
105
+ (0, import_node_fs.createReadStream)(srcPath),
106
+ (0, import_node_zlib.createBrotliCompress)(resolveBrotliOptions(options)),
107
+ (0, import_node_fs.createWriteStream)(destPath)
108
+ );
109
+ if (inPlace) {
110
+ await (0, import_fs.safeDelete)(srcPath);
111
+ }
112
+ return destPath;
113
+ }
114
+ async function decompressBrotliFile(srcPath, destOrOptions) {
115
+ const { destPath, inPlace } = resolveFileArgs(
116
+ "decompressBrotliFile",
117
+ srcPath,
118
+ destOrOptions,
119
+ void 0,
120
+ (p) => {
121
+ if (!hasBrotliExt(p)) {
122
+ throw new Error(
123
+ `decompressBrotliFile: ${p} has no .br/.brotli extension; can't infer destination`
124
+ );
125
+ }
126
+ return stripExt(p, BROTLI_EXTS);
127
+ }
128
+ );
129
+ await (0, import_promises.pipeline)(
130
+ (0, import_node_fs.createReadStream)(srcPath),
131
+ (0, import_node_zlib.createBrotliDecompress)(),
132
+ (0, import_node_fs.createWriteStream)(destPath)
133
+ );
134
+ if (inPlace) {
135
+ await (0, import_fs.safeDelete)(srcPath);
136
+ }
137
+ return destPath;
138
+ }
139
+ function createBrotliCompressor(options) {
140
+ return (0, import_node_zlib.createBrotliCompress)(resolveBrotliOptions(options));
141
+ }
142
+ function createBrotliDecompressor() {
143
+ return (0, import_node_zlib.createBrotliDecompress)();
144
+ }
145
+ async function compressGzip(input, options) {
146
+ const buf = typeof input === "string" ? import_node_buffer.Buffer.from(input, "utf8") : input;
147
+ return await gzipAsync(buf, resolveGzipOptions(options));
148
+ }
149
+ async function decompressGzip(input) {
150
+ return await gunzipAsync(input);
151
+ }
152
+ async function compressGzipFile(srcPath, destOrOptions, maybeOptions) {
153
+ const { destPath, options, inPlace } = resolveFileArgs(
154
+ "compressGzipFile",
155
+ srcPath,
156
+ destOrOptions,
157
+ maybeOptions,
158
+ (p) => `${p}.gz`
159
+ );
160
+ await (0, import_promises.pipeline)(
161
+ (0, import_node_fs.createReadStream)(srcPath),
162
+ (0, import_node_zlib.createGzip)(resolveGzipOptions(options)),
163
+ (0, import_node_fs.createWriteStream)(destPath)
164
+ );
165
+ if (inPlace) {
166
+ await (0, import_fs.safeDelete)(srcPath);
167
+ }
168
+ return destPath;
169
+ }
170
+ async function decompressGzipFile(srcPath, destOrOptions) {
171
+ const { destPath, inPlace } = resolveFileArgs(
172
+ "decompressGzipFile",
173
+ srcPath,
174
+ destOrOptions,
175
+ void 0,
176
+ (p) => {
177
+ if (!hasGzipExt(p)) {
178
+ throw new Error(
179
+ `decompressGzipFile: ${p} has no .gz/.gzip/.tgz extension; can't infer destination`
180
+ );
181
+ }
182
+ const stripped = stripExt(p, GZIP_EXTS);
183
+ return (0, import_primordials.StringPrototypeToLowerCase)(import_node_path.default.extname(p)) === ".tgz" ? `${stripped}.tar` : stripped;
184
+ }
185
+ );
186
+ await (0, import_promises.pipeline)(
187
+ (0, import_node_fs.createReadStream)(srcPath),
188
+ (0, import_node_zlib.createGunzip)(),
189
+ (0, import_node_fs.createWriteStream)(destPath)
190
+ );
191
+ if (inPlace) {
192
+ await (0, import_fs.safeDelete)(srcPath);
193
+ }
194
+ return destPath;
195
+ }
196
+ function createGzipCompressor(options) {
197
+ return (0, import_node_zlib.createGzip)(resolveGzipOptions(options));
198
+ }
199
+ function createGzipDecompressor() {
200
+ return (0, import_node_zlib.createGunzip)();
201
+ }
202
+ const BROTLI_MIN_LEN = 4;
203
+ function isBrotliCompressed(input) {
204
+ return import_node_buffer.Buffer.isBuffer(input) && input.byteLength >= BROTLI_MIN_LEN;
205
+ }
206
+ const GZIP_MAGIC_0 = 31;
207
+ const GZIP_MAGIC_1 = 139;
208
+ function isGzipCompressed(input) {
209
+ return import_node_buffer.Buffer.isBuffer(input) && input.byteLength >= 2 && input[0] === GZIP_MAGIC_0 && input[1] === GZIP_MAGIC_1;
210
+ }
211
+ const BROTLI_EXTS = /* @__PURE__ */ new Set([".br", ".brotli"]);
212
+ const GZIP_EXTS = /* @__PURE__ */ new Set([".gz", ".gzip", ".tgz"]);
213
+ function hasBrotliExt(filePath) {
214
+ return BROTLI_EXTS.has((0, import_primordials.StringPrototypeToLowerCase)(import_node_path.default.extname(filePath)));
215
+ }
216
+ function hasGzipExt(filePath) {
217
+ return GZIP_EXTS.has((0, import_primordials.StringPrototypeToLowerCase)(import_node_path.default.extname(filePath)));
218
+ }
219
+ function stripExt(filePath, exts) {
220
+ const ext = import_node_path.default.extname(filePath);
221
+ if (!exts.has((0, import_primordials.StringPrototypeToLowerCase)(ext))) {
222
+ return filePath;
223
+ }
224
+ return filePath.slice(0, -ext.length);
225
+ }
226
+ function resolveFileArgs(fnName, srcPath, destOrOptions, maybeOptions, computeInPlaceDest) {
227
+ if (typeof destOrOptions === "string") {
228
+ if (srcPath === destOrOptions) {
229
+ throw new Error(
230
+ `${fnName}: srcPath and destPath must differ; got ${srcPath}`
231
+ );
232
+ }
233
+ return Object.freeze({
234
+ __proto__: null,
235
+ destPath: destOrOptions,
236
+ options: maybeOptions,
237
+ inPlace: false
238
+ });
239
+ }
240
+ if (destOrOptions?.inPlace) {
241
+ return Object.freeze({
242
+ __proto__: null,
243
+ destPath: computeInPlaceDest(srcPath),
244
+ options: destOrOptions,
245
+ inPlace: true
246
+ });
247
+ }
248
+ throw new Error(
249
+ `${fnName}: missing destPath; pass an explicit destination or { inPlace: true }`
250
+ );
251
+ }
252
+ // Annotate the CommonJS export names for ESM import in node:
253
+ 0 && (module.exports = {
254
+ BROTLI_EXTS,
255
+ GZIP_EXTS,
256
+ compressBrotli,
257
+ compressBrotliFile,
258
+ compressGzip,
259
+ compressGzipFile,
260
+ createBrotliCompressor,
261
+ createBrotliDecompressor,
262
+ createGzipCompressor,
263
+ createGzipDecompressor,
264
+ decompressBrotli,
265
+ decompressBrotliFile,
266
+ decompressGzip,
267
+ decompressGzipFile,
268
+ hasBrotliExt,
269
+ hasGzipExt,
270
+ isBrotliCompressed,
271
+ isGzipCompressed,
272
+ resolveBrotliOptions,
273
+ resolveGzipOptions,
274
+ stripExt
275
+ });
@@ -77,7 +77,7 @@ const SOCKET_FIREWALL_APP_NAME = "sfw";
77
77
  const SOCKET_REGISTRY_APP_NAME = "registry";
78
78
  const SOCKET_APP_PREFIX = "_";
79
79
  const SOCKET_LIB_NAME = "@socketsecurity/lib";
80
- const SOCKET_LIB_VERSION = "5.27.0";
80
+ const SOCKET_LIB_VERSION = "5.28.0";
81
81
  const SOCKET_LIB_URL = "https://github.com/SocketDev/socket-lib";
82
82
  const SOCKET_LIB_USER_AGENT = `socketsecurity-lib/${SOCKET_LIB_VERSION} (${SOCKET_LIB_URL})`;
83
83
  const SOCKET_IPC_HANDSHAKE = "SOCKET_IPC_HANDSHAKE";
@@ -53,6 +53,36 @@ export interface EnsurePackageInstallOptions {
53
53
  * - An explicit `{ type: 'integrity' | 'checksum', value }` object.
54
54
  */
55
55
  hash?: HashSpec | undefined;
56
+ /**
57
+ * Override the install root passed to Arborist. By default, the
58
+ * install root is `~/.socket/_dlx/<cacheKey>/` (or
59
+ * `SOCKET_DLX_DIR/<cacheKey>/`) — keyed by spec so multiple specs
60
+ * share a parent dir without colliding. When `installRoot` is set,
61
+ * the install root is the value verbatim — no cacheKey subdirectory.
62
+ *
63
+ * In both cases the package itself lands at
64
+ * `<installRoot>/node_modules/<packageName>/` with transitive deps as
65
+ * siblings under the same `node_modules/` directory. That layout is a
66
+ * fixed property of Arborist; this option only controls the parent.
67
+ *
68
+ * That means **the caller is responsible for keeping per-spec
69
+ * installs separated** — calling twice with the same `installRoot`
70
+ * but different specs (e.g. `ink@7` and `ink@8`) overwrites the
71
+ * earlier install. Either pass a different `installRoot` per spec or
72
+ * pass `force: true` to accept the overwrite.
73
+ *
74
+ * Pass a sentinel name (e.g. `_dlx`, `_pkg`, `vendor`) — never one
75
+ * that ends in `node_modules`, since that turns the install root
76
+ * into something parent-walking resolvers, IDE indexers, and pnpm
77
+ * hoisting will mistake for a workspace `node_modules/`.
78
+ *
79
+ * Use cases:
80
+ * - Build pipelines that want the install gitignored alongside their
81
+ * own outputs and walkable by tools that resolve through
82
+ * `node_modules` (e.g. esbuild's `nodePaths`).
83
+ * - Tests that need a deterministic, easily-cleaned install path.
84
+ */
85
+ installRoot?: string | undefined;
56
86
  /**
57
87
  * Vendored `package-lock.json` to drive a reproducible install. Accepts
58
88
  * a filesystem path (sniffed) or raw JSON content (sniffed via leading
@@ -168,6 +168,7 @@ async function downloadPackage(options) {
168
168
  binaryName,
169
169
  force: userForce,
170
170
  hash,
171
+ installRoot,
171
172
  lockfile,
172
173
  package: packageSpec,
173
174
  yes
@@ -183,7 +184,7 @@ async function downloadPackage(options) {
183
184
  packageName,
184
185
  fullPackageSpec,
185
186
  force,
186
- { hash, lockfile }
187
+ { hash, installRoot, lockfile }
187
188
  );
188
189
  const binaryPath = findBinaryPath(packageDir, packageName, binaryName);
189
190
  makePackageBinsExecutable(packageDir, packageName);
@@ -196,8 +197,9 @@ async function downloadPackage(options) {
196
197
  async function ensurePackageInstalled(packageName, packageSpec, force, install) {
197
198
  const fs = /* @__PURE__ */ getFs();
198
199
  const path = /* @__PURE__ */ getPath();
199
- const cacheKey = (0, import_cache.generateCacheKey)(packageSpec);
200
- const packageDir = (0, import_normalize.normalizePath)(path.join((0, import_socket2.getSocketDlxDir)(), cacheKey));
200
+ const packageDir = (0, import_normalize.normalizePath)(
201
+ install?.installRoot ?? path.join((0, import_socket2.getSocketDlxDir)(), (0, import_cache.generateCacheKey)(packageSpec))
202
+ );
201
203
  const installedDir = (0, import_normalize.normalizePath)(
202
204
  path.join(packageDir, "node_modules", packageName)
203
205
  );
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "5.27.0",
3
+ "version": "5.28.0",
4
4
  "packageManager": "pnpm@11.0.6+sha512.97f906e1da2bedac3df83cadae04b4753a130092dd49d55cd36825ad3e623e9df3f97754f8f259e699172a360fac569acf2f908e7732bdae3eddb2dcf7e121fd",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",
8
8
  "provenance": true
9
9
  },
10
+ "bin": {
11
+ "socket-lib": "./dist/bin/socket-lib.js"
12
+ },
10
13
  "description": "Core utilities and infrastructure for Socket.dev security tools",
11
14
  "keywords": [
12
15
  "Socket.dev",
@@ -127,6 +130,18 @@
127
130
  "types": "./dist/bin.d.ts",
128
131
  "default": "./dist/bin.js"
129
132
  },
133
+ "./bin/check": {
134
+ "types": "./dist/bin/check.d.ts",
135
+ "default": "./dist/bin/check.js"
136
+ },
137
+ "./bin/check-primordials": {
138
+ "types": "./dist/bin/check-primordials.d.ts",
139
+ "default": "./dist/bin/check-primordials.js"
140
+ },
141
+ "./bin/socket-lib": {
142
+ "types": "./dist/bin/socket-lib.d.ts",
143
+ "default": "./dist/bin/socket-lib.js"
144
+ },
130
145
  "./cacache": {
131
146
  "types": "./dist/cacache.d.ts",
132
147
  "default": "./dist/cacache.js"
@@ -135,10 +150,18 @@
135
150
  "types": "./dist/cache-with-ttl.d.ts",
136
151
  "default": "./dist/cache-with-ttl.js"
137
152
  },
153
+ "./checks/primordials": {
154
+ "types": "./dist/checks/primordials.d.ts",
155
+ "default": "./dist/checks/primordials.js"
156
+ },
138
157
  "./colors": {
139
158
  "types": "./dist/colors.d.ts",
140
159
  "default": "./dist/colors.js"
141
160
  },
161
+ "./compression": {
162
+ "types": "./dist/compression.d.ts",
163
+ "default": "./dist/compression.js"
164
+ },
142
165
  "./constants/agents": {
143
166
  "types": "./dist/constants/agents.d.ts",
144
167
  "default": "./dist/constants/agents.js"