Skip to content

Commit 2897645

Browse files
committed
Reuse spinner
1 parent 8252840 commit 2897645

27 files changed

+109
-110
lines changed

.dep-stats.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@socketregistry/is-unicode-supported": "^1.0.1",
1111
"@socketregistry/packageurl-js": "^1.0.2",
1212
"@socketsecurity/config": "^2.1.3",
13-
"@socketsecurity/registry": "^1.0.107",
13+
"@socketsecurity/registry": "^1.0.108",
1414
"@socketsecurity/sdk": "^1.4.5",
1515
"blessed": "^0.1.81",
1616
"blessed-contrib": "^4.11.0",
@@ -72,7 +72,7 @@
7272
"@socketregistry/is-interactive": "^1.0.1",
7373
"@socketregistry/packageurl-js": "^1.0.2",
7474
"@socketsecurity/config": "^2.1.3",
75-
"@socketsecurity/registry": "^1.0.107",
75+
"@socketsecurity/registry": "^1.0.108",
7676
"@socketsecurity/sdk": "^1.4.5",
7777
"blessed": "^0.1.81",
7878
"blessed-contrib": "^4.11.0",

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
@@ -77,7 +77,7 @@
7777
"@socketregistry/is-unicode-supported": "^1.0.1",
7878
"@socketregistry/packageurl-js": "^1.0.2",
7979
"@socketsecurity/config": "^2.1.3",
80-
"@socketsecurity/registry": "^1.0.107",
80+
"@socketsecurity/registry": "^1.0.108",
8181
"@socketsecurity/sdk": "^1.4.5",
8282
"blessed": "^0.1.81",
8383
"blessed-contrib": "^4.11.0",

src/commands/analytics/display-analytics.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import fs from 'node:fs/promises'
44
import ScreenWidget from 'blessed/lib/widgets/screen'
55
import contrib from 'blessed-contrib'
66

7-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
8-
7+
import constants from '../../constants'
98
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
109
import { setupSdk } from '../../utils/sdk'
1110

11+
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
1212
import type { Widgets } from 'blessed' // Note: Widgets does not seem to actually work as code :'(
1313

