@socketsecurity/lib 5.26.0 → 5.27.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 +371 -1185
- package/README.md +1 -1
- package/dist/abort.js +7 -6
- package/dist/agent.js +16 -15
- package/dist/ansi.js +3 -2
- package/dist/archives.js +18 -17
- package/dist/argv/flags.js +29 -28
- package/dist/argv/parse.js +4 -3
- package/dist/arrays.js +3 -2
- package/dist/bin.js +12 -11
- package/dist/cacache.js +16 -11
- package/dist/cache-with-ttl.js +26 -21
- package/dist/colors.js +2 -1
- package/dist/constants/licenses.js +2 -1
- package/dist/constants/lifecycle-script-names.js +2 -1
- package/dist/constants/maintained-node-versions.js +2 -1
- package/dist/constants/node.js +4 -3
- package/dist/constants/package-default-socket-categories.js +2 -1
- package/dist/constants/packages.js +4 -3
- package/dist/constants/socket.js +1 -1
- package/dist/cover/code.js +9 -8
- package/dist/cover/formatters.js +12 -11
- package/dist/cover/type.js +5 -4
- package/dist/crypto.d.ts +36 -0
- package/dist/{effects/ultra.js → crypto.js} +26 -37
- package/dist/debug.js +12 -15
- package/dist/dlx/arborist.js +10 -9
- package/dist/dlx/binary.js +27 -24
- package/dist/dlx/cache.js +2 -10
- package/dist/dlx/detect.js +6 -5
- package/dist/dlx/integrity.js +13 -11
- package/dist/dlx/lockfile.js +7 -6
- package/dist/dlx/manifest.js +6 -5
- package/dist/dlx/package.js +17 -16
- package/dist/dlx/packages.js +6 -5
- package/dist/dlx/paths.d.ts +1 -1
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +4 -3
- package/dist/effects/shimmer-keyframes.d.ts +62 -0
- package/dist/effects/shimmer-keyframes.js +55 -0
- package/dist/effects/shimmer-terminal.d.ts +66 -0
- package/dist/effects/shimmer-terminal.js +57 -0
- package/dist/effects/shimmer.d.ts +293 -0
- package/dist/effects/shimmer.js +180 -0
- package/dist/env/rewire.js +4 -3
- package/dist/env.js +5 -4
- package/dist/errors.js +1 -1
- package/dist/external/@npmcli/package-json/lib/read-package.js +10 -10
- package/dist/external/@npmcli/package-json.js +372 -372
- package/dist/external/@npmcli/promise-spawn.js +24 -24
- package/dist/external/@socketregistry/packageurl-js.js +19 -18
- package/dist/external/@socketregistry/yocto-spinner.js +4 -3
- package/dist/external/@yarnpkg/extensions.js +2 -1
- package/dist/external/adm-zip.js +71 -71
- package/dist/external/debug.js +22 -22
- package/dist/external/external-pack.js +45 -45
- package/dist/external/fast-sort.js +5 -5
- package/dist/external/libnpmexec.js +4 -3
- package/dist/external/npm-pack.js +369 -369
- package/dist/external/p-map.js +9 -9
- package/dist/external/pico-pack.js +190 -190
- package/dist/external/pony-cause.js +2 -1
- package/dist/external/spdx-pack.js +11 -10
- package/dist/external/tar-fs.js +58 -58
- package/dist/external/which.js +13 -13
- package/dist/external/yargs-parser.js +71 -71
- package/dist/fs.js +50 -68
- package/dist/git.js +14 -13
- package/dist/github.d.ts +34 -0
- package/dist/github.js +248 -23
- package/dist/globs.d.ts +20 -0
- package/dist/globs.js +134 -25
- package/dist/http-request.d.ts +4 -3
- package/dist/http-request.js +39 -32
- package/dist/ipc-cli.js +2 -1
- package/dist/ipc.js +5 -4
- package/dist/json/edit.js +4 -3
- package/dist/json/format.js +3 -2
- package/dist/json/parse.js +7 -6
- package/dist/links.js +2 -1
- package/dist/logger.js +21 -14
- package/dist/memoization.js +16 -15
- package/dist/node/async-hooks.d.ts +6 -0
- package/dist/node/async-hooks.js +34 -0
- package/dist/node/child-process.d.ts +11 -0
- package/dist/node/child-process.js +34 -0
- package/dist/node/crypto.d.ts +6 -0
- package/dist/node/crypto.js +34 -0
- package/dist/node/events.d.ts +6 -0
- package/dist/node/events.js +34 -0
- package/dist/node/fs-promises.d.ts +6 -0
- package/dist/node/fs-promises.js +34 -0
- package/dist/node/fs.d.ts +14 -0
- package/dist/node/fs.js +34 -0
- package/dist/node/http.d.ts +6 -0
- package/dist/node/http.js +34 -0
- package/dist/node/https.d.ts +6 -0
- package/dist/node/https.js +34 -0
- package/dist/node/os.d.ts +6 -0
- package/dist/node/os.js +34 -0
- package/dist/node/path.d.ts +6 -0
- package/dist/node/path.js +34 -0
- package/dist/node/timers-promises.d.ts +6 -0
- package/dist/node/timers-promises.js +34 -0
- package/dist/node/url.d.ts +6 -0
- package/dist/node/url.js +34 -0
- package/dist/node/util.d.ts +6 -0
- package/dist/node/util.js +34 -0
- package/dist/objects.js +2 -2
- package/dist/packages/edit.js +8 -7
- package/dist/packages/exports.js +17 -16
- package/dist/packages/isolation.js +20 -13
- package/dist/packages/licenses.js +6 -3
- package/dist/packages/manifest.js +2 -1
- package/dist/packages/normalize.js +8 -4
- package/dist/packages/operations.js +5 -4
- package/dist/packages/provenance.js +7 -6
- package/dist/packages/specs.js +2 -1
- package/dist/packages/validation.js +2 -1
- package/dist/paths/normalize.js +32 -40
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.js +3 -2
- package/dist/performance.js +19 -18
- package/dist/primordials.d.ts +85 -2
- package/dist/primordials.js +311 -23
- package/dist/process-lock.js +14 -13
- package/dist/promise-queue.js +17 -9
- package/dist/promises.d.ts +29 -6
- package/dist/promises.js +19 -15
- package/dist/regexps.js +9 -8
- package/dist/releases/github-api.d.ts +56 -0
- package/dist/releases/github-api.js +275 -0
- package/dist/releases/github-archives.d.ts +60 -0
- package/dist/releases/github-archives.js +136 -0
- package/dist/releases/github-assets.d.ts +21 -0
- package/dist/releases/github-assets.js +52 -0
- package/dist/releases/github-auth.d.ts +16 -0
- package/dist/releases/github-auth.js +51 -0
- package/dist/releases/github-downloads.d.ts +42 -0
- package/dist/releases/github-downloads.js +155 -0
- package/dist/releases/github-types.d.ts +66 -0
- package/dist/{effects/types.js → releases/github-types.js} +2 -2
- package/dist/releases/socket-btm.d.ts +1 -1
- package/dist/releases/socket-btm.js +17 -17
- package/dist/schema/parse.js +2 -1
- package/dist/schema/validate.js +6 -5
- package/dist/sea/util.d.ts +43 -0
- package/dist/{sea.js → sea/util.js} +7 -7
- package/dist/shadow.js +2 -1
- package/dist/signal-exit.js +2 -2
- package/dist/smol/primordial.d.ts +80 -0
- package/dist/smol/primordial.js +46 -0
- package/dist/smol/util.d.ts +87 -0
- package/dist/smol/util.js +59 -0
- package/dist/smol/versions.d.ts +46 -0
- package/dist/smol/versions.js +46 -0
- package/dist/spawn.js +58 -63
- package/dist/spinner.d.ts +13 -6
- package/dist/spinner.js +75 -57
- package/dist/ssri.js +8 -7
- package/dist/stdio/footer.js +13 -12
- package/dist/stdio/header.js +5 -4
- package/dist/stdio/progress.js +13 -12
- package/dist/strings.js +19 -18
- package/dist/suppress-warnings.js +2 -2
- package/dist/tables.js +16 -13
- package/dist/temporary-executor.js +2 -1
- package/dist/themes/context.js +2 -1
- package/dist/themes/types.d.ts +1 -1
- package/dist/themes/utils.d.ts +8 -3
- package/dist/themes/utils.js +29 -5
- package/dist/url.js +4 -3
- package/dist/versions.js +27 -22
- package/package.json +120 -26
- package/dist/effects/text-shimmer.d.ts +0 -58
- package/dist/effects/text-shimmer.js +0 -192
- package/dist/effects/types.d.ts +0 -47
- package/dist/effects/ultra.d.ts +0 -22
- package/dist/releases/github.d.ts +0 -234
- package/dist/releases/github.js +0 -417
- package/dist/sea.d.ts +0 -30
- package/dist/themes/index.d.ts +0 -49
- package/dist/themes/index.js +0 -60
package/dist/fs.js
CHANGED
|
@@ -67,12 +67,15 @@ 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");
|
|
73
75
|
var import_socket = require("./paths/socket");
|
|
74
76
|
var import_promises = require("./promises");
|
|
75
77
|
var import_sorts = require("./sorts");
|
|
78
|
+
var import_primordials = require("./primordials");
|
|
76
79
|
const abortSignal = (0, import_process.getAbortSignal)();
|
|
77
80
|
const NEWLINE_REGEX = /\n/g;
|
|
78
81
|
const defaultRemoveOptions = (0, import_objects.objectFreeze)({
|
|
@@ -84,12 +87,9 @@ const defaultRemoveOptions = (0, import_objects.objectFreeze)({
|
|
|
84
87
|
});
|
|
85
88
|
let _del;
|
|
86
89
|
let _cachedAllowedDirs;
|
|
87
|
-
let _buffer;
|
|
88
|
-
let _fs;
|
|
89
|
-
let _path;
|
|
90
90
|
function getAllowedDirectories() {
|
|
91
91
|
if (_cachedAllowedDirs === void 0) {
|
|
92
|
-
const path =
|
|
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)()),
|
|
@@ -99,13 +99,6 @@ function getAllowedDirectories() {
|
|
|
99
99
|
return _cachedAllowedDirs;
|
|
100
100
|
}
|
|
101
101
|
// @__NO_SIDE_EFFECTS__
|
|
102
|
-
function getBuffer() {
|
|
103
|
-
if (_buffer === void 0) {
|
|
104
|
-
_buffer = require("node:buffer");
|
|
105
|
-
}
|
|
106
|
-
return _buffer;
|
|
107
|
-
}
|
|
108
|
-
// @__NO_SIDE_EFFECTS__
|
|
109
102
|
function getDel() {
|
|
110
103
|
if (_del === void 0) {
|
|
111
104
|
_del = require("./external/del");
|
|
@@ -113,27 +106,13 @@ function getDel() {
|
|
|
113
106
|
return _del;
|
|
114
107
|
}
|
|
115
108
|
// @__NO_SIDE_EFFECTS__
|
|
116
|
-
function getFs() {
|
|
117
|
-
if (_fs === void 0) {
|
|
118
|
-
_fs = require("node:fs");
|
|
119
|
-
}
|
|
120
|
-
return _fs;
|
|
121
|
-
}
|
|
122
|
-
// @__NO_SIDE_EFFECTS__
|
|
123
|
-
function getPath() {
|
|
124
|
-
if (_path === void 0) {
|
|
125
|
-
_path = require("node:path");
|
|
126
|
-
}
|
|
127
|
-
return _path;
|
|
128
|
-
}
|
|
129
|
-
// @__NO_SIDE_EFFECTS__
|
|
130
109
|
function innerReadDirNames(dirents, dirname, options) {
|
|
131
110
|
const {
|
|
132
111
|
ignore,
|
|
133
112
|
includeEmpty = true,
|
|
134
113
|
sort = true
|
|
135
114
|
} = { __proto__: null, ...options };
|
|
136
|
-
const path =
|
|
115
|
+
const path = (0, import_path.getNodePath)();
|
|
137
116
|
const names = dirents.filter(
|
|
138
117
|
(d) => d.isDirectory() && (includeEmpty || !/* @__PURE__ */ isDirEmptySync(path.join(dirname || d.parentPath, d.name), {
|
|
139
118
|
ignore
|
|
@@ -144,8 +123,8 @@ function innerReadDirNames(dirents, dirname, options) {
|
|
|
144
123
|
// @__NO_SIDE_EFFECTS__
|
|
145
124
|
function stringify(json, EOL, finalEOL, replacer, spaces = 2) {
|
|
146
125
|
const EOF = finalEOL ? EOL : "";
|
|
147
|
-
const str =
|
|
148
|
-
return `${
|
|
126
|
+
const str = (0, import_primordials.JSONStringify)(json, replacer, spaces);
|
|
127
|
+
return `${(0, import_primordials.StringPrototypeReplace)(str, NEWLINE_REGEX, EOL)}${EOF}`;
|
|
149
128
|
}
|
|
150
129
|
// @__NO_SIDE_EFFECTS__
|
|
151
130
|
async function findUp(name, options) {
|
|
@@ -163,8 +142,8 @@ async function findUp(name, options) {
|
|
|
163
142
|
if (onlyFiles) {
|
|
164
143
|
onlyDirectories = false;
|
|
165
144
|
}
|
|
166
|
-
const fs =
|
|
167
|
-
const path =
|
|
145
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
146
|
+
const path = (0, import_path.getNodePath)();
|
|
168
147
|
let dir = path.resolve(cwd);
|
|
169
148
|
const { root } = path.parse(dir);
|
|
170
149
|
const names = (0, import_arrays.isArray)(name) ? name : [name];
|
|
@@ -208,8 +187,8 @@ function findUpSync(name, options) {
|
|
|
208
187
|
if (onlyFiles) {
|
|
209
188
|
onlyDirectories = false;
|
|
210
189
|
}
|
|
211
|
-
const fs =
|
|
212
|
-
const path =
|
|
190
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
191
|
+
const path = (0, import_path.getNodePath)();
|
|
213
192
|
let dir = path.resolve(cwd);
|
|
214
193
|
const { root } = path.parse(dir);
|
|
215
194
|
const stopDir = stopAt ? path.resolve(stopAt) : void 0;
|
|
@@ -264,7 +243,7 @@ function isDirEmptySync(dirname, options) {
|
|
|
264
243
|
__proto__: null,
|
|
265
244
|
...options
|
|
266
245
|
};
|
|
267
|
-
const fs =
|
|
246
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
268
247
|
try {
|
|
269
248
|
const files = fs.readdirSync(dirname);
|
|
270
249
|
const { length } = files;
|
|
@@ -295,7 +274,7 @@ function isDirSync(filepath) {
|
|
|
295
274
|
}
|
|
296
275
|
// @__NO_SIDE_EFFECTS__
|
|
297
276
|
function isSymLinkSync(filepath) {
|
|
298
|
-
const fs =
|
|
277
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
299
278
|
try {
|
|
300
279
|
return fs.lstatSync(filepath).isSymbolicLink();
|
|
301
280
|
} catch {
|
|
@@ -375,7 +354,7 @@ function normalizeEncodingSlow(enc) {
|
|
|
375
354
|
}
|
|
376
355
|
// @__NO_SIDE_EFFECTS__
|
|
377
356
|
async function readDirNames(dirname, options) {
|
|
378
|
-
const fs =
|
|
357
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
379
358
|
try {
|
|
380
359
|
return /* @__PURE__ */ innerReadDirNames(
|
|
381
360
|
await fs.promises.readdir(dirname, {
|
|
@@ -392,7 +371,7 @@ async function readDirNames(dirname, options) {
|
|
|
392
371
|
}
|
|
393
372
|
// @__NO_SIDE_EFFECTS__
|
|
394
373
|
function readDirNamesSync(dirname, options) {
|
|
395
|
-
const fs =
|
|
374
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
396
375
|
try {
|
|
397
376
|
return /* @__PURE__ */ innerReadDirNames(
|
|
398
377
|
fs.readdirSync(dirname, {
|
|
@@ -410,7 +389,7 @@ function readDirNamesSync(dirname, options) {
|
|
|
410
389
|
// @__NO_SIDE_EFFECTS__
|
|
411
390
|
async function readFileBinary(filepath, options) {
|
|
412
391
|
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
413
|
-
const fs =
|
|
392
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
414
393
|
return await fs.promises.readFile(filepath, {
|
|
415
394
|
signal: abortSignal,
|
|
416
395
|
...opts,
|
|
@@ -420,7 +399,7 @@ async function readFileBinary(filepath, options) {
|
|
|
420
399
|
// @__NO_SIDE_EFFECTS__
|
|
421
400
|
function readFileBinarySync(filepath, options) {
|
|
422
401
|
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
423
|
-
const fs =
|
|
402
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
424
403
|
return fs.readFileSync(filepath, {
|
|
425
404
|
...opts,
|
|
426
405
|
encoding: null
|
|
@@ -429,7 +408,7 @@ function readFileBinarySync(filepath, options) {
|
|
|
429
408
|
// @__NO_SIDE_EFFECTS__
|
|
430
409
|
async function readFileUtf8(filepath, options) {
|
|
431
410
|
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
432
|
-
const fs =
|
|
411
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
433
412
|
return await fs.promises.readFile(filepath, {
|
|
434
413
|
signal: abortSignal,
|
|
435
414
|
...opts,
|
|
@@ -439,7 +418,7 @@ async function readFileUtf8(filepath, options) {
|
|
|
439
418
|
// @__NO_SIDE_EFFECTS__
|
|
440
419
|
function readFileUtf8Sync(filepath, options) {
|
|
441
420
|
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
442
|
-
const fs =
|
|
421
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
443
422
|
return fs.readFileSync(filepath, {
|
|
444
423
|
...opts,
|
|
445
424
|
encoding: "utf8"
|
|
@@ -453,7 +432,7 @@ async function readJson(filepath, options) {
|
|
|
453
432
|
...opts
|
|
454
433
|
};
|
|
455
434
|
const shouldThrow = throws === void 0 || !!throws;
|
|
456
|
-
const fs =
|
|
435
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
457
436
|
let content = "";
|
|
458
437
|
try {
|
|
459
438
|
content = await fs.promises.readFile(filepath, {
|
|
@@ -465,14 +444,14 @@ async function readJson(filepath, options) {
|
|
|
465
444
|
if (shouldThrow) {
|
|
466
445
|
const code = e.code;
|
|
467
446
|
if (code === "ENOENT") {
|
|
468
|
-
throw new
|
|
447
|
+
throw new import_primordials.ErrorCtor(
|
|
469
448
|
`JSON file not found: ${filepath}
|
|
470
449
|
Ensure the file exists or create it with the expected structure.`,
|
|
471
450
|
{ cause: e }
|
|
472
451
|
);
|
|
473
452
|
}
|
|
474
453
|
if (code === "EACCES" || code === "EPERM") {
|
|
475
|
-
throw new
|
|
454
|
+
throw new import_primordials.ErrorCtor(
|
|
476
455
|
`Permission denied reading JSON file: ${filepath}
|
|
477
456
|
Check file permissions or run with appropriate access.`,
|
|
478
457
|
{ cause: e }
|
|
@@ -496,7 +475,7 @@ function readJsonSync(filepath, options) {
|
|
|
496
475
|
...opts
|
|
497
476
|
};
|
|
498
477
|
const shouldThrow = throws === void 0 || !!throws;
|
|
499
|
-
const fs =
|
|
478
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
500
479
|
let content = "";
|
|
501
480
|
try {
|
|
502
481
|
content = fs.readFileSync(filepath, {
|
|
@@ -508,14 +487,14 @@ function readJsonSync(filepath, options) {
|
|
|
508
487
|
if (shouldThrow) {
|
|
509
488
|
const code = e.code;
|
|
510
489
|
if (code === "ENOENT") {
|
|
511
|
-
throw new
|
|
490
|
+
throw new import_primordials.ErrorCtor(
|
|
512
491
|
`JSON file not found: ${filepath}
|
|
513
492
|
Ensure the file exists or create it with the expected structure.`,
|
|
514
493
|
{ cause: e }
|
|
515
494
|
);
|
|
516
495
|
}
|
|
517
496
|
if (code === "EACCES" || code === "EPERM") {
|
|
518
|
-
throw new
|
|
497
|
+
throw new import_primordials.ErrorCtor(
|
|
519
498
|
`Permission denied reading JSON file: ${filepath}
|
|
520
499
|
Check file permissions or run with appropriate access.`,
|
|
521
500
|
{ cause: e }
|
|
@@ -536,14 +515,14 @@ async function safeDelete(filepath, options) {
|
|
|
536
515
|
const patterns = (0, import_arrays.isArray)(filepath) ? filepath.map(import_normalize.pathLikeToString) : [(0, import_normalize.pathLikeToString)(filepath)];
|
|
537
516
|
let shouldForce = opts.force !== false;
|
|
538
517
|
if (!shouldForce && patterns.length > 0) {
|
|
539
|
-
const path =
|
|
518
|
+
const path = (0, import_path.getNodePath)();
|
|
540
519
|
const allowedDirs = getAllowedDirectories();
|
|
541
520
|
const allInAllowedDirs = patterns.every((pattern) => {
|
|
542
521
|
const resolvedPath = path.resolve(pattern);
|
|
543
522
|
for (const allowedDir of allowedDirs) {
|
|
544
|
-
const isInAllowedDir =
|
|
523
|
+
const isInAllowedDir = (0, import_primordials.StringPrototypeStartsWith)(resolvedPath, allowedDir + path.sep) || resolvedPath === allowedDir;
|
|
545
524
|
const relativePath = path.relative(allowedDir, resolvedPath);
|
|
546
|
-
const isGoingBackward =
|
|
525
|
+
const isGoingBackward = (0, import_primordials.StringPrototypeStartsWith)(relativePath, "..");
|
|
547
526
|
if (isInAllowedDir && !isGoingBackward) {
|
|
548
527
|
return true;
|
|
549
528
|
}
|
|
@@ -578,14 +557,14 @@ function safeDeleteSync(filepath, options) {
|
|
|
578
557
|
const patterns = (0, import_arrays.isArray)(filepath) ? filepath.map(import_normalize.pathLikeToString) : [(0, import_normalize.pathLikeToString)(filepath)];
|
|
579
558
|
let shouldForce = opts.force !== false;
|
|
580
559
|
if (!shouldForce && patterns.length > 0) {
|
|
581
|
-
const path =
|
|
560
|
+
const path = (0, import_path.getNodePath)();
|
|
582
561
|
const allowedDirs = getAllowedDirectories();
|
|
583
562
|
const allInAllowedDirs = patterns.every((pattern) => {
|
|
584
563
|
const resolvedPath = path.resolve(pattern);
|
|
585
564
|
for (const allowedDir of allowedDirs) {
|
|
586
|
-
const isInAllowedDir =
|
|
565
|
+
const isInAllowedDir = (0, import_primordials.StringPrototypeStartsWith)(resolvedPath, allowedDir + path.sep) || resolvedPath === allowedDir;
|
|
587
566
|
const relativePath = path.relative(allowedDir, resolvedPath);
|
|
588
|
-
const isGoingBackward =
|
|
567
|
+
const isGoingBackward = (0, import_primordials.StringPrototypeStartsWith)(relativePath, "..");
|
|
589
568
|
if (isInAllowedDir && !isGoingBackward) {
|
|
590
569
|
return true;
|
|
591
570
|
}
|
|
@@ -613,7 +592,12 @@ function safeDeleteSync(filepath, options) {
|
|
|
613
592
|
lastError = e;
|
|
614
593
|
if (attempt < maxRetries) {
|
|
615
594
|
const waitMs = delay;
|
|
616
|
-
|
|
595
|
+
(0, import_primordials.AtomicsWait)(
|
|
596
|
+
new import_primordials.Int32ArrayCtor(new import_primordials.SharedArrayBufferCtor(4)),
|
|
597
|
+
0,
|
|
598
|
+
0,
|
|
599
|
+
waitMs
|
|
600
|
+
);
|
|
617
601
|
delay *= 2;
|
|
618
602
|
}
|
|
619
603
|
}
|
|
@@ -623,7 +607,7 @@ function safeDeleteSync(filepath, options) {
|
|
|
623
607
|
}
|
|
624
608
|
}
|
|
625
609
|
async function safeMkdir(path, options) {
|
|
626
|
-
const fs =
|
|
610
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
627
611
|
const opts = { __proto__: null, recursive: true, ...options };
|
|
628
612
|
try {
|
|
629
613
|
await fs.promises.mkdir(path, opts);
|
|
@@ -634,7 +618,7 @@ async function safeMkdir(path, options) {
|
|
|
634
618
|
}
|
|
635
619
|
}
|
|
636
620
|
function safeMkdirSync(path, options) {
|
|
637
|
-
const fs =
|
|
621
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
638
622
|
const opts = { __proto__: null, recursive: true, ...options };
|
|
639
623
|
try {
|
|
640
624
|
fs.mkdirSync(path, opts);
|
|
@@ -651,7 +635,7 @@ async function safeReadFile(filepath, options) {
|
|
|
651
635
|
const readOpts = { __proto__: null, ...rawReadOpts };
|
|
652
636
|
const shouldReturnBuffer = readOpts.encoding === null;
|
|
653
637
|
const encoding = shouldReturnBuffer ? null : /* @__PURE__ */ normalizeEncoding(readOpts.encoding);
|
|
654
|
-
const fs =
|
|
638
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
655
639
|
try {
|
|
656
640
|
return await fs.promises.readFile(filepath, {
|
|
657
641
|
__proto__: null,
|
|
@@ -665,8 +649,7 @@ async function safeReadFile(filepath, options) {
|
|
|
665
649
|
return void 0;
|
|
666
650
|
}
|
|
667
651
|
if (shouldReturnBuffer) {
|
|
668
|
-
|
|
669
|
-
return Buffer2.isBuffer(defaultValue) ? defaultValue : void 0;
|
|
652
|
+
return (0, import_primordials.BufferIsBuffer)(defaultValue) ? defaultValue : void 0;
|
|
670
653
|
}
|
|
671
654
|
return typeof defaultValue === "string" ? defaultValue : String(defaultValue);
|
|
672
655
|
}
|
|
@@ -677,7 +660,7 @@ function safeReadFileSync(filepath, options) {
|
|
|
677
660
|
const readOpts = { __proto__: null, ...rawReadOpts };
|
|
678
661
|
const shouldReturnBuffer = readOpts.encoding === null;
|
|
679
662
|
const encoding = shouldReturnBuffer ? null : /* @__PURE__ */ normalizeEncoding(readOpts.encoding);
|
|
680
|
-
const fs =
|
|
663
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
681
664
|
try {
|
|
682
665
|
return fs.readFileSync(filepath, {
|
|
683
666
|
__proto__: null,
|
|
@@ -690,14 +673,13 @@ function safeReadFileSync(filepath, options) {
|
|
|
690
673
|
return void 0;
|
|
691
674
|
}
|
|
692
675
|
if (shouldReturnBuffer) {
|
|
693
|
-
|
|
694
|
-
return Buffer2.isBuffer(defaultValue) ? defaultValue : void 0;
|
|
676
|
+
return (0, import_primordials.BufferIsBuffer)(defaultValue) ? defaultValue : void 0;
|
|
695
677
|
}
|
|
696
678
|
return typeof defaultValue === "string" ? defaultValue : String(defaultValue);
|
|
697
679
|
}
|
|
698
680
|
// @__NO_SIDE_EFFECTS__
|
|
699
681
|
async function safeStats(filepath) {
|
|
700
|
-
const fs =
|
|
682
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
701
683
|
try {
|
|
702
684
|
return await fs.promises.stat(filepath);
|
|
703
685
|
} catch {
|
|
@@ -706,7 +688,7 @@ async function safeStats(filepath) {
|
|
|
706
688
|
}
|
|
707
689
|
// @__NO_SIDE_EFFECTS__
|
|
708
690
|
function safeStatsSync(filepath) {
|
|
709
|
-
const fs =
|
|
691
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
710
692
|
try {
|
|
711
693
|
return fs.statSync(filepath, {
|
|
712
694
|
__proto__: null,
|
|
@@ -718,8 +700,8 @@ function safeStatsSync(filepath) {
|
|
|
718
700
|
}
|
|
719
701
|
// @__NO_SIDE_EFFECTS__
|
|
720
702
|
function uniqueSync(filepath) {
|
|
721
|
-
const fs =
|
|
722
|
-
const path =
|
|
703
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
704
|
+
const path = (0, import_path.getNodePath)();
|
|
723
705
|
const filepathStr = String(filepath);
|
|
724
706
|
if (!fs.existsSync(filepathStr)) {
|
|
725
707
|
return (0, import_normalize.normalizePath)(filepathStr);
|
|
@@ -737,7 +719,7 @@ function uniqueSync(filepath) {
|
|
|
737
719
|
}
|
|
738
720
|
// @__NO_SIDE_EFFECTS__
|
|
739
721
|
function validateFiles(filepaths) {
|
|
740
|
-
const fs =
|
|
722
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
741
723
|
const validPaths = [];
|
|
742
724
|
const invalidPaths = [];
|
|
743
725
|
const { R_OK } = fs.constants;
|
|
@@ -757,7 +739,7 @@ async function writeJson(filepath, jsonContent, options) {
|
|
|
757
739
|
__proto__: null,
|
|
758
740
|
...opts
|
|
759
741
|
};
|
|
760
|
-
const fs =
|
|
742
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
761
743
|
const jsonString = /* @__PURE__ */ stringify(
|
|
762
744
|
jsonContent,
|
|
763
745
|
EOL || "\n",
|
|
@@ -777,7 +759,7 @@ function writeJsonSync(filepath, jsonContent, options) {
|
|
|
777
759
|
__proto__: null,
|
|
778
760
|
...opts
|
|
779
761
|
};
|
|
780
|
-
const fs =
|
|
762
|
+
const fs = (0, import_fs.getNodeFs)();
|
|
781
763
|
const jsonString = /* @__PURE__ */ stringify(
|
|
782
764
|
jsonContent,
|
|
783
765
|
EOL || "\n",
|
package/dist/git.js
CHANGED
|
@@ -52,13 +52,14 @@ var import_globs = require("./globs");
|
|
|
52
52
|
var import_normalize = require("./paths/normalize");
|
|
53
53
|
var import_spawn = require("./spawn");
|
|
54
54
|
var import_strings = require("./strings");
|
|
55
|
+
var import_primordials = require("./primordials");
|
|
55
56
|
let _fs;
|
|
56
57
|
let _path;
|
|
57
|
-
const gitDiffCache =
|
|
58
|
+
const gitDiffCache = new import_primordials.MapCtor();
|
|
58
59
|
const GIT_CACHE_MAX_SIZE = 100;
|
|
59
60
|
let _gitPath;
|
|
60
|
-
const realpathCache =
|
|
61
|
-
const gitRootCache =
|
|
61
|
+
const realpathCache = new import_primordials.MapCtor();
|
|
62
|
+
const gitRootCache = new import_primordials.MapCtor();
|
|
62
63
|
function getCachedGitDiff(key) {
|
|
63
64
|
const result = gitDiffCache.get(key);
|
|
64
65
|
if (result) {
|
|
@@ -68,7 +69,7 @@ function getCachedGitDiff(key) {
|
|
|
68
69
|
return result;
|
|
69
70
|
}
|
|
70
71
|
function stableKey(value) {
|
|
71
|
-
return
|
|
72
|
+
return (0, import_primordials.JSONStringify)(value, (_key, val) => {
|
|
72
73
|
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
73
74
|
const sorted = {};
|
|
74
75
|
for (const k of Object.keys(val).sort()) {
|
|
@@ -166,7 +167,7 @@ async function innerDiff(args, options) {
|
|
|
166
167
|
...args[2],
|
|
167
168
|
stdioString: false
|
|
168
169
|
});
|
|
169
|
-
const stdout =
|
|
170
|
+
const stdout = (0, import_primordials.BufferIsBuffer)(spawnResult.stdout) ? spawnResult.stdout.toString("utf8") : String(spawnResult.stdout);
|
|
170
171
|
const spawnCwd = typeof args[2]["cwd"] === "string" ? args[2]["cwd"] : void 0;
|
|
171
172
|
result = parseGitDiffStdout(stdout, parseOptions, spawnCwd);
|
|
172
173
|
} catch (e) {
|
|
@@ -196,7 +197,7 @@ function innerDiffSync(args, options) {
|
|
|
196
197
|
...args[2],
|
|
197
198
|
stdioString: false
|
|
198
199
|
});
|
|
199
|
-
const stdout =
|
|
200
|
+
const stdout = (0, import_primordials.BufferIsBuffer)(spawnResult.stdout) ? spawnResult.stdout.toString("utf8") : String(spawnResult.stdout);
|
|
200
201
|
const spawnCwd = typeof args[2]["cwd"] === "string" ? args[2]["cwd"] : void 0;
|
|
201
202
|
result = parseGitDiffStdout(stdout, parseOptions, spawnCwd);
|
|
202
203
|
} catch (e) {
|
|
@@ -225,7 +226,7 @@ function parseGitDiffStdout(stdout, options, spawnCwd) {
|
|
|
225
226
|
let rawFiles = stdout ? (0, import_strings.stripAnsi)(stdout).split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line) : [];
|
|
226
227
|
if (porcelain) {
|
|
227
228
|
rawFiles = rawFiles.map((line) => {
|
|
228
|
-
return line.length > 3 ?
|
|
229
|
+
return line.length > 3 ? (0, import_primordials.StringPrototypeSubstring)(line, 3) : line;
|
|
229
230
|
});
|
|
230
231
|
}
|
|
231
232
|
const files = absolute ? rawFiles.map((relPath2) => (0, import_normalize.normalizePath)(path.join(rootPath, relPath2))) : rawFiles.map((relPath2) => (0, import_normalize.normalizePath)(relPath2));
|
|
@@ -324,7 +325,7 @@ async function isChanged(pathname, options) {
|
|
|
324
325
|
const resolvedPathname = getCachedRealpath(pathname);
|
|
325
326
|
const baseCwd = options?.cwd ? getCachedRealpath(options["cwd"]) : getCwd();
|
|
326
327
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
327
|
-
return
|
|
328
|
+
return (0, import_primordials.ArrayPrototypeIncludes)(files, relativePath);
|
|
328
329
|
}
|
|
329
330
|
function isChangedSync(pathname, options) {
|
|
330
331
|
const files = getChangedFilesSync({
|
|
@@ -337,7 +338,7 @@ function isChangedSync(pathname, options) {
|
|
|
337
338
|
const resolvedPathname = getCachedRealpath(pathname);
|
|
338
339
|
const baseCwd = options?.cwd ? getCachedRealpath(options["cwd"]) : getCwd();
|
|
339
340
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
340
|
-
return
|
|
341
|
+
return (0, import_primordials.ArrayPrototypeIncludes)(files, relativePath);
|
|
341
342
|
} catch {
|
|
342
343
|
return false;
|
|
343
344
|
}
|
|
@@ -352,7 +353,7 @@ async function isStaged(pathname, options) {
|
|
|
352
353
|
const resolvedPathname = getCachedRealpath(pathname);
|
|
353
354
|
const baseCwd = options?.cwd ? getCachedRealpath(options["cwd"]) : getCwd();
|
|
354
355
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
355
|
-
return
|
|
356
|
+
return (0, import_primordials.ArrayPrototypeIncludes)(files, relativePath);
|
|
356
357
|
}
|
|
357
358
|
function isStagedSync(pathname, options) {
|
|
358
359
|
const files = getStagedFilesSync({
|
|
@@ -364,7 +365,7 @@ function isStagedSync(pathname, options) {
|
|
|
364
365
|
const resolvedPathname = getCachedRealpath(pathname);
|
|
365
366
|
const baseCwd = options?.cwd ? getCachedRealpath(options["cwd"]) : getCwd();
|
|
366
367
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
367
|
-
return
|
|
368
|
+
return (0, import_primordials.ArrayPrototypeIncludes)(files, relativePath);
|
|
368
369
|
}
|
|
369
370
|
async function isUnstaged(pathname, options) {
|
|
370
371
|
const files = await getUnstagedFiles({
|
|
@@ -376,7 +377,7 @@ async function isUnstaged(pathname, options) {
|
|
|
376
377
|
const resolvedPathname = getCachedRealpath(pathname);
|
|
377
378
|
const baseCwd = options?.cwd ? getCachedRealpath(options["cwd"]) : getCwd();
|
|
378
379
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
379
|
-
return
|
|
380
|
+
return (0, import_primordials.ArrayPrototypeIncludes)(files, relativePath);
|
|
380
381
|
}
|
|
381
382
|
function isUnstagedSync(pathname, options) {
|
|
382
383
|
const files = getUnstagedFilesSync({
|
|
@@ -388,7 +389,7 @@ function isUnstagedSync(pathname, options) {
|
|
|
388
389
|
const resolvedPathname = getCachedRealpath(pathname);
|
|
389
390
|
const baseCwd = options?.cwd ? getCachedRealpath(options["cwd"]) : getCwd();
|
|
390
391
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
391
|
-
return
|
|
392
|
+
return (0, import_primordials.ArrayPrototypeIncludes)(files, relativePath);
|
|
392
393
|
}
|
|
393
394
|
// Annotate the CommonJS export names for ESM import in node:
|
|
394
395
|
0 && (module.exports = {
|
package/dist/github.d.ts
CHANGED
|
@@ -21,6 +21,40 @@
|
|
|
21
21
|
* - Cache to minimize API calls
|
|
22
22
|
*/
|
|
23
23
|
import type { SpawnOptions } from './spawn';
|
|
24
|
+
/**
|
|
25
|
+
* Thrown by `fetchGitHub` when GitHub returns HTTP 200 OK with a
|
|
26
|
+
* zero-byte body — the "successful empty response" pattern.
|
|
27
|
+
*
|
|
28
|
+
* Why this exists (background for new contributors):
|
|
29
|
+
* GitHub's REST API has a documented failure mode that is *very*
|
|
30
|
+
* easy to miss in code review. During incidents where the search
|
|
31
|
+
* / Elasticsearch backing index is degraded (see GitHub status
|
|
32
|
+
* pages with titles like "search is degraded" or "Pull Requests
|
|
33
|
+
* degraded"), the REST `/repos/...` GET endpoints return:
|
|
34
|
+
* - HTTP status: 200 OK ← looks like success
|
|
35
|
+
* - Body: "" ← but the payload is empty
|
|
36
|
+
* - Headers: no Retry-After, no rate-limit signal, nothing
|
|
37
|
+
*
|
|
38
|
+
* Without a typed error, calling code does
|
|
39
|
+
* `JSON.parse(response.body.toString('utf8'))`
|
|
40
|
+
* on an empty string, which throws a confusing
|
|
41
|
+
* `SyntaxError: Unexpected end of JSON input`. That error has
|
|
42
|
+
* nothing to do with our code — but it's the only signal upstream
|
|
43
|
+
* sees. This class wraps that case in a *named* error so callers
|
|
44
|
+
* can `instanceof GitHubEmptyBodyError` and choose what to do:
|
|
45
|
+
* retry the same endpoint later, fall back to GraphQL (which uses
|
|
46
|
+
* a different backend and is unaffected by ES outages), or surface
|
|
47
|
+
* a clean message to the user.
|
|
48
|
+
*
|
|
49
|
+
* The HTTP status is hard-coded to 200 because that's *exactly*
|
|
50
|
+
* what makes this insidious — a real 4xx/5xx would already be
|
|
51
|
+
* handled by the rate-limit / status-code branch above.
|
|
52
|
+
*/
|
|
53
|
+
export declare class GitHubEmptyBodyError extends Error {
|
|
54
|
+
/** HTTP status (always 200 — that's what makes this case insidious). */
|
|
55
|
+
status: number;
|
|
56
|
+
constructor(url: string);
|
|
57
|
+
}
|
|
24
58
|
/**
|
|
25
59
|
* Options for GitHub API fetch requests.
|
|
26
60
|
*/
|