Skip to content

Commit 5f2fcfa

Browse files
committed
lint fix/prettier
1 parent 923645e commit 5f2fcfa

File tree

3 files changed

+104
-77
lines changed

3 files changed

+104
-77
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ socket --help
2121
- `socket optimize` - Optimize dependencies with
2222
[`@socketregistry`](https://github.com/SocketDev/socket-registry) overrides!
2323
_(👀 [our blog post](https://socket.dev/blog/introducing-socket-optimize))_
24+
2425
- `--pin` - Pin overrides to their latest version.
2526
- `--prod` - Add overrides for only production dependencies.
2627

@@ -95,7 +96,8 @@ npm run build:dist
9596
npm exec socket
9697
```
9798

98-
That should invoke it from local sources. If you make changes you run `build:dist` again.
99+
That should invoke it from local sources. If you make changes you run
100+
`build:dist` again.
99101

100102
### Environment variables for development
101103

src/commands/sbom/index.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { scala } from './scala'
55

66
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
77

8-
const description = 'Generate a "Software Bill of Materials" for given file or dir'
9-
const help = (name:string) => `
8+
const description =
9+
'Generate a "Software Bill of Materials" for given file or dir'
10+
const help = (name: string) => `
1011
Usage
1112
1213
$ ${name} <language> <target>
@@ -24,7 +25,7 @@ const help = (name:string) => `
2425
Examples
2526
2627
$ ${name} ./build.sbt
27-
`;
28+
`
2829

2930
export const sbom: CliSubcommand = {
3031
description,
@@ -34,14 +35,11 @@ export const sbom: CliSubcommand = {
3435
// Note: this won't catch `socket sbom -xyz --help` sort of cases which
3536
// would fallback to the default meow help behavior. That's fine.
3637
if (argv.length === 0 || argv[0] === '--help') {
37-
meow(
38-
help(name),
39-
{
40-
argv: ['--help'] as const, // meow will exit() when --help is passed
41-
description,
42-
importMeta
43-
}
44-
)
38+
meow(help(name), {
39+
argv: ['--help'] as const, // meow will exit() when --help is passed
40+
description,
41+
importMeta
42+
})
4543
}
4644

4745
// argv = argv.filter(o => o !== '--help');

src/commands/sbom/scala.ts

Lines changed: 92 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import util from 'node:util';
2-
import fs from 'node:fs';
3-
import child_process from 'node:child_process';
4-
import path from 'node:path';
1+
import util from 'node:util'
2+
import fs from 'node:fs'
3+
import child_process from 'node:child_process'
4+
import path from 'node:path'
55

66
import meow from 'meow'
77
import { getFlagListOutput } from '../../utils/output-formatting.ts'
88
import { Spinner } from '@socketsecurity/registry/lib/spinner'
99

1010
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
1111

12-
type ListDescription = string | { description: string, type?: string, default?: string }
12+
type ListDescription =
13+
| string
14+
| { description: string; type?: string; default?: string }
1315

14-
const execp = util.promisify(child_process.exec);
15-
const renamep = util.promisify(fs.rename);
16+
const execp = util.promisify(child_process.exec)
17+
const renamep = util.promisify(fs.rename)
1618

17-
const description = 'Generate a "Software Bill of Materials" (`pom.xml`) from Scala\'s `build.sbt` file'
19+
const description =
20+
'Generate a "Software Bill of Materials" (`pom.xml`) from Scala\'s `build.sbt` file'
1821

1922
const sbomFlags: Record<string, ListDescription> = {
2023
bin: {
@@ -25,7 +28,8 @@ const sbomFlags: Record<string, ListDescription> = {
2528
out: {
2629
type: 'string',
2730
default: './socket.pom.xml',
28-
description: 'Path of output file; where to store the resulting sbom, see also --stdout'
31+
description:
32+
'Path of output file; where to store the resulting sbom, see also --stdout'
2933
},
3034
stdout: {
3135
type: 'boolean',
@@ -42,7 +46,7 @@ const sbomFlags: Record<string, ListDescription> = {
4246
}
4347
}
4448

45-
const help = (name:string, flags: Record<string, ListDescription>) => `
49+
const help = (name: string, flags: Record<string, ListDescription>) => `
4650
Usage
4751
$ ${name} [--sbt=path/to/sbt/binary] [--out=path/to/result] FILE|DIR
4852
@@ -73,78 +77,96 @@ const help = (name:string, flags: Record<string, ListDescription>) => `
7377
7478
$ ${name} ./build.sbt
7579
$ ${name} --bin=/usr/bin/sbt ./build.sbt
76-
`;
80+
`
7781

7882
export const scala: CliSubcommand = {
7983
description,
8084
async run(argv, importMeta, { parentName }) {
8185
const name = `${parentName} scala`
8286
// note: meow will exit if it prints the --help screen
83-
const cli = meow(
84-
help(name, sbomFlags),
85-
{
86-
argv: argv.length === 0 ? ['--help'] : argv,
87-
description,
88-
importMeta
89-
}
90-
)
87+
const cli = meow(help(name, sbomFlags), {
88+
argv: argv.length === 0 ? ['--help'] : argv,
89+
description,
90+
importMeta
91+
})
9192

9293
const target = cli.input[0]
9394

9495
if (!target) {
9596
// will exit.
96-
new Spinner().start('Parsing...').error(`Failure: Missing FILE|DIR argument. See \`${name} --help\` for details.`);
97-
process.exit(1);
97+
new Spinner()
98+
.start('Parsing...')
99+
.error(
100+
`Failure: Missing FILE|DIR argument. See \`${name} --help\` for details.`
101+
)
102+
process.exit(1)
98103
}
99104

100105
if (cli.input.length > 1) {
101106
// will exit.
102-
new Spinner().start('Parsing...').error(`Failure: Can only accept one FILE or DIR, received ${cli.input.length} (make sure to escape spaces!). See \`${name} --help\` for details.`);
103-
process.exit(1);
107+
new Spinner()
108+
.start('Parsing...')
109+
.error(
110+
`Failure: Can only accept one FILE or DIR, received ${cli.input.length} (make sure to escape spaces!). See \`${name} --help\` for details.`
111+
)
112+
process.exit(1)
104113
}
105114

106-
let bin:string = 'sbt'
115+
let bin: string = 'sbt'
107116
if (cli.flags['bin']) {
108117
bin = cli.flags['bin'] as string
109118
}
110119

111-
let out:string = './socket.pom.xml'
120+
let out: string = './socket.pom.xml'
112121
if (cli.flags['out']) {
113122
out = cli.flags['out'] as string
114123
}
115124
if (cli.flags['stdout']) {
116-
out = '-';
125+
out = '-'
117126
}
118127

119128
// TODO: we can make `-` (accept from stdin) work by storing it into /tmp
120129
if (target === '-') {
121-
new Spinner().start('Parsing...').error(`Failure: Currently source code from stdin is not supported. See \`${name} --help\` for details.`);
122-
process.exit(1);
130+
new Spinner()
131+
.start('Parsing...')
132+
.error(
133+
`Failure: Currently source code from stdin is not supported. See \`${name} --help\` for details.`
134+
)
135+
process.exit(1)
123136
}
124137

125-
const verbose = cli.flags['verbose'] as boolean ?? false;
138+
const verbose = (cli.flags['verbose'] as boolean) ?? false
126139

127-
let sbtOpts:Array<string> = [];
140+
let sbtOpts: Array<string> = []
128141
if (cli.flags['sbtOpts']) {
129-
sbtOpts = (cli.flags['sbtOpts'] as string).split(' ').map(s => s.trim()).filter(Boolean)
142+
sbtOpts = (cli.flags['sbtOpts'] as string)
143+
.split(' ')
144+
.map(s => s.trim())
145+
.filter(Boolean)
130146
}
131147

132-
await startConversion(target, bin, out, verbose, sbtOpts);
148+
await startConversion(target, bin, out, verbose, sbtOpts)
133149
}
134150
}
135151

136-
async function startConversion(target: string, bin: string, out: string, verbose: boolean, sbtOpts: Array<string>) {
137-
const spinner = new Spinner();
138-
139-
const rbin = path.resolve(bin);
140-
const rtarget = path.resolve(target);
141-
const rout = out === '-' ? '-' : path.resolve(out);
142-
143-
if (verbose){
144-
spinner.clear();
145-
console.log(`- Absolute bin path: \`${rbin}\``);
146-
console.log(`- Absolute target path: \`${rtarget}\``);
147-
console.log(`- Absolute out path: \`${rout}\``);
152+
async function startConversion(
153+
target: string,
154+
bin: string,
155+
out: string,
156+
verbose: boolean,
157+
sbtOpts: Array<string>
158+
) {
159+
const spinner = new Spinner()
160+
161+
const rbin = path.resolve(bin)
162+
const rtarget = path.resolve(target)
163+
const rout = out === '-' ? '-' : path.resolve(out)
164+
165+
if (verbose) {
166+
spinner.clear()
167+
console.log(`- Absolute bin path: \`${rbin}\``)
168+
console.log(`- Absolute target path: \`${rtarget}\``)
169+
console.log(`- Absolute out path: \`${rout}\``)
148170
}
149171

150172
spinner.start(`Running sbt from \`${bin}\` on \`${target}\`...`)
@@ -153,50 +175,55 @@ async function startConversion(target: string, bin: string, out: string, verbose
153175
// We must now run sbt, pick the generated xml from the /target folder (the stdout should tell you the location upon success) and store it somewhere else.
154176
// TODO: Not sure what this somewhere else might be tbh.
155177

156-
const output = await execp(bin +` makePom ${sbtOpts.join(' ')}`, {cwd: target || '.'});
157-
spinner.success();
178+
const output = await execp(bin + ` makePom ${sbtOpts.join(' ')}`, {
179+
cwd: target || '.'
180+
})
181+
spinner.success()
158182
if (verbose) {
159183
console.group('sbt stdout:')
160-
console.log(output);
161-
console.groupEnd();
184+
console.log(output)
185+
console.groupEnd()
162186
}
163187

164188
if (output.stderr) {
165-
spinner.error('There were errors while running sbt');
189+
spinner.error('There were errors while running sbt')
166190
// (In verbose mode, stderr was printed above, no need to repeat it)
167-
if (!verbose) console.error(output.stderr);
168-
process.exit(1);
191+
if (!verbose) console.error(output.stderr)
192+
process.exit(1)
169193
}
170194

171-
const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim();
195+
const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
172196
if (!loc) {
173-
spinner.error('There were no errors from sbt but could not find the location of resulting .pom file either');
174-
process.exit(1);
197+
spinner.error(
198+
'There were no errors from sbt but could not find the location of resulting .pom file either'
199+
)
200+
process.exit(1)
175201
}
176202

177203
// Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
178204
if (out === '-') {
179-
spinner.start('Result:\n```').success();
180-
console.log(fs.readFileSync(loc, 'utf8'));
205+
spinner.start('Result:\n```').success()
206+
console.log(fs.readFileSync(loc, 'utf8'))
181207
console.log('```')
182-
spinner.start().success(`OK`);
208+
spinner.start().success(`OK`)
183209
} else {
184210
if (verbose) {
185-
spinner.start(`Moving sbom file from \`${loc.replace(/^\/home\/[^\/]*?\//, '~/')}\` to \`${out}\``);
211+
spinner.start(
212+
`Moving sbom file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
213+
)
186214
} else {
187-
spinner.start('Moving output pom file');
215+
spinner.start('Moving output pom file')
188216
}
189217
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
190-
await renamep(loc, out);
191-
spinner.success();
192-
spinner.start().success(`OK. File should be available in \`${out}\``);
218+
await renamep(loc, out)
219+
spinner.success()
220+
spinner.start().success(`OK. File should be available in \`${out}\``)
193221
}
194222
} catch (e) {
195223
spinner.error('There was an unexpected error while running this')
196224
if (verbose) {
197-
console.log(e);
225+
console.log(e)
198226
}
199-
process.exit(1);
227+
process.exit(1)
200228
}
201-
202229
}

0 commit comments

Comments
 (0)