@socketsecurity/lib 5.5.3 → 5.7.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 +95 -1
- package/dist/cache-with-ttl.js +5 -1
- package/dist/dlx/binary.d.ts +47 -52
- package/dist/dlx/binary.js +129 -134
- package/dist/dlx/detect.d.ts +8 -8
- package/dist/dlx/detect.js +18 -18
- package/dist/dlx/manifest.d.ts +43 -36
- package/dist/dlx/manifest.js +114 -112
- package/dist/dlx/package.d.ts +55 -0
- package/dist/dlx/package.js +89 -79
- package/dist/env/ci.js +1 -2
- package/dist/env/rewire.d.ts +33 -22
- package/dist/env/rewire.js +20 -7
- package/dist/env/socket-cli.d.ts +24 -24
- package/dist/env/socket-cli.js +12 -12
- package/dist/env/temp-dir.d.ts +6 -6
- package/dist/env/temp-dir.js +4 -4
- package/dist/env/windows.d.ts +6 -6
- package/dist/env/windows.js +4 -4
- package/dist/external/libnpmexec.js +2 -2
- package/dist/github.js +10 -1
- package/dist/http-request.d.ts +79 -63
- package/dist/http-request.js +203 -159
- package/dist/packages/specs.js +1 -1
- package/dist/releases/github.d.ts +18 -7
- package/dist/releases/github.js +94 -92
- package/package.json +4 -4
package/dist/releases/github.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var github_exports = {};
|
|
31
31
|
__export(github_exports, {
|
|
32
32
|
SOCKET_BTM_REPO: () => SOCKET_BTM_REPO,
|
|
33
|
+
createAssetMatcher: () => createAssetMatcher,
|
|
33
34
|
downloadGitHubRelease: () => downloadGitHubRelease,
|
|
34
35
|
downloadReleaseAsset: () => downloadReleaseAsset,
|
|
35
36
|
getAuthHeaders: () => getAuthHeaders,
|
|
@@ -43,7 +44,6 @@ var import_http_request = require("../http-request.js");
|
|
|
43
44
|
var import_logger = require("../logger.js");
|
|
44
45
|
var import_promises = require("../promises.js");
|
|
45
46
|
var import_spawn = require("../spawn.js");
|
|
46
|
-
const logger = (0, import_logger.getDefaultLogger)();
|
|
47
47
|
const RETRY_CONFIG = Object.freeze({
|
|
48
48
|
__proto__: null,
|
|
49
49
|
// Exponential backoff: delay doubles with each retry (5s, 10s, 20s).
|
|
@@ -53,19 +53,13 @@ const RETRY_CONFIG = Object.freeze({
|
|
|
53
53
|
// Maximum number of retry attempts (excluding initial request).
|
|
54
54
|
retries: 2
|
|
55
55
|
});
|
|
56
|
+
const SOCKET_BTM_REPO = {
|
|
57
|
+
owner: "SocketDev",
|
|
58
|
+
repo: "socket-btm"
|
|
59
|
+
};
|
|
60
|
+
const logger = (0, import_logger.getDefaultLogger)();
|
|
56
61
|
let _fs;
|
|
57
62
|
let _path;
|
|
58
|
-
function createMatcher(pattern) {
|
|
59
|
-
if (typeof pattern === "string") {
|
|
60
|
-
const isMatch = (0, import_picomatch.default)(pattern);
|
|
61
|
-
return (input) => isMatch(input);
|
|
62
|
-
}
|
|
63
|
-
if (pattern instanceof RegExp) {
|
|
64
|
-
return (input) => pattern.test(input);
|
|
65
|
-
}
|
|
66
|
-
const { prefix, suffix } = pattern;
|
|
67
|
-
return (input) => input.startsWith(prefix) && input.endsWith(suffix);
|
|
68
|
-
}
|
|
69
63
|
// @__NO_SIDE_EFFECTS__
|
|
70
64
|
function getFs() {
|
|
71
65
|
if (_fs === void 0) {
|
|
@@ -80,10 +74,91 @@ function getPath() {
|
|
|
80
74
|
}
|
|
81
75
|
return _path;
|
|
82
76
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
function createAssetMatcher(pattern) {
|
|
78
|
+
if (typeof pattern === "string") {
|
|
79
|
+
const isMatch = (0, import_picomatch.default)(pattern);
|
|
80
|
+
return (input) => isMatch(input);
|
|
81
|
+
}
|
|
82
|
+
if (pattern instanceof RegExp) {
|
|
83
|
+
return (input) => pattern.test(input);
|
|
84
|
+
}
|
|
85
|
+
const { prefix, suffix } = pattern;
|
|
86
|
+
return (input) => input.startsWith(prefix) && input.endsWith(suffix);
|
|
87
|
+
}
|
|
88
|
+
async function downloadGitHubRelease(config) {
|
|
89
|
+
const {
|
|
90
|
+
assetName,
|
|
91
|
+
binaryName,
|
|
92
|
+
cwd = process.cwd(),
|
|
93
|
+
downloadDir = "build/downloaded",
|
|
94
|
+
owner,
|
|
95
|
+
platformArch,
|
|
96
|
+
quiet = false,
|
|
97
|
+
removeMacOSQuarantine = true,
|
|
98
|
+
repo,
|
|
99
|
+
tag: explicitTag,
|
|
100
|
+
toolName,
|
|
101
|
+
toolPrefix
|
|
102
|
+
} = config;
|
|
103
|
+
let tag;
|
|
104
|
+
if (explicitTag) {
|
|
105
|
+
tag = explicitTag;
|
|
106
|
+
} else if (toolPrefix) {
|
|
107
|
+
const latestTag = await getLatestRelease(
|
|
108
|
+
toolPrefix,
|
|
109
|
+
{ owner, repo },
|
|
110
|
+
{ quiet }
|
|
111
|
+
);
|
|
112
|
+
if (!latestTag) {
|
|
113
|
+
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
114
|
+
}
|
|
115
|
+
tag = latestTag;
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error("Either toolPrefix or tag must be provided");
|
|
118
|
+
}
|
|
119
|
+
const path = /* @__PURE__ */ getPath();
|
|
120
|
+
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
121
|
+
const binaryDir = path.join(resolvedDownloadDir, toolName, platformArch);
|
|
122
|
+
const binaryPath = path.join(binaryDir, binaryName);
|
|
123
|
+
const versionPath = path.join(binaryDir, ".version");
|
|
124
|
+
const fs = /* @__PURE__ */ getFs();
|
|
125
|
+
if (fs.existsSync(versionPath) && fs.existsSync(binaryPath)) {
|
|
126
|
+
const cachedVersion = (await fs.promises.readFile(versionPath, "utf8")).trim();
|
|
127
|
+
if (cachedVersion === tag && fs.existsSync(binaryPath)) {
|
|
128
|
+
if (!quiet) {
|
|
129
|
+
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
130
|
+
}
|
|
131
|
+
return binaryPath;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!quiet) {
|
|
135
|
+
logger.info(`Downloading ${toolName} for ${platformArch}...`);
|
|
136
|
+
}
|
|
137
|
+
await downloadReleaseAsset(
|
|
138
|
+
tag,
|
|
139
|
+
assetName,
|
|
140
|
+
binaryPath,
|
|
141
|
+
{ owner, repo },
|
|
142
|
+
{ quiet }
|
|
143
|
+
);
|
|
144
|
+
const isWindows = binaryName.endsWith(".exe");
|
|
145
|
+
if (!isWindows) {
|
|
146
|
+
fs.chmodSync(binaryPath, 493);
|
|
147
|
+
if (removeMacOSQuarantine && process.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
148
|
+
try {
|
|
149
|
+
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
150
|
+
stdio: "ignore"
|
|
151
|
+
});
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
await fs.promises.writeFile(versionPath, tag, "utf8");
|
|
157
|
+
if (!quiet) {
|
|
158
|
+
logger.info(`Downloaded ${toolName} to ${binaryPath}`);
|
|
159
|
+
}
|
|
160
|
+
return binaryPath;
|
|
161
|
+
}
|
|
87
162
|
async function downloadReleaseAsset(tag, assetPattern, outputPath, repoConfig, options = {}) {
|
|
88
163
|
const { owner, repo } = repoConfig;
|
|
89
164
|
const { quiet = false } = options;
|
|
@@ -120,7 +195,7 @@ function getAuthHeaders() {
|
|
|
120
195
|
async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
121
196
|
const { assetPattern, quiet = false } = options;
|
|
122
197
|
const { owner, repo } = repoConfig;
|
|
123
|
-
const isMatch = assetPattern ?
|
|
198
|
+
const isMatch = assetPattern ? createAssetMatcher(assetPattern) : void 0;
|
|
124
199
|
return await (0, import_promises.pRetry)(
|
|
125
200
|
async () => {
|
|
126
201
|
const response = await (0, import_http_request.httpRequest)(
|
|
@@ -188,7 +263,7 @@ async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
|
188
263
|
async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
189
264
|
const { owner, repo } = repoConfig;
|
|
190
265
|
const { quiet = false } = options;
|
|
191
|
-
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern :
|
|
266
|
+
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern : createAssetMatcher(assetPattern);
|
|
192
267
|
return await (0, import_promises.pRetry)(
|
|
193
268
|
async () => {
|
|
194
269
|
const response = await (0, import_http_request.httpRequest)(
|
|
@@ -229,83 +304,10 @@ async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
|
229
304
|
}
|
|
230
305
|
);
|
|
231
306
|
}
|
|
232
|
-
async function downloadGitHubRelease(config) {
|
|
233
|
-
const {
|
|
234
|
-
assetName,
|
|
235
|
-
binaryName,
|
|
236
|
-
cwd = process.cwd(),
|
|
237
|
-
downloadDir = "build/downloaded",
|
|
238
|
-
owner,
|
|
239
|
-
platformArch,
|
|
240
|
-
quiet = false,
|
|
241
|
-
removeMacOSQuarantine = true,
|
|
242
|
-
repo,
|
|
243
|
-
tag: explicitTag,
|
|
244
|
-
toolName,
|
|
245
|
-
toolPrefix
|
|
246
|
-
} = config;
|
|
247
|
-
let tag;
|
|
248
|
-
if (explicitTag) {
|
|
249
|
-
tag = explicitTag;
|
|
250
|
-
} else if (toolPrefix) {
|
|
251
|
-
const latestTag = await getLatestRelease(
|
|
252
|
-
toolPrefix,
|
|
253
|
-
{ owner, repo },
|
|
254
|
-
{ quiet }
|
|
255
|
-
);
|
|
256
|
-
if (!latestTag) {
|
|
257
|
-
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
258
|
-
}
|
|
259
|
-
tag = latestTag;
|
|
260
|
-
} else {
|
|
261
|
-
throw new Error("Either toolPrefix or tag must be provided");
|
|
262
|
-
}
|
|
263
|
-
const path = /* @__PURE__ */ getPath();
|
|
264
|
-
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
265
|
-
const binaryDir = path.join(resolvedDownloadDir, toolName, platformArch);
|
|
266
|
-
const binaryPath = path.join(binaryDir, binaryName);
|
|
267
|
-
const versionPath = path.join(binaryDir, ".version");
|
|
268
|
-
const fs = /* @__PURE__ */ getFs();
|
|
269
|
-
if (fs.existsSync(versionPath) && fs.existsSync(binaryPath)) {
|
|
270
|
-
const cachedVersion = (await fs.promises.readFile(versionPath, "utf8")).trim();
|
|
271
|
-
if (cachedVersion === tag) {
|
|
272
|
-
if (!quiet) {
|
|
273
|
-
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
274
|
-
}
|
|
275
|
-
return binaryPath;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (!quiet) {
|
|
279
|
-
logger.info(`Downloading ${toolName} for ${platformArch}...`);
|
|
280
|
-
}
|
|
281
|
-
await downloadReleaseAsset(
|
|
282
|
-
tag,
|
|
283
|
-
assetName,
|
|
284
|
-
binaryPath,
|
|
285
|
-
{ owner, repo },
|
|
286
|
-
{ quiet }
|
|
287
|
-
);
|
|
288
|
-
const isWindows = binaryName.endsWith(".exe");
|
|
289
|
-
if (!isWindows) {
|
|
290
|
-
fs.chmodSync(binaryPath, 493);
|
|
291
|
-
if (removeMacOSQuarantine && process.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
292
|
-
try {
|
|
293
|
-
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
294
|
-
stdio: "ignore"
|
|
295
|
-
});
|
|
296
|
-
} catch {
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
await fs.promises.writeFile(versionPath, tag, "utf8");
|
|
301
|
-
if (!quiet) {
|
|
302
|
-
logger.info(`Downloaded ${toolName} to ${binaryPath}`);
|
|
303
|
-
}
|
|
304
|
-
return binaryPath;
|
|
305
|
-
}
|
|
306
307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
307
308
|
0 && (module.exports = {
|
|
308
309
|
SOCKET_BTM_REPO,
|
|
310
|
+
createAssetMatcher,
|
|
309
311
|
downloadGitHubRelease,
|
|
310
312
|
downloadReleaseAsset,
|
|
311
313
|
getAuthHeaders,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/lib",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"packageManager": "pnpm@10.
|
|
3
|
+
"version": "5.7.0",
|
|
4
|
+
"packageManager": "pnpm@10.29.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Core utilities and infrastructure for Socket.dev security tools",
|
|
7
7
|
"keywords": [
|
|
@@ -730,7 +730,7 @@
|
|
|
730
730
|
"@socketregistry/is-unicode-supported": "1.0.5",
|
|
731
731
|
"@socketregistry/packageurl-js": "1.3.5",
|
|
732
732
|
"@socketregistry/yocto-spinner": "1.0.25",
|
|
733
|
-
"@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.5.
|
|
733
|
+
"@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.5.3",
|
|
734
734
|
"@types/node": "24.9.2",
|
|
735
735
|
"@typescript/native-preview": "7.0.0-dev.20250920.1",
|
|
736
736
|
"@vitest/coverage-v8": "4.0.3",
|
|
@@ -754,7 +754,7 @@
|
|
|
754
754
|
"globals": "16.4.0",
|
|
755
755
|
"has-flag": "5.0.1",
|
|
756
756
|
"husky": "9.1.7",
|
|
757
|
-
"libnpmexec": "^10.
|
|
757
|
+
"libnpmexec": "^10.2.0",
|
|
758
758
|
"libnpmpack": "9.0.9",
|
|
759
759
|
"lint-staged": "15.2.11",
|
|
760
760
|
"magic-string": "0.30.17",
|