-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcmd-patch.mts
More file actions
57 lines (46 loc) · 1.43 KB
/
cmd-patch.mts
File metadata and controls
57 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { runPatch } from '@socketsecurity/socket-patch/run'
import constants from '../../constants.mts'
import type { CliCommandContext } from '../../utils/meow-with-subcommands.mts'
export const CMD_NAME = 'patch'
const description = 'Manage CVE patches for dependencies'
const hidden = false
export const cmdPatch = {
description,
hidden,
run,
}
async function run(
argv: string[] | readonly string[],
_importMeta: ImportMeta,
_context: CliCommandContext,
): Promise<void> {
const { ENV } = constants
// Map socket-cli environment to socket-patch options.
// Only include properties with defined values (exactOptionalPropertyTypes).
const options: Parameters<typeof runPatch>[1] = {}
// Strip /v0/ suffix from API URL if present.
const apiUrl = ENV.SOCKET_CLI_API_BASE_URL?.replace(/\/v0\/?$/, '')
if (apiUrl) {
options.apiUrl = apiUrl
}
if (ENV.SOCKET_CLI_API_TOKEN) {
options.apiToken = ENV.SOCKET_CLI_API_TOKEN
}
if (ENV.SOCKET_CLI_ORG_SLUG) {
options.orgSlug = ENV.SOCKET_CLI_ORG_SLUG
}
if (ENV.SOCKET_PATCH_PROXY_URL) {
options.patchProxyUrl = ENV.SOCKET_PATCH_PROXY_URL
}
if (ENV.SOCKET_CLI_API_PROXY) {
options.httpProxy = ENV.SOCKET_CLI_API_PROXY
}
if (ENV.SOCKET_CLI_DEBUG) {
options.debug = ENV.SOCKET_CLI_DEBUG
}
// Forward all arguments to socket-patch.
const exitCode = await runPatch([...argv], options)
if (exitCode !== 0) {
process.exitCode = exitCode
}
}