1414
type FormattedData = {
@@ -73,7 +73,10 @@ export async function displayAnalytics({
7373
outputJson: boolean
7474
filePath: string
7575
}): Promise<void> {
76-
const spinner = new Spinner({ text: 'Fetching analytics data' }).start()
76+
// Lazily access constants.spinner.
77+
const { spinner } = constants
78+
79+
spinner.start('Fetching analytics data')
7780

7881
let data: undefined | { [key: string]: any }[]
7982
if (scope === 'org') {

src/commands/audit-log/get-audit-log.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Separator, select } from '@socketsecurity/registry/lib/prompts'
2-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
32

3+
import constants from '../../constants'
44
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
55
import { setupSdk } from '../../utils/sdk'
66

@@ -33,9 +33,10 @@ export async function getAuditLog({
3333
perPage: number
3434
type: string
3535
}): Promise<void> {
36-
const spinner = new Spinner({
37-
text: `Looking up audit log for ${orgSlug}\n`
38-
}).start()
36+
// Lazily access constants.spinner.
37+
const { spinner } = constants
38+
39+
spinner.start(`Looking up audit log for ${orgSlug}`)
3940

4041
const socketSdk = await setupSdk(apiToken)
4142
const result = await handleApiCall(

src/commands/dependencies/find-dependencies.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import chalkTable from 'chalk-table'
33
import colors from 'yoctocolors-cjs'
44

5-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
6-
5+
import constants from '../../constants'
76
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
87
import { AuthError } from '../../utils/errors'
98
import { getDefaultToken, setupSdk } from '../../utils/sdk'
@@ -23,7 +22,11 @@ export async function findDependencies({
2322
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
2423
)
2524
}
26-
const spinner = new Spinner({ text: 'Searching dependencies...' }).start()
25+
// Lazily access constants.spinner.
26+
const { spinner } = constants
27+
28+
spinner.start('Searching dependencies...')
29+
2730
const socketSdk = await setupSdk(apiToken)
2831

2932
const result = await handleApiCall(

src/commands/diff-scan/get-diff-scan.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import util from 'node:util'
33

44
import colors from 'yoctocolors-cjs'
55

6-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
7-
6+
import constants from '../../constants'
87
import { handleAPIError, queryAPI } from '../../utils/api'
98

109
export async function getDiffScan(
@@ -25,7 +24,8 @@ export async function getDiffScan(
2524
},
2625
apiToken: string
2726
): Promise<void> {
28-
const spinner = new Spinner()
27+
// Lazily access constants.spinner.
28+
const { spinner } = constants
2929

3030
spinner.start('Getting diff scan...')
3131

src/commands/fix/run-fix.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
fetchPackagePackument,
55
readPackageJson
66
} from '@socketsecurity/registry/lib/packages'
7-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
87

98
import constants from '../../constants'
109
import {
@@ -29,7 +28,11 @@ function isTopLevel(tree: SafeNode, node: SafeNode): boolean {
2928
}
3029

3130
export async function runFix() {
32-
const spinner = new Spinner().start()
31+
// Lazily access constants.spinner.
32+
const { spinner } = constants
33+
34+
spinner.start()
35+
3336
const cwd = process.cwd()
3437
const editablePkgJson = await readPackageJson(cwd, { editable: true })
3538
// const agentDetails = await detect()

src/commands/info/get-package-info.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
2-
31
import { fetchPackageInfo } from './fetch-package-info'
42
import { formatPackageInfo } from './format-package-info'
3+
import constants from '../../constants'
54

65
import type { SocketSdkAlert } from '../../utils/alert/severity'
76
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
@@ -29,11 +28,15 @@ export async function getPackageInfo({
2928
pkgVersion: string
3029
strict: boolean
3130
}) {
32-
const spinnerText =
31+
// Lazily access constants.spinner.
32+
const { spinner } = constants
33+
34+
spinner.start(
3335
pkgVersion === 'latest'
3436
? `Looking up data for the latest version of ${pkgName}`
3537
: `Looking up data for version ${pkgVersion} of ${pkgName}`
36-
const spinner = new Spinner({ text: spinnerText }).start()
38+
)
39+
3740
const packageData = await fetchPackageInfo(
3841
pkgName,
3942
pkgVersion,

src/commands/login/attempt-login.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import terminalLink from 'terminal-link'
22

33
import { confirm, password, select } from '@socketsecurity/registry/lib/prompts'
4-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
54

65
import { applyLogin } from './apply-login'
76
import constants from '../../constants'
@@ -28,18 +27,17 @@ export async function attemptLogin(
2827
apiBaseUrl: string | undefined,
2928
apiProxy: string | undefined
3029
) {
30+
apiBaseUrl ??= getSetting('apiBaseUrl') ?? undefined
31+
apiProxy ??= getSetting('apiProxy') ?? undefined
3132
const apiToken =
3233
(await password({
3334
message: `Enter your ${terminalLink(
3435
'Socket.dev API key',
3536
'https://docs.socket.dev/docs/api-keys'
3637
)} (leave blank for a public key)`
3738
})) || SOCKET_PUBLIC_API_TOKEN
38-
39-
apiBaseUrl ??= getSetting('apiBaseUrl') ?? undefined
40-
apiProxy ??= getSetting('apiProxy') ?? undefined
41-
42-
const spinner = new Spinner()
39+
// Lazily access constants.spinner.
40+
const { spinner } = constants
4341

4442
spinner.start('Verifying API key...')
4543

@@ -65,7 +63,6 @@ export async function attemptLogin(
6563
}))
6664

6765
let enforcedOrgs: Array<string> = []
68-
6966
if (enforcedChoices.length > 1) {
7067
const id = <string | null>await select(
7168
{

0 commit comments

Comments
 (0)