@socketsecurity/lib 5.18.1 → 5.19.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 +49 -0
- package/README.md +6 -5
- package/dist/abort.d.ts +3 -0
- package/dist/abort.js +1 -0
- package/dist/agent.d.ts +66 -49
- package/dist/agent.js +51 -50
- package/dist/ansi.d.ts +2 -5
- package/dist/ansi.js +3 -2
- package/dist/archives.d.ts +25 -21
- package/dist/archives.js +35 -34
- package/dist/argv/flags.d.ts +100 -91
- package/dist/argv/flags.js +88 -87
- package/dist/argv/parse.d.ts +30 -40
- package/dist/argv/parse.js +33 -32
- package/dist/arrays.d.ts +4 -8
- package/dist/arrays.js +1 -0
- package/dist/bin.d.ts +7 -5
- package/dist/bin.js +52 -29
- package/dist/cacache.d.ts +13 -12
- package/dist/cacache.js +9 -8
- package/dist/cache-with-ttl.d.ts +53 -35
- package/dist/cache-with-ttl.js +1 -0
- package/dist/colors.d.ts +5 -5
- package/dist/colors.js +1 -0
- package/dist/constants/agents.d.ts +5 -9
- package/dist/constants/agents.js +3 -2
- package/dist/constants/core.d.ts +5 -10
- package/dist/constants/core.js +2 -1
- package/dist/constants/encoding.d.ts +3 -3
- package/dist/constants/encoding.js +1 -0
- package/dist/constants/github.d.ts +3 -3
- package/dist/constants/github.js +1 -0
- package/dist/constants/licenses.d.ts +9 -2
- package/dist/constants/licenses.js +1 -0
- package/dist/constants/lifecycle-script-names.js +1 -0
- package/dist/constants/maintained-node-versions.d.ts +3 -0
- package/dist/constants/maintained-node-versions.js +1 -0
- package/dist/constants/node.d.ts +125 -16
- package/dist/constants/node.js +74 -73
- package/dist/constants/package-default-node-range.d.ts +3 -1
- package/dist/constants/package-default-node-range.js +2 -1
- package/dist/constants/package-default-socket-categories.d.ts +0 -1
- package/dist/constants/package-default-socket-categories.js +1 -0
- package/dist/constants/packages.d.ts +12 -17
- package/dist/constants/packages.js +31 -16
- package/dist/constants/platform.d.ts +1 -2
- package/dist/constants/platform.js +2 -1
- package/dist/constants/process.d.ts +18 -0
- package/dist/constants/process.js +1 -0
- package/dist/constants/socket.d.ts +4 -10
- package/dist/constants/socket.js +2 -1
- package/dist/constants/testing.d.ts +3 -3
- package/dist/constants/testing.js +1 -0
- package/dist/constants/time.d.ts +3 -4
- package/dist/constants/time.js +1 -0
- package/dist/constants/typescript.d.ts +10 -3
- package/dist/constants/typescript.js +5 -4
- package/dist/cover/code.d.ts +3 -0
- package/dist/cover/code.js +12 -12
- package/dist/cover/formatters.d.ts +12 -9
- package/dist/cover/formatters.js +19 -18
- package/dist/cover/type.d.ts +3 -0
- package/dist/cover/type.js +1 -0
- package/dist/cover/types.js +1 -0
- package/dist/debug.d.ts +32 -47
- package/dist/debug.js +97 -96
- package/dist/dlx/arborist.d.ts +134 -0
- package/dist/dlx/arborist.js +177 -0
- package/dist/dlx/binary.d.ts +25 -9
- package/dist/dlx/binary.js +34 -12
- package/dist/dlx/cache.d.ts +1 -0
- package/dist/dlx/cache.js +2 -1
- package/dist/dlx/detect.d.ts +15 -0
- package/dist/dlx/detect.js +28 -20
- package/dist/dlx/dir.d.ts +1 -11
- package/dist/dlx/dir.js +2 -12
- package/dist/dlx/integrity.d.ts +86 -0
- package/dist/dlx/integrity.js +112 -0
- package/dist/dlx/lockfile.d.ts +115 -0
- package/dist/dlx/lockfile.js +139 -0
- package/dist/dlx/manifest.d.ts +26 -1
- package/dist/dlx/manifest.js +9 -6
- package/dist/dlx/package.d.ts +58 -3
- package/dist/dlx/package.js +101 -74
- package/dist/dlx/packages.d.ts +1 -11
- package/dist/dlx/packages.js +3 -14
- package/dist/dlx/paths.d.ts +1 -0
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +1 -0
- package/dist/effects/text-shimmer.d.ts +13 -2
- package/dist/effects/text-shimmer.js +50 -46
- package/dist/effects/types.js +1 -0
- package/dist/effects/ultra.js +1 -0
- package/dist/env/ci.d.ts +6 -1
- package/dist/env/ci.js +1 -0
- package/dist/env/debug.d.ts +5 -1
- package/dist/env/debug.js +1 -0
- package/dist/env/github.d.ts +19 -23
- package/dist/env/github.js +5 -4
- package/dist/env/helpers.d.ts +21 -9
- package/dist/env/helpers.js +5 -11
- package/dist/env/home.d.ts +17 -4
- package/dist/env/home.js +2 -1
- package/dist/env/locale.d.ts +4 -3
- package/dist/env/locale.js +1 -0
- package/dist/env/node-auth-token.d.ts +5 -1
- package/dist/env/node-auth-token.js +1 -0
- package/dist/env/node-env.d.ts +5 -1
- package/dist/env/node-env.js +1 -0
- package/dist/env/npm.d.ts +4 -5
- package/dist/env/npm.js +1 -0
- package/dist/env/package-manager.d.ts +4 -3
- package/dist/env/package-manager.js +2 -1
- package/dist/env/path.d.ts +5 -1
- package/dist/env/path.js +1 -0
- package/dist/env/pre-commit.d.ts +5 -1
- package/dist/env/pre-commit.js +1 -0
- package/dist/env/rewire.d.ts +10 -0
- package/dist/env/rewire.js +7 -5
- package/dist/env/shell.d.ts +5 -1
- package/dist/env/shell.js +1 -0
- package/dist/env/socket-cli-shadow.d.ts +4 -5
- package/dist/env/socket-cli-shadow.js +1 -0
- package/dist/env/socket-cli.d.ts +4 -14
- package/dist/env/socket-cli.js +1 -0
- package/dist/env/socket.d.ts +6 -18
- package/dist/env/socket.js +4 -3
- package/dist/env/temp-dir.d.ts +4 -3
- package/dist/env/temp-dir.js +1 -0
- package/dist/env/term.d.ts +5 -1
- package/dist/env/term.js +1 -0
- package/dist/env/test.d.ts +4 -3
- package/dist/env/test.js +1 -0
- package/dist/env/windows.d.ts +4 -4
- package/dist/env/windows.js +1 -0
- package/dist/env/xdg.d.ts +4 -3
- package/dist/env/xdg.js +1 -0
- package/dist/env.d.ts +83 -23
- package/dist/env.js +112 -80
- package/dist/errors.js +1 -0
- package/dist/external/@npmcli/package-json.js +9 -3968
- package/dist/external/@socketregistry/packageurl-js.js +2 -2
- package/dist/external/debug.js +162 -328
- package/dist/external/external-pack.js +3 -2835
- package/dist/external/npm-pack.js +13939 -33342
- package/dist/external/zod.js +160 -7558
- package/dist/fs.d.ts +92 -113
- package/dist/fs.js +35 -35
- package/dist/git.d.ts +170 -164
- package/dist/git.js +113 -87
- package/dist/github.d.ts +249 -227
- package/dist/github.js +82 -81
- package/dist/globs.d.ts +31 -17
- package/dist/globs.js +51 -58
- package/dist/http-request.d.ts +99 -99
- package/dist/http-request.js +182 -156
- package/dist/ipc-cli.d.ts +28 -0
- package/dist/{utils/get-ipc.js → ipc-cli.js} +4 -3
- package/dist/ipc.d.ts +9 -299
- package/dist/ipc.js +18 -204
- package/dist/json/edit.d.ts +3 -1
- package/dist/json/edit.js +30 -30
- package/dist/json/format.d.ts +36 -36
- package/dist/json/format.js +22 -21
- package/dist/json/parse.d.ts +4 -2
- package/dist/json/parse.js +1 -0
- package/dist/json/types.js +1 -0
- package/dist/{links/index.d.ts → links.d.ts} +6 -2
- package/dist/{links/index.js → links.js} +5 -4
- package/dist/logger.d.ts +4 -6
- package/dist/logger.js +61 -53
- package/dist/memoization.d.ts +52 -49
- package/dist/memoization.js +55 -33
- package/dist/objects.d.ts +25 -44
- package/dist/objects.js +2 -1
- package/dist/package-extensions.d.ts +6 -0
- package/dist/package-extensions.js +2 -1
- package/dist/packages/edit.d.ts +3 -5
- package/dist/packages/edit.js +4 -3
- package/dist/packages/exports.d.ts +11 -14
- package/dist/packages/exports.js +11 -10
- package/dist/packages/isolation.d.ts +4 -0
- package/dist/packages/isolation.js +20 -19
- package/dist/packages/licenses.d.ts +3 -10
- package/dist/packages/licenses.js +2 -1
- package/dist/packages/manifest.d.ts +3 -3
- package/dist/packages/manifest.js +1 -0
- package/dist/packages/normalize.d.ts +3 -4
- package/dist/packages/normalize.js +1 -0
- package/dist/packages/operations.d.ts +3 -10
- package/dist/packages/operations.js +1 -0
- package/dist/packages/provenance.d.ts +10 -8
- package/dist/packages/provenance.js +55 -54
- package/dist/packages/specs.d.ts +3 -5
- package/dist/packages/specs.js +1 -0
- package/dist/packages/validation.d.ts +3 -3
- package/dist/packages/validation.js +1 -0
- package/dist/packages.d.ts +2 -17
- package/dist/packages.js +2 -1
- package/dist/paths/dirnames.d.ts +0 -2
- package/dist/paths/dirnames.js +1 -0
- package/dist/paths/exts.d.ts +0 -1
- package/dist/paths/exts.js +1 -0
- package/dist/paths/filenames.d.ts +0 -1
- package/dist/paths/filenames.js +1 -0
- package/dist/paths/globs.d.ts +0 -1
- package/dist/paths/globs.js +1 -0
- package/dist/paths/normalize.d.ts +115 -123
- package/dist/paths/normalize.js +128 -127
- package/dist/paths/packages.d.ts +3 -2
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.d.ts +9 -0
- package/dist/paths/rewire.js +5 -3
- package/dist/paths/socket.d.ts +37 -23
- package/dist/paths/socket.js +26 -25
- package/dist/performance.d.ts +87 -84
- package/dist/performance.js +97 -96
- package/dist/process-lock.d.ts +41 -1
- package/dist/process-lock.js +24 -17
- package/dist/promise-queue.d.ts +6 -0
- package/dist/promise-queue.js +1 -0
- package/dist/promises.d.ts +40 -55
- package/dist/promises.js +12 -11
- package/dist/regexps.d.ts +0 -5
- package/dist/regexps.js +1 -0
- package/dist/releases/github.d.ts +59 -63
- package/dist/releases/github.js +95 -100
- package/dist/releases/socket-btm.d.ts +9 -2
- package/dist/releases/socket-btm.js +32 -25
- package/dist/sea.d.ts +5 -0
- package/dist/sea.js +1 -0
- package/dist/shadow.d.ts +4 -0
- package/dist/shadow.js +1 -0
- package/dist/signal-exit.d.ts +7 -7
- package/dist/signal-exit.js +46 -45
- package/dist/sorts.d.ts +5 -7
- package/dist/sorts.js +11 -10
- package/dist/spawn.d.ts +96 -77
- package/dist/spawn.js +39 -38
- package/dist/spinner.d.ts +21 -22
- package/dist/spinner.js +15 -11
- package/dist/ssri.d.ts +31 -36
- package/dist/ssri.js +15 -14
- package/dist/stdio/_stream.d.ts +31 -0
- package/dist/stdio/_stream.js +57 -0
- package/dist/stdio/divider.d.ts +40 -36
- package/dist/stdio/divider.js +10 -9
- package/dist/stdio/footer.d.ts +20 -0
- package/dist/stdio/footer.js +12 -2
- package/dist/stdio/header.d.ts +4 -16
- package/dist/stdio/header.js +1 -9
- package/dist/stdio/stderr.d.ts +51 -39
- package/dist/stdio/stderr.js +19 -22
- package/dist/stdio/stdout.d.ts +54 -52
- package/dist/stdio/stdout.js +35 -33
- package/dist/streams.d.ts +4 -3
- package/dist/streams.js +1 -0
- package/dist/strings.d.ts +31 -85
- package/dist/strings.js +5 -49
- package/dist/suppress-warnings.d.ts +32 -15
- package/dist/suppress-warnings.js +14 -13
- package/dist/tables.d.ts +30 -26
- package/dist/tables.js +24 -23
- package/dist/temporary-executor.d.ts +4 -0
- package/dist/temporary-executor.js +1 -0
- package/dist/themes/context.d.ts +30 -26
- package/dist/themes/context.js +19 -18
- package/dist/themes/index.d.ts +0 -4
- package/dist/themes/index.js +1 -0
- package/dist/themes/themes.d.ts +1 -1
- package/dist/themes/themes.js +1 -0
- package/dist/themes/types.js +1 -0
- package/dist/themes/utils.d.ts +46 -43
- package/dist/themes/utils.js +45 -44
- package/dist/types.d.ts +48 -52
- package/dist/types.js +35 -35
- package/dist/url.d.ts +48 -53
- package/dist/url.js +38 -37
- package/dist/validation/json-parser.d.ts +19 -190
- package/dist/validation/json-parser.js +5 -69
- package/dist/validation/types.d.ts +9 -33
- package/dist/validation/types.js +1 -0
- package/dist/versions.d.ts +1 -0
- package/dist/versions.js +2 -1
- package/dist/words.d.ts +3 -6
- package/dist/words.js +1 -0
- package/dist/zod.js +1 -0
- package/package.json +34 -70
- package/dist/external/@inquirer/checkbox.js +0 -5
- package/dist/external/@inquirer/confirm.js +0 -5
- package/dist/external/@inquirer/input.js +0 -5
- package/dist/external/@inquirer/password.js +0 -5
- package/dist/external/@inquirer/search.js +0 -5
- package/dist/external/@inquirer/select.js +0 -5
- package/dist/functions.d.ts +0 -57
- package/dist/functions.js +0 -70
- package/dist/stdio/clear.d.ts +0 -140
- package/dist/stdio/clear.js +0 -95
- package/dist/stdio/mask.d.ts +0 -151
- package/dist/stdio/mask.js +0 -224
- package/dist/stdio/progress.d.ts +0 -148
- package/dist/stdio/progress.js +0 -212
- package/dist/stdio/prompts.d.ts +0 -195
- package/dist/stdio/prompts.js +0 -176
- package/dist/utils/get-ipc.d.ts +0 -15
package/dist/git.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -52,35 +53,32 @@ var import_normalize = require("./paths/normalize");
|
|
|
52
53
|
var import_spawn = require("./spawn");
|
|
53
54
|
var import_strings = require("./strings");
|
|
54
55
|
let _fs;
|
|
55
|
-
// @__NO_SIDE_EFFECTS__
|
|
56
|
-
function getFs() {
|
|
57
|
-
if (_fs === void 0) {
|
|
58
|
-
_fs = require("fs");
|
|
59
|
-
}
|
|
60
|
-
return _fs;
|
|
61
|
-
}
|
|
62
56
|
let _path;
|
|
63
|
-
// @__NO_SIDE_EFFECTS__
|
|
64
|
-
function getPath() {
|
|
65
|
-
if (_path === void 0) {
|
|
66
|
-
_path = require("path");
|
|
67
|
-
}
|
|
68
|
-
return _path;
|
|
69
|
-
}
|
|
70
57
|
const gitDiffCache = /* @__PURE__ */ new Map();
|
|
71
|
-
const gitDiffAccessOrder = [];
|
|
72
58
|
const GIT_CACHE_MAX_SIZE = 100;
|
|
73
|
-
function evictLRUGitCache() {
|
|
74
|
-
if (gitDiffCache.size >= GIT_CACHE_MAX_SIZE && gitDiffAccessOrder.length > 0) {
|
|
75
|
-
const oldest = gitDiffAccessOrder.shift();
|
|
76
|
-
if (oldest) {
|
|
77
|
-
gitDiffCache.delete(oldest);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
59
|
let _gitPath;
|
|
82
60
|
const realpathCache = /* @__PURE__ */ new Map();
|
|
83
61
|
const gitRootCache = /* @__PURE__ */ new Map();
|
|
62
|
+
function getCachedGitDiff(key) {
|
|
63
|
+
const result = gitDiffCache.get(key);
|
|
64
|
+
if (result) {
|
|
65
|
+
gitDiffCache.delete(key);
|
|
66
|
+
gitDiffCache.set(key, result);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function stableKey(value) {
|
|
71
|
+
return JSON.stringify(value, (_key, val) => {
|
|
72
|
+
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
73
|
+
const sorted = {};
|
|
74
|
+
for (const k of Object.keys(val).sort()) {
|
|
75
|
+
sorted[k] = val[k];
|
|
76
|
+
}
|
|
77
|
+
return sorted;
|
|
78
|
+
}
|
|
79
|
+
return val;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
84
82
|
function getCachedRealpath(pathname) {
|
|
85
83
|
const fs = /* @__PURE__ */ getFs();
|
|
86
84
|
const cached = realpathCache.get(pathname);
|
|
@@ -90,22 +88,31 @@ function getCachedRealpath(pathname) {
|
|
|
90
88
|
}
|
|
91
89
|
realpathCache.delete(pathname);
|
|
92
90
|
}
|
|
93
|
-
|
|
91
|
+
let resolved;
|
|
92
|
+
try {
|
|
93
|
+
resolved = fs.realpathSync(pathname);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const code = error.code;
|
|
96
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
resolved = pathname;
|
|
100
|
+
}
|
|
94
101
|
realpathCache.set(pathname, resolved);
|
|
95
102
|
return resolved;
|
|
96
103
|
}
|
|
97
|
-
function getGitPath() {
|
|
98
|
-
if (_gitPath === void 0) {
|
|
99
|
-
const resolved = (0, import_bin.whichSync)("git", { nothrow: true });
|
|
100
|
-
_gitPath = typeof resolved === "string" ? resolved : "git";
|
|
101
|
-
}
|
|
102
|
-
return _gitPath;
|
|
103
|
-
}
|
|
104
104
|
function getCwd() {
|
|
105
|
-
return (
|
|
105
|
+
return getCachedRealpath(import_node_process.default.cwd());
|
|
106
|
+
}
|
|
107
|
+
// @__NO_SIDE_EFFECTS__
|
|
108
|
+
function getFs() {
|
|
109
|
+
if (_fs === void 0) {
|
|
110
|
+
_fs = require("node:fs");
|
|
111
|
+
}
|
|
112
|
+
return _fs;
|
|
106
113
|
}
|
|
107
114
|
function getGitDiffSpawnArgs(cwd) {
|
|
108
|
-
const resolvedCwd = cwd ? (
|
|
115
|
+
const resolvedCwd = cwd ? getCachedRealpath(cwd) : getCwd();
|
|
109
116
|
return {
|
|
110
117
|
all: [
|
|
111
118
|
getGitPath(),
|
|
@@ -130,11 +137,25 @@ function getGitDiffSpawnArgs(cwd) {
|
|
|
130
137
|
]
|
|
131
138
|
};
|
|
132
139
|
}
|
|
140
|
+
function getGitPath() {
|
|
141
|
+
if (_gitPath === void 0) {
|
|
142
|
+
const resolved = (0, import_bin.whichSync)("git", { nothrow: true });
|
|
143
|
+
_gitPath = typeof resolved === "string" ? resolved : "git";
|
|
144
|
+
}
|
|
145
|
+
return _gitPath;
|
|
146
|
+
}
|
|
147
|
+
// @__NO_SIDE_EFFECTS__
|
|
148
|
+
function getPath() {
|
|
149
|
+
if (_path === void 0) {
|
|
150
|
+
_path = require("node:path");
|
|
151
|
+
}
|
|
152
|
+
return _path;
|
|
153
|
+
}
|
|
133
154
|
async function innerDiff(args, options) {
|
|
134
155
|
const { cache = true, ...parseOptions } = { __proto__: null, ...options };
|
|
135
|
-
const cacheKey = cache ?
|
|
156
|
+
const cacheKey = cache ? stableKey({ args, parseOptions }) : void 0;
|
|
136
157
|
if (cache && cacheKey) {
|
|
137
|
-
const result2 =
|
|
158
|
+
const result2 = getCachedGitDiff(cacheKey);
|
|
138
159
|
if (result2) {
|
|
139
160
|
return result2;
|
|
140
161
|
}
|
|
@@ -156,17 +177,15 @@ async function innerDiff(args, options) {
|
|
|
156
177
|
return [];
|
|
157
178
|
}
|
|
158
179
|
if (cache && cacheKey) {
|
|
159
|
-
|
|
160
|
-
gitDiffCache.set(cacheKey, result);
|
|
161
|
-
gitDiffAccessOrder.push(cacheKey);
|
|
180
|
+
setCachedGitDiff(cacheKey, result);
|
|
162
181
|
}
|
|
163
182
|
return result;
|
|
164
183
|
}
|
|
165
184
|
function innerDiffSync(args, options) {
|
|
166
185
|
const { cache = true, ...parseOptions } = { __proto__: null, ...options };
|
|
167
|
-
const cacheKey = cache ?
|
|
186
|
+
const cacheKey = cache ? stableKey({ args, parseOptions }) : void 0;
|
|
168
187
|
if (cache && cacheKey) {
|
|
169
|
-
const result2 =
|
|
188
|
+
const result2 = getCachedGitDiff(cacheKey);
|
|
170
189
|
if (result2) {
|
|
171
190
|
return result2;
|
|
172
191
|
}
|
|
@@ -188,39 +207,10 @@ function innerDiffSync(args, options) {
|
|
|
188
207
|
return [];
|
|
189
208
|
}
|
|
190
209
|
if (cache && cacheKey) {
|
|
191
|
-
|
|
192
|
-
gitDiffCache.set(cacheKey, result);
|
|
193
|
-
gitDiffAccessOrder.push(cacheKey);
|
|
210
|
+
setCachedGitDiff(cacheKey, result);
|
|
194
211
|
}
|
|
195
212
|
return result;
|
|
196
213
|
}
|
|
197
|
-
function findGitRoot(startPath) {
|
|
198
|
-
const fs = /* @__PURE__ */ getFs();
|
|
199
|
-
const path = /* @__PURE__ */ getPath();
|
|
200
|
-
const cached = gitRootCache.get(startPath);
|
|
201
|
-
if (cached) {
|
|
202
|
-
if (fs.existsSync(path.join(cached, ".git"))) {
|
|
203
|
-
return cached;
|
|
204
|
-
}
|
|
205
|
-
gitRootCache.delete(startPath);
|
|
206
|
-
}
|
|
207
|
-
let currentPath = startPath;
|
|
208
|
-
while (true) {
|
|
209
|
-
try {
|
|
210
|
-
const gitPath = path.join(currentPath, ".git");
|
|
211
|
-
if (fs.existsSync(gitPath)) {
|
|
212
|
-
gitRootCache.set(startPath, currentPath);
|
|
213
|
-
return currentPath;
|
|
214
|
-
}
|
|
215
|
-
} catch {
|
|
216
|
-
}
|
|
217
|
-
const parentPath = path.dirname(currentPath);
|
|
218
|
-
if (parentPath === currentPath) {
|
|
219
|
-
return startPath;
|
|
220
|
-
}
|
|
221
|
-
currentPath = parentPath;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
214
|
function parseGitDiffStdout(stdout, options, spawnCwd) {
|
|
225
215
|
const defaultRoot = spawnCwd ? findGitRoot(spawnCwd) : getCwd();
|
|
226
216
|
const {
|
|
@@ -232,7 +222,7 @@ function parseGitDiffStdout(stdout, options, spawnCwd) {
|
|
|
232
222
|
const path = /* @__PURE__ */ getPath();
|
|
233
223
|
const cwd = cwdOption === defaultRoot ? defaultRoot : getCachedRealpath(cwdOption);
|
|
234
224
|
const rootPath = defaultRoot;
|
|
235
|
-
let rawFiles = stdout ? (0, import_strings.stripAnsi)(stdout).split(
|
|
225
|
+
let rawFiles = stdout ? (0, import_strings.stripAnsi)(stdout).split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line) : [];
|
|
236
226
|
if (porcelain) {
|
|
237
227
|
rawFiles = rawFiles.map((line) => {
|
|
238
228
|
return line.length > 3 ? line.substring(3) : line;
|
|
@@ -256,6 +246,42 @@ function parseGitDiffStdout(stdout, options, spawnCwd) {
|
|
|
256
246
|
}
|
|
257
247
|
return filtered;
|
|
258
248
|
}
|
|
249
|
+
function setCachedGitDiff(key, result) {
|
|
250
|
+
if (gitDiffCache.size >= GIT_CACHE_MAX_SIZE) {
|
|
251
|
+
const oldest = gitDiffCache.keys().next().value;
|
|
252
|
+
if (oldest !== void 0) {
|
|
253
|
+
gitDiffCache.delete(oldest);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
gitDiffCache.set(key, result);
|
|
257
|
+
}
|
|
258
|
+
function findGitRoot(startPath) {
|
|
259
|
+
const fs = /* @__PURE__ */ getFs();
|
|
260
|
+
const path = /* @__PURE__ */ getPath();
|
|
261
|
+
const cached = gitRootCache.get(startPath);
|
|
262
|
+
if (cached) {
|
|
263
|
+
if (fs.existsSync(path.join(cached, ".git"))) {
|
|
264
|
+
return cached;
|
|
265
|
+
}
|
|
266
|
+
gitRootCache.delete(startPath);
|
|
267
|
+
}
|
|
268
|
+
let currentPath = startPath;
|
|
269
|
+
while (true) {
|
|
270
|
+
try {
|
|
271
|
+
const gitPath = path.join(currentPath, ".git");
|
|
272
|
+
if (fs.existsSync(gitPath)) {
|
|
273
|
+
gitRootCache.set(startPath, currentPath);
|
|
274
|
+
return currentPath;
|
|
275
|
+
}
|
|
276
|
+
} catch {
|
|
277
|
+
}
|
|
278
|
+
const parentPath = path.dirname(currentPath);
|
|
279
|
+
if (parentPath === currentPath) {
|
|
280
|
+
return startPath;
|
|
281
|
+
}
|
|
282
|
+
currentPath = parentPath;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
259
285
|
async function getChangedFiles(options) {
|
|
260
286
|
const args = getGitDiffSpawnArgs(options?.cwd).all;
|
|
261
287
|
return await innerDiff(args, {
|
|
@@ -272,14 +298,6 @@ function getChangedFilesSync(options) {
|
|
|
272
298
|
porcelain: true
|
|
273
299
|
});
|
|
274
300
|
}
|
|
275
|
-
async function getUnstagedFiles(options) {
|
|
276
|
-
const args = getGitDiffSpawnArgs(options?.cwd).unstaged;
|
|
277
|
-
return await innerDiff(args, options);
|
|
278
|
-
}
|
|
279
|
-
function getUnstagedFilesSync(options) {
|
|
280
|
-
const args = getGitDiffSpawnArgs(options?.cwd).unstaged;
|
|
281
|
-
return innerDiffSync(args, options);
|
|
282
|
-
}
|
|
283
301
|
async function getStagedFiles(options) {
|
|
284
302
|
const args = getGitDiffSpawnArgs(options?.cwd).staged;
|
|
285
303
|
return await innerDiff(args, options);
|
|
@@ -288,6 +306,14 @@ function getStagedFilesSync(options) {
|
|
|
288
306
|
const args = getGitDiffSpawnArgs(options?.cwd).staged;
|
|
289
307
|
return innerDiffSync(args, options);
|
|
290
308
|
}
|
|
309
|
+
async function getUnstagedFiles(options) {
|
|
310
|
+
const args = getGitDiffSpawnArgs(options?.cwd).unstaged;
|
|
311
|
+
return await innerDiff(args, options);
|
|
312
|
+
}
|
|
313
|
+
function getUnstagedFilesSync(options) {
|
|
314
|
+
const args = getGitDiffSpawnArgs(options?.cwd).unstaged;
|
|
315
|
+
return innerDiffSync(args, options);
|
|
316
|
+
}
|
|
291
317
|
async function isChanged(pathname, options) {
|
|
292
318
|
const files = await getChangedFiles({
|
|
293
319
|
__proto__: null,
|
|
@@ -316,8 +342,8 @@ function isChangedSync(pathname, options) {
|
|
|
316
342
|
return false;
|
|
317
343
|
}
|
|
318
344
|
}
|
|
319
|
-
async function
|
|
320
|
-
const files = await
|
|
345
|
+
async function isStaged(pathname, options) {
|
|
346
|
+
const files = await getStagedFiles({
|
|
321
347
|
__proto__: null,
|
|
322
348
|
...options,
|
|
323
349
|
absolute: false
|
|
@@ -328,8 +354,8 @@ async function isUnstaged(pathname, options) {
|
|
|
328
354
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
329
355
|
return files.includes(relativePath);
|
|
330
356
|
}
|
|
331
|
-
function
|
|
332
|
-
const files =
|
|
357
|
+
function isStagedSync(pathname, options) {
|
|
358
|
+
const files = getStagedFilesSync({
|
|
333
359
|
__proto__: null,
|
|
334
360
|
...options,
|
|
335
361
|
absolute: false
|
|
@@ -340,8 +366,8 @@ function isUnstagedSync(pathname, options) {
|
|
|
340
366
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
341
367
|
return files.includes(relativePath);
|
|
342
368
|
}
|
|
343
|
-
async function
|
|
344
|
-
const files = await
|
|
369
|
+
async function isUnstaged(pathname, options) {
|
|
370
|
+
const files = await getUnstagedFiles({
|
|
345
371
|
__proto__: null,
|
|
346
372
|
...options,
|
|
347
373
|
absolute: false
|
|
@@ -352,8 +378,8 @@ async function isStaged(pathname, options) {
|
|
|
352
378
|
const relativePath = (0, import_normalize.normalizePath)(path.relative(baseCwd, resolvedPathname));
|
|
353
379
|
return files.includes(relativePath);
|
|
354
380
|
}
|
|
355
|
-
function
|
|
356
|
-
const files =
|
|
381
|
+
function isUnstagedSync(pathname, options) {
|
|
382
|
+
const files = getUnstagedFilesSync({
|
|
357
383
|
__proto__: null,
|
|
358
384
|
...options,
|
|
359
385
|
absolute: false
|