@socketsecurity/lib 5.26.1 → 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.
Files changed (59) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +1 -1
  3. package/dist/bin/check-primordials.d.ts +18 -0
  4. package/dist/bin/check-primordials.js +229 -0
  5. package/dist/bin/check.d.ts +15 -0
  6. package/dist/bin/check.js +73 -0
  7. package/dist/bin/socket-lib.d.ts +17 -0
  8. package/dist/bin/socket-lib.js +64 -0
  9. package/dist/checks/primordials.d.ts +110 -0
  10. package/dist/checks/primordials.js +244 -0
  11. package/dist/compression.d.ts +218 -0
  12. package/dist/compression.js +275 -0
  13. package/dist/constants/socket.js +1 -1
  14. package/dist/crypto.js +3 -10
  15. package/dist/dlx/package.d.ts +30 -0
  16. package/dist/dlx/package.js +5 -3
  17. package/dist/external/adm-zip.js +2 -2
  18. package/dist/external/tar-fs.js +2 -2
  19. package/dist/fs.js +31 -45
  20. package/dist/node/async-hooks.d.ts +6 -0
  21. package/dist/node/async-hooks.js +34 -0
  22. package/dist/node/child-process.d.ts +11 -0
  23. package/dist/node/child-process.js +34 -0
  24. package/dist/node/crypto.d.ts +6 -0
  25. package/dist/node/crypto.js +34 -0
  26. package/dist/node/events.d.ts +6 -0
  27. package/dist/node/events.js +34 -0
  28. package/dist/node/fs-promises.d.ts +6 -0
  29. package/dist/node/fs-promises.js +34 -0
  30. package/dist/node/fs.d.ts +14 -0
  31. package/dist/node/fs.js +34 -0
  32. package/dist/node/http.d.ts +6 -0
  33. package/dist/node/http.js +34 -0
  34. package/dist/node/https.d.ts +6 -0
  35. package/dist/node/https.js +34 -0
  36. package/dist/node/os.d.ts +6 -0
  37. package/dist/node/os.js +34 -0
  38. package/dist/node/path.d.ts +6 -0
  39. package/dist/node/path.js +34 -0
  40. package/dist/node/timers-promises.d.ts +6 -0
  41. package/dist/node/timers-promises.js +34 -0
  42. package/dist/node/url.d.ts +6 -0
  43. package/dist/node/url.js +34 -0
  44. package/dist/node/util.d.ts +6 -0
  45. package/dist/node/util.js +34 -0
  46. package/dist/primordials.d.ts +76 -2
  47. package/dist/primordials.js +294 -23
  48. package/dist/sea/util.d.ts +43 -0
  49. package/dist/{sea.js → sea/util.js} +7 -7
  50. package/dist/smol/primordial.d.ts +80 -0
  51. package/dist/smol/primordial.js +46 -0
  52. package/dist/smol/util.d.ts +87 -0
  53. package/dist/smol/util.js +59 -0
  54. package/dist/smol/versions.d.ts +46 -0
  55. package/dist/smol/versions.js +46 -0
  56. package/dist/spawn.js +13 -28
  57. package/dist/versions.js +27 -22
  58. package/package.json +102 -9
  59. package/dist/sea.d.ts +0 -30
@@ -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.26.1";
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";
package/dist/crypto.js CHANGED
@@ -24,20 +24,13 @@ __export(crypto_exports, {
24
24
  hash: () => hash
25
25
  });
26
26
  module.exports = __toCommonJS(crypto_exports);
27
- let _crypto;
27
+ var import_crypto = require("./node/crypto");
28
28
  let _hash;
29
29
  let _hashProbed = false;
30
30
  // @__NO_SIDE_EFFECTS__
31
- function getCrypto() {
32
- if (_crypto === void 0) {
33
- _crypto = require("node:crypto");
34
- }
35
- return _crypto;
36
- }
37
- // @__NO_SIDE_EFFECTS__
38
31
  function getNativeHash() {
39
32
  if (!_hashProbed) {
40
- const fn = (/* @__PURE__ */ getCrypto()).hash;
33
+ const fn = (0, import_crypto.getNodeCrypto)().hash;
41
34
  if (typeof fn === "function") {
42
35
  _hash = fn;
43
36
  }
@@ -51,7 +44,7 @@ function hash(algorithm, data, outputEncoding) {
51
44
  if (native !== void 0) {
52
45
  return native(algorithm, data, outputEncoding);
53
46
  }
54
- return (/* @__PURE__ */ getCrypto()).createHash(algorithm).update(data).digest(outputEncoding);
47
+ return (0, import_crypto.getNodeCrypto)().createHash(algorithm).update(data).digest(outputEncoding);
55
48
  }
56
49
  // Annotate the CommonJS export names for ESM import in node:
57
50
  0 && (module.exports = {
@@ -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
  );
@@ -1,4 +1,4 @@
1
- const { ArrayCtor: _p_ArrayCtor, ArrayFrom: _p_ArrayFrom, ArrayIsArray: _p_ArrayIsArray, ArrayPrototypeFindLast: _p_ArrayPrototypeFindLast, BufferAlloc: _p_BufferAlloc, BufferFrom: _p_BufferFrom, BufferIsBuffer: _p_BufferIsBuffer, DateCtor: _p_DateCtor, ErrorCtor: _p_ErrorCtor, JSONStringify: _p_JSONStringify, MathMax: _p_MathMax, MathRandom: _p_MathRandom, ObjectAssign: _p_ObjectAssign, ObjectCreate: _p_ObjectCreate, ObjectKeys: _p_ObjectKeys, PromiseCtor: _p_PromiseCtor, SetCtor: _p_SetCtor, TypeErrorCtor: _p_TypeErrorCtor, Uint32ArrayCtor: _p_Uint32ArrayCtor } = require('../primordials.js')
1
+ const { ArrayCtor: _p_ArrayCtor, ArrayFrom: _p_ArrayFrom, ArrayIsArray: _p_ArrayIsArray, ArrayPrototypeFindLast: _p_ArrayPrototypeFindLast, BufferAlloc: _p_BufferAlloc, BufferFrom: _p_BufferFrom, BufferIsBuffer: _p_BufferIsBuffer, DateCtor: _p_DateCtor, ErrorCtor: _p_ErrorCtor, JSONStringify: _p_JSONStringify, MathImul: _p_MathImul, MathMax: _p_MathMax, MathRandom: _p_MathRandom, ObjectAssign: _p_ObjectAssign, ObjectCreate: _p_ObjectCreate, ObjectKeys: _p_ObjectKeys, PromiseCtor: _p_PromiseCtor, SetCtor: _p_SetCtor, TypeErrorCtor: _p_TypeErrorCtor, Uint32ArrayCtor: _p_Uint32ArrayCtor } = require('../primordials.js')
2
2
  "use strict";
3
3
  /**
4
4
  * Bundled from adm-zip
@@ -1097,7 +1097,7 @@ var require_zipcrypto = __commonJS({
1097
1097
  }
1098
1098
  return crc >>> 0;
1099
1099
  });
1100
- var uMul = /* @__PURE__ */ __name((a, b) => Math.imul(a, b) >>> 0, "uMul");
1100
+ var uMul = /* @__PURE__ */ __name((a, b) => _p_MathImul(a, b) >>> 0, "uMul");
1101
1101
  var crc32update = /* @__PURE__ */ __name((pCrc32, bval) => {
1102
1102
  return crctable[(pCrc32 ^ bval) & 255] ^ pCrc32 >>> 8;
1103
1103
  }, "crc32update");
@@ -1,4 +1,4 @@
1
- const { ArrayCtor: _p_ArrayCtor, ArrayIsArray: _p_ArrayIsArray, BufferAlloc: _p_BufferAlloc, BufferAllocUnsafe: _p_BufferAllocUnsafe, BufferAllocUnsafeSlow: _p_BufferAllocUnsafeSlow, BufferByteLength: _p_BufferByteLength, BufferConcat: _p_BufferConcat, BufferFrom: _p_BufferFrom, BufferIsBuffer: _p_BufferIsBuffer, BufferIsEncoding: _p_BufferIsEncoding, DateCtor: _p_DateCtor, ErrorCtor: _p_ErrorCtor, MathFloor: _p_MathFloor, MathMax: _p_MathMax, MathMin: _p_MathMin, MathPow: _p_MathPow, ObjectDefineProperty: _p_ObjectDefineProperty, ObjectKeys: _p_ObjectKeys, PromiseCtor: _p_PromiseCtor, PromiseResolve: _p_PromiseResolve, StringFromCharCode: _p_StringFromCharCode, StringFromCodePoint: _p_StringFromCodePoint, StringPrototypeStartsWith: _p_StringPrototypeStartsWith, TypeErrorCtor: _p_TypeErrorCtor } = require('../primordials.js')
1
+ const { ArrayCtor: _p_ArrayCtor, ArrayIsArray: _p_ArrayIsArray, BufferAlloc: _p_BufferAlloc, BufferAllocUnsafe: _p_BufferAllocUnsafe, BufferAllocUnsafeSlow: _p_BufferAllocUnsafeSlow, BufferByteLength: _p_BufferByteLength, BufferConcat: _p_BufferConcat, BufferFrom: _p_BufferFrom, BufferIsBuffer: _p_BufferIsBuffer, BufferIsEncoding: _p_BufferIsEncoding, DateCtor: _p_DateCtor, ErrorCtor: _p_ErrorCtor, MathFloor: _p_MathFloor, MathLog: _p_MathLog, MathMax: _p_MathMax, MathMin: _p_MathMin, MathPow: _p_MathPow, ObjectDefineProperty: _p_ObjectDefineProperty, ObjectKeys: _p_ObjectKeys, PromiseCtor: _p_PromiseCtor, PromiseResolve: _p_PromiseResolve, StringFromCharCode: _p_StringFromCharCode, StringFromCodePoint: _p_StringFromCodePoint, StringPrototypeStartsWith: _p_StringPrototypeStartsWith, TypeErrorCtor: _p_TypeErrorCtor } = require('../primordials.js')
2
2
  "use strict";
3
3
  /**
4
4
  * Bundled from tar-fs
@@ -1860,7 +1860,7 @@ var require_headers = __commonJS({
1860
1860
  __name(decodeStr, "decodeStr");
1861
1861
  function addLength(str) {
1862
1862
  const len = b4a.byteLength(str);
1863
- let digits = _p_MathFloor(Math.log(len) / Math.log(10)) + 1;
1863
+ let digits = _p_MathFloor(_p_MathLog(len) / _p_MathLog(10)) + 1;
1864
1864
  if (len + digits >= _p_MathPow(10, digits)) digits++;
1865
1865
  return len + digits + str;
1866
1866
  }
package/dist/fs.js CHANGED
@@ -67,6 +67,8 @@ var import_process = require("./constants/process");
67
67
  var import_errors = require("./errors");
68
68
  var import_globs = require("./globs");
69
69
  var import_parse = require("./json/parse");
70
+ var import_fs = require("./node/fs");
71
+ var import_path = require("./node/path");
70
72
  var import_objects = require("./objects");
71
73
  var import_normalize = require("./paths/normalize");
72
74
  var import_rewire = require("./paths/rewire");
@@ -85,11 +87,9 @@ const defaultRemoveOptions = (0, import_objects.objectFreeze)({
85
87
  });
86
88
  let _del;
87
89
  let _cachedAllowedDirs;
88
- let _fs;
89
- let _path;
90
90
  function getAllowedDirectories() {
91
91
  if (_cachedAllowedDirs === void 0) {
92
- const path = /* @__PURE__ */ getPath();
92
+ const path = (0, import_path.getNodePath)();
93
93
  _cachedAllowedDirs = [
94
94
  path.resolve((0, import_socket.getOsTmpDir)()),
95
95
  path.resolve((0, import_socket.getSocketCacacheDir)()),
@@ -106,27 +106,13 @@ function getDel() {
106
106
  return _del;
107
107
  }
108
108
  // @__NO_SIDE_EFFECTS__
109
- function getFs() {
110
- if (_fs === void 0) {
111
- _fs = require("node:fs");
112
- }
113
- return _fs;
114
- }
115
- // @__NO_SIDE_EFFECTS__
116
- function getPath() {
117
- if (_path === void 0) {
118
- _path = require("node:path");
119
- }
120
- return _path;
121
- }
122
- // @__NO_SIDE_EFFECTS__
123
109
  function innerReadDirNames(dirents, dirname, options) {
124
110
  const {
125
111
  ignore,
126
112
  includeEmpty = true,
127
113
  sort = true
128
114
  } = { __proto__: null, ...options };
129
- const path = /* @__PURE__ */ getPath();
115
+ const path = (0, import_path.getNodePath)();
130
116
  const names = dirents.filter(
131
117
  (d) => d.isDirectory() && (includeEmpty || !/* @__PURE__ */ isDirEmptySync(path.join(dirname || d.parentPath, d.name), {
132
118
  ignore
@@ -156,8 +142,8 @@ async function findUp(name, options) {
156
142
  if (onlyFiles) {
157
143
  onlyDirectories = false;
158
144
  }
159
- const fs = /* @__PURE__ */ getFs();
160
- const path = /* @__PURE__ */ getPath();
145
+ const fs = (0, import_fs.getNodeFs)();
146
+ const path = (0, import_path.getNodePath)();
161
147
  let dir = path.resolve(cwd);
162
148
  const { root } = path.parse(dir);
163
149
  const names = (0, import_arrays.isArray)(name) ? name : [name];
@@ -201,8 +187,8 @@ function findUpSync(name, options) {
201
187
  if (onlyFiles) {
202
188
  onlyDirectories = false;
203
189
  }
204
- const fs = /* @__PURE__ */ getFs();
205
- const path = /* @__PURE__ */ getPath();
190
+ const fs = (0, import_fs.getNodeFs)();
191
+ const path = (0, import_path.getNodePath)();
206
192
  let dir = path.resolve(cwd);
207
193
  const { root } = path.parse(dir);
208
194
  const stopDir = stopAt ? path.resolve(stopAt) : void 0;
@@ -257,7 +243,7 @@ function isDirEmptySync(dirname, options) {
257
243
  __proto__: null,
258
244
  ...options
259
245
  };
260
- const fs = /* @__PURE__ */ getFs();
246
+ const fs = (0, import_fs.getNodeFs)();
261
247
  try {
262
248
  const files = fs.readdirSync(dirname);
263
249
  const { length } = files;
@@ -288,7 +274,7 @@ function isDirSync(filepath) {
288
274
  }
289
275
  // @__NO_SIDE_EFFECTS__
290
276
  function isSymLinkSync(filepath) {
291
- const fs = /* @__PURE__ */ getFs();
277
+ const fs = (0, import_fs.getNodeFs)();
292
278
  try {
293
279
  return fs.lstatSync(filepath).isSymbolicLink();
294
280
  } catch {
@@ -368,7 +354,7 @@ function normalizeEncodingSlow(enc) {
368
354
  }
369
355
  // @__NO_SIDE_EFFECTS__
370
356
  async function readDirNames(dirname, options) {
371
- const fs = /* @__PURE__ */ getFs();
357
+ const fs = (0, import_fs.getNodeFs)();
372
358
  try {
373
359
  return /* @__PURE__ */ innerReadDirNames(
374
360
  await fs.promises.readdir(dirname, {
@@ -385,7 +371,7 @@ async function readDirNames(dirname, options) {
385
371
  }
386
372
  // @__NO_SIDE_EFFECTS__
387
373
  function readDirNamesSync(dirname, options) {
388
- const fs = /* @__PURE__ */ getFs();
374
+ const fs = (0, import_fs.getNodeFs)();
389
375
  try {
390
376
  return /* @__PURE__ */ innerReadDirNames(
391
377
  fs.readdirSync(dirname, {
@@ -403,7 +389,7 @@ function readDirNamesSync(dirname, options) {
403
389
  // @__NO_SIDE_EFFECTS__
404
390
  async function readFileBinary(filepath, options) {
405
391
  const opts = typeof options === "string" ? { encoding: options } : options;
406
- const fs = /* @__PURE__ */ getFs();
392
+ const fs = (0, import_fs.getNodeFs)();
407
393
  return await fs.promises.readFile(filepath, {
408
394
  signal: abortSignal,
409
395
  ...opts,
@@ -413,7 +399,7 @@ async function readFileBinary(filepath, options) {
413
399
  // @__NO_SIDE_EFFECTS__
414
400
  function readFileBinarySync(filepath, options) {
415
401
  const opts = typeof options === "string" ? { encoding: options } : options;
416
- const fs = /* @__PURE__ */ getFs();
402
+ const fs = (0, import_fs.getNodeFs)();
417
403
  return fs.readFileSync(filepath, {
418
404
  ...opts,
419
405
  encoding: null
@@ -422,7 +408,7 @@ function readFileBinarySync(filepath, options) {
422
408
  // @__NO_SIDE_EFFECTS__
423
409
  async function readFileUtf8(filepath, options) {
424
410
  const opts = typeof options === "string" ? { encoding: options } : options;
425
- const fs = /* @__PURE__ */ getFs();
411
+ const fs = (0, import_fs.getNodeFs)();
426
412
  return await fs.promises.readFile(filepath, {
427
413
  signal: abortSignal,
428
414
  ...opts,
@@ -432,7 +418,7 @@ async function readFileUtf8(filepath, options) {
432
418
  // @__NO_SIDE_EFFECTS__
433
419
  function readFileUtf8Sync(filepath, options) {
434
420
  const opts = typeof options === "string" ? { encoding: options } : options;
435
- const fs = /* @__PURE__ */ getFs();
421
+ const fs = (0, import_fs.getNodeFs)();
436
422
  return fs.readFileSync(filepath, {
437
423
  ...opts,
438
424
  encoding: "utf8"
@@ -446,7 +432,7 @@ async function readJson(filepath, options) {
446
432
  ...opts
447
433
  };
448
434
  const shouldThrow = throws === void 0 || !!throws;
449
- const fs = /* @__PURE__ */ getFs();
435
+ const fs = (0, import_fs.getNodeFs)();
450
436
  let content = "";
451
437
  try {
452
438
  content = await fs.promises.readFile(filepath, {
@@ -489,7 +475,7 @@ function readJsonSync(filepath, options) {
489
475
  ...opts
490
476
  };
491
477
  const shouldThrow = throws === void 0 || !!throws;
492
- const fs = /* @__PURE__ */ getFs();
478
+ const fs = (0, import_fs.getNodeFs)();
493
479
  let content = "";
494
480
  try {
495
481
  content = fs.readFileSync(filepath, {
@@ -529,7 +515,7 @@ async function safeDelete(filepath, options) {
529
515
  const patterns = (0, import_arrays.isArray)(filepath) ? filepath.map(import_normalize.pathLikeToString) : [(0, import_normalize.pathLikeToString)(filepath)];
530
516
  let shouldForce = opts.force !== false;
531
517
  if (!shouldForce && patterns.length > 0) {
532
- const path = /* @__PURE__ */ getPath();
518
+ const path = (0, import_path.getNodePath)();
533
519
  const allowedDirs = getAllowedDirectories();
534
520
  const allInAllowedDirs = patterns.every((pattern) => {
535
521
  const resolvedPath = path.resolve(pattern);
@@ -571,7 +557,7 @@ function safeDeleteSync(filepath, options) {
571
557
  const patterns = (0, import_arrays.isArray)(filepath) ? filepath.map(import_normalize.pathLikeToString) : [(0, import_normalize.pathLikeToString)(filepath)];
572
558
  let shouldForce = opts.force !== false;
573
559
  if (!shouldForce && patterns.length > 0) {
574
- const path = /* @__PURE__ */ getPath();
560
+ const path = (0, import_path.getNodePath)();
575
561
  const allowedDirs = getAllowedDirectories();
576
562
  const allInAllowedDirs = patterns.every((pattern) => {
577
563
  const resolvedPath = path.resolve(pattern);
@@ -621,7 +607,7 @@ function safeDeleteSync(filepath, options) {
621
607
  }
622
608
  }
623
609
  async function safeMkdir(path, options) {
624
- const fs = /* @__PURE__ */ getFs();
610
+ const fs = (0, import_fs.getNodeFs)();
625
611
  const opts = { __proto__: null, recursive: true, ...options };
626
612
  try {
627
613
  await fs.promises.mkdir(path, opts);
@@ -632,7 +618,7 @@ async function safeMkdir(path, options) {
632
618
  }
633
619
  }
634
620
  function safeMkdirSync(path, options) {
635
- const fs = /* @__PURE__ */ getFs();
621
+ const fs = (0, import_fs.getNodeFs)();
636
622
  const opts = { __proto__: null, recursive: true, ...options };
637
623
  try {
638
624
  fs.mkdirSync(path, opts);
@@ -649,7 +635,7 @@ async function safeReadFile(filepath, options) {
649
635
  const readOpts = { __proto__: null, ...rawReadOpts };
650
636
  const shouldReturnBuffer = readOpts.encoding === null;
651
637
  const encoding = shouldReturnBuffer ? null : /* @__PURE__ */ normalizeEncoding(readOpts.encoding);
652
- const fs = /* @__PURE__ */ getFs();
638
+ const fs = (0, import_fs.getNodeFs)();
653
639
  try {
654
640
  return await fs.promises.readFile(filepath, {
655
641
  __proto__: null,
@@ -674,7 +660,7 @@ function safeReadFileSync(filepath, options) {
674
660
  const readOpts = { __proto__: null, ...rawReadOpts };
675
661
  const shouldReturnBuffer = readOpts.encoding === null;
676
662
  const encoding = shouldReturnBuffer ? null : /* @__PURE__ */ normalizeEncoding(readOpts.encoding);
677
- const fs = /* @__PURE__ */ getFs();
663
+ const fs = (0, import_fs.getNodeFs)();
678
664
  try {
679
665
  return fs.readFileSync(filepath, {
680
666
  __proto__: null,
@@ -693,7 +679,7 @@ function safeReadFileSync(filepath, options) {
693
679
  }
694
680
  // @__NO_SIDE_EFFECTS__
695
681
  async function safeStats(filepath) {
696
- const fs = /* @__PURE__ */ getFs();
682
+ const fs = (0, import_fs.getNodeFs)();
697
683
  try {
698
684
  return await fs.promises.stat(filepath);
699
685
  } catch {
@@ -702,7 +688,7 @@ async function safeStats(filepath) {
702
688
  }
703
689
  // @__NO_SIDE_EFFECTS__
704
690
  function safeStatsSync(filepath) {
705
- const fs = /* @__PURE__ */ getFs();
691
+ const fs = (0, import_fs.getNodeFs)();
706
692
  try {
707
693
  return fs.statSync(filepath, {
708
694
  __proto__: null,
@@ -714,8 +700,8 @@ function safeStatsSync(filepath) {
714
700
  }
715
701
  // @__NO_SIDE_EFFECTS__
716
702
  function uniqueSync(filepath) {
717
- const fs = /* @__PURE__ */ getFs();
718
- const path = /* @__PURE__ */ getPath();
703
+ const fs = (0, import_fs.getNodeFs)();
704
+ const path = (0, import_path.getNodePath)();
719
705
  const filepathStr = String(filepath);
720
706
  if (!fs.existsSync(filepathStr)) {
721
707
  return (0, import_normalize.normalizePath)(filepathStr);
@@ -733,7 +719,7 @@ function uniqueSync(filepath) {
733
719
  }
734
720
  // @__NO_SIDE_EFFECTS__
735
721
  function validateFiles(filepaths) {
736
- const fs = /* @__PURE__ */ getFs();
722
+ const fs = (0, import_fs.getNodeFs)();
737
723
  const validPaths = [];
738
724
  const invalidPaths = [];
739
725
  const { R_OK } = fs.constants;
@@ -753,7 +739,7 @@ async function writeJson(filepath, jsonContent, options) {
753
739
  __proto__: null,
754
740
  ...opts
755
741
  };
756
- const fs = /* @__PURE__ */ getFs();
742
+ const fs = (0, import_fs.getNodeFs)();
757
743
  const jsonString = /* @__PURE__ */ stringify(
758
744
  jsonContent,
759
745
  EOL || "\n",
@@ -773,7 +759,7 @@ function writeJsonSync(filepath, jsonContent, options) {
773
759
  __proto__: null,
774
760
  ...opts
775
761
  };
776
- const fs = /* @__PURE__ */ getFs();
762
+ const fs = (0, import_fs.getNodeFs)();
777
763
  const jsonString = /* @__PURE__ */ stringify(
778
764
  jsonContent,
779
765
  EOL || "\n",