Skip to content

Commit 7315920

Browse files
committed
Spawn trims and strips ansi by default now
1 parent d8de9c3 commit 7315920

35 files changed

+382
-407
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"@socketregistry/is-interactive": "1.0.6",
112112
"@socketregistry/packageurl-js": "1.0.8",
113113
"@socketsecurity/config": "3.0.1",
114-
"@socketsecurity/registry": "1.0.218",
114+
"@socketsecurity/registry": "1.0.219",
115115
"@socketsecurity/sdk": "1.4.51",
116116
"@types/blessed": "0.1.25",
117117
"@types/cmd-shim": "5.0.2",

src/commands/analytics/cmd-analytics.test.mts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ describe('socket analytics', async () => {
7575
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
7676
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>
7777
78-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
78+
\\xd7 Input error: Please review the input requirements and try again
7979
80-
- The time filter must either be 7, 30 or 90 (\\x1b[32mok\\x1b[39m)
80+
- The time filter must either be 7, 30 or 90 (ok)
8181
82-
- You need to be logged in to use this command. See \`socket login\`. (\\x1b[31mmissing API token\\x1b[39m)
83-
\\x1b[22m"
82+
- You need to be logged in to use this command. See \`socket login\`. (missing API token)
83+
"
8484
`)
8585

8686
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)
@@ -109,12 +109,12 @@ describe('socket analytics', async () => {
109109
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
110110
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>
111111
112-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
112+
\\xd7 Input error: Please review the input requirements and try again
113113
114-
- Legacy flags are no longer supported. See v1 migration guide. (\\x1b[31mreceived legacy flags\\x1b[39m)
114+
- Legacy flags are no longer supported. See v1 migration guide. (received legacy flags)
115115
116-
- The time filter must either be 7, 30 or 90 (\\x1b[32mok\\x1b[39m)
117-
\\x1b[22m"
116+
- The time filter must either be 7, 30 or 90 (ok)
117+
"
118118
`)
119119

120120
expect(code, 'dry-run should reject legacy flags with code 2').toBe(2)
@@ -170,12 +170,12 @@ describe('socket analytics', async () => {
170170
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
171171
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>
172172
173-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
173+
\\xd7 Input error: Please review the input requirements and try again
174174
175-
- When scope=repo, repo name should be the second argument (\\x1b[31mmissing\\x1b[39m)
175+
- When scope=repo, repo name should be the second argument (missing)
176176
177-
- The time filter must either be 7, 30 or 90 (\\x1b[32mok\\x1b[39m)
178-
\\x1b[22m"
177+
- The time filter must either be 7, 30 or 90 (ok)
178+
"
179179
`)
180180

181181
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)
@@ -282,12 +282,12 @@ describe('socket analytics', async () => {
282282
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
283283
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>
284284
285-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
285+
\\xd7 Input error: Please review the input requirements and try again
286286
287-
- Legacy flags are no longer supported. See v1 migration guide. (\\x1b[31mreceived legacy flags\\x1b[39m)
287+
- Legacy flags are no longer supported. See v1 migration guide. (received legacy flags)
288288
289-
- The time filter must either be 7, 30 or 90 (\\x1b[32mok\\x1b[39m)
290-
\\x1b[22m"
289+
- The time filter must either be 7, 30 or 90 (ok)
290+
"
291291
`)
292292

293293
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)

src/commands/audit-log/cmd-audit-log.test.mts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ describe('socket audit-log', async () => {
7979
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
8080
|_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: <redacted>
8181
82-
\\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now...
83-
\\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag.
82+
\\u203c Unable to determine the target org. Trying to auto-discover it now...
83+
i Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag.
8484
85-
\\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode
86-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
85+
\\xd7 Skipping auto-discovery of org in dry-run mode
86+
\\xd7 Input error: Please review the input requirements and try again
8787
88-
- Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m)
89-
\\x1b[22m"
88+
- Org name by default setting, --org, or auto-discovered (missing)
89+
"
9090
`)
9191

9292
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)
@@ -113,10 +113,10 @@ describe('socket audit-log', async () => {
113113
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
114114
|_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: <redacted>
115115
116-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
116+
\\xd7 Input error: Please review the input requirements and try again
117117
118-
- Legacy flags are no longer supported. See v1 migration guide. (\\x1b[31mreceived legacy flags\\x1b[39m)
119-
\\x1b[22m"
118+
- Legacy flags are no longer supported. See v1 migration guide. (received legacy flags)
119+
"
120120
`)
121121

122122
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)

src/commands/config/cmd-config-get.test.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ describe('socket config get', async () => {
7575
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
7676
|_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: <redacted>
7777
78-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
78+
\\xd7 Input error: Please review the input requirements and try again
7979
80-
- Config key should be the first arg (\\x1b[31mmissing\\x1b[39m)
81-
\\x1b[22m"
80+
- Config key should be the first arg (missing)
81+
"
8282
`)
8383

8484
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)

src/commands/config/cmd-config-set.test.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ describe('socket config get', async () => {
7676
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
7777
|_____|___|___|_,_|___|_|.dev | Command: \`socket config set\`, cwd: <redacted>
7878
79-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
79+
\\xd7 Input error: Please review the input requirements and try again
8080
81-
- Config key should be the first arg (\\x1b[31mmissing\\x1b[39m)
81+
- Config key should be the first arg (missing)
8282
83-
- Key value should be the remaining args (use \`unset\` to unset a value) (\\x1b[31mmissing\\x1b[39m)
84-
\\x1b[22m"
83+
- Key value should be the remaining args (use \`unset\` to unset a value) (missing)
84+
"
8585
`)
8686

8787
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)

src/commands/config/cmd-config-unset.test.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ describe('socket config unset', async () => {
7070
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
7171
|_____|___|___|_,_|___|_|.dev | Command: \`socket config unset\`, cwd: <redacted>
7272
73-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again
73+
\\xd7 Input error: Please review the input requirements and try again
7474
75-
- Config key should be the first arg (\\x1b[31mmissing\\x1b[39m)
76-
\\x1b[22m"
75+
- Config key should be the first arg (missing)
76+
"
7777
`)
7878

7979
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)

src/commands/config/cmd-config.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('socket config', async () => {
8585
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
8686
|_____|___|___|_,_|___|_|.dev | Command: \`socket\`, cwd: <redacted>
8787
88-
\\x1b[31m\\xd7\\x1b[39m Could not parse Config as JSON"
88+
\\xd7 Could not parse Config as JSON"
8989
`)
9090

9191
expect(stderr.includes('Could not parse Config as JSON')).toBe(true)
@@ -106,7 +106,7 @@ describe('socket config', async () => {
106106
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
107107
|_____|___|___|_,_|___|_|.dev | Command: \`socket\`, cwd: <redacted>
108108
109-
\\x1b[31m\\xd7\\x1b[39m Could not parse Config as JSON"
109+
\\xd7 Could not parse Config as JSON"
110110
`)
111111

112112
expect(stderr.includes('Could not parse Config as JSON')).toBe(true)

src/commands/fix/git.mts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { debugFn } from '@socketsecurity/registry/lib/debug'
55
import { normalizePath } from '@socketsecurity/registry/lib/path'
66
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
77
import { spawn } from '@socketsecurity/registry/lib/spawn'
8-
import { stripAnsi } from '@socketsecurity/registry/lib/strings'
98

109
import constants from '../../constants.mts'
1110
import { getPurlObject } from '../../utils/purl.mts'
@@ -88,10 +87,11 @@ export async function getBaseGitBranch(cwd = process.cwd()): Promise<string> {
8887
// 3. Try to resolve the default remote branch using 'git remote show origin'.
8988
// This handles detached HEADs or workflows triggered by tags/releases.
9089
try {
91-
const stdout = stripAnsi(
92-
(await spawn('git', ['remote', 'show', 'origin'], { cwd })).stdout.trim(),
93-
)
94-
const match = /(?<=HEAD branch: ).+/.exec(stdout)
90+
const originDetails = (
91+
await spawn('git', ['remote', 'show', 'origin'], { cwd })
92+
).stdout
93+
94+
const match = /(?<=HEAD branch: ).+/.exec(originDetails)
9595
if (match?.[0]) {
9696
return match[0].trim()
9797
}
@@ -266,11 +266,9 @@ export async function gitRepoInfo(
266266
cwd = process.cwd(),
267267
): Promise<RepoInfo | null> {
268268
try {
269-
const remoteUrl = stripAnsi(
270-
(
271-
await spawn('git', ['remote', 'get-url', 'origin'], { cwd })
272-
).stdout.trim(),
273-
)
269+
const remoteUrl = (
270+
await spawn('git', ['remote', 'get-url', 'origin'], { cwd })
271+
).stdout
274272
// 1. Handle SSH-style, e.g. git@github.com:owner/repo.git
275273
const sshMatch = /^git@[^:]+:([^/]+)\/(.+?)(?:\.git)?$/.exec(remoteUrl)
276274
if (sshMatch) {
@@ -309,11 +307,9 @@ export async function gitEnsureIdentity(
309307
let configValue
310308
try {
311309
// Will throw with exit code 1 if the config property is not set.
312-
configValue = stripAnsi(
313-
(
314-
await spawn('git', ['config', '--get', prop], stdioPipeOptions)
315-
).stdout.trim(),
316-
)
310+
configValue = (
311+
await spawn('git', ['config', '--get', prop], stdioPipeOptions)
312+
).stdout
317313
} catch {}
318314
if (configValue !== value) {
319315
try {
@@ -333,19 +329,16 @@ export async function gitRemoteBranchExists(
333329
const stdioPipeOptions: SpawnOptions = { cwd }
334330
try {
335331
return (
336-
stripAnsi(
337-
(
338-
await spawn(
339-
'git',
340-
['ls-remote', '--heads', 'origin', branch],
341-
stdioPipeOptions,
342-
)
343-
).stdout.trim(),
344-
).length > 0
332+
(
333+
await spawn(
334+
'git',
335+
['ls-remote', '--heads', 'origin', branch],
336+
stdioPipeOptions,
337+
)
338+
).stdout.length > 0
345339
)
346-
} catch {
347-
return false
348-
}
340+
} catch {}
341+
return false
349342
}
350343

351344
export async function gitResetAndClean(
@@ -371,13 +364,14 @@ export async function gitUnstagedModifiedFiles(
371364
): Promise<CResult<string[]>> {
372365
try {
373366
const stdioPipeOptions: SpawnOptions = { cwd }
374-
const stdout = stripAnsi(
375-
(
376-
await spawn('git', ['diff', '--name-only'], stdioPipeOptions)
377-
).stdout.trim(),
378-
)
379-
const rawFiles = stdout.split('\n') ?? []
380-
return { ok: true, data: rawFiles.map(relPath => normalizePath(relPath)) }
367+
const changedFilesDetails = (
368+
await spawn('git', ['diff', '--name-only'], stdioPipeOptions)
369+
).stdout
370+
const rawRelPaths = changedFilesDetails.split('\n') ?? []
371+
return {
372+
ok: true,
373+
data: rawRelPaths.map(relPath => normalizePath(relPath)),
374+
}
381375
} catch (e) {
382376
debugFn('catch: git diff --name-only failed\n', e)
383377

src/commands/json/cmd-json.test.mts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ describe('socket json', async () => {
5252
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
5353
|_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: <redacted>
5454
55-
\\x1b[34mi\\x1b[39m Target cwd: <redacted>
56-
\\x1b[31m\\xd7\\x1b[39m Not found: <redacted>"
55+
i Target cwd: <redacted>
56+
\\xd7 Not found: <redacted>"
5757
`)
5858

5959
expect(code, 'not found is failure').toBe(1)
@@ -73,8 +73,8 @@ describe('socket json', async () => {
7373
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
7474
|_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: <redacted>
7575
76-
\\x1b[34mi\\x1b[39m Target cwd: <redacted>
77-
\\x1b[31m\\xd7\\x1b[39m Not found: <redacted>"
76+
i Target cwd: <redacted>
77+
\\xd7 Not found: <redacted>"
7878
`)
7979

8080
expect(code, 'not found is failure').toBe(1)
@@ -100,8 +100,8 @@ describe('socket json', async () => {
100100
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
101101
|_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: <redacted>
102102
103-
\\x1b[34mi\\x1b[39m Target cwd: <redacted>
104-
\\x1b[31m\\xd7\\x1b[39m Not found: <redacted>"
103+
i Target cwd: <redacted>
104+
\\xd7 Not found: <redacted>"
105105
`)
106106

107107
expect(code, 'not found is failure').toBe(1)
@@ -140,8 +140,8 @@ describe('socket json', async () => {
140140
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
141141
|_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: <redacted>
142142
143-
\\x1b[34mi\\x1b[39m Target cwd: <redacted>
144-
\\x1b[32m\\u221a\\x1b[39m This is the contents of <redacted>:"
143+
i Target cwd: <redacted>
144+
\\u221a This is the contents of <redacted>:"
145145
`)
146146

147147
expect(code, 'found is ok').toBe(0)

0 commit comments

Comments
 (0)