Skip to content

Commit 39a638d

Browse files
committed
Add spinner to optimize command
1 parent 0e18463 commit 39a638d

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/commands/optimize.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33
import spawn from '@npmcli/promise-spawn'
44
import { getManifestData } from '@socketsecurity/registry'
55
import meow from 'meow'
6+
import ora from 'ora'
67

78
import { printFlagList } from '../utils/formatting'
89
import { writeFileUtf8 } from '../utils/fs'
@@ -363,21 +364,29 @@ export const optimize: CliSubcommand = {
363364
aoState
364365
)
365366
}
366-
if (agent === 'npm') {
367-
const wrapperPath = path.join(distPath, 'npm-cli.js')
368-
await spawn(process.execPath, [wrapperPath, ...argv], {
369-
stdio: 'inherit',
370-
env: (<unknown>{
371-
__proto__: null,
372-
...process.env,
373-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
374-
}) as NodeJS.ProcessEnv
375-
})
376-
}
377367
}
378368
const { size: count } = aoState.packageNames
379369
if (count) {
380370
console.log(`Added ${count} Socket.dev optimized overrides 🚀`)
371+
if (agent === 'npm') {
372+
const spinner = ora('Updating package-lock.json...').start()
373+
const wrapperPath = path.join(distPath, 'npm-cli.js')
374+
try {
375+
await spawn(process.execPath, [wrapperPath, 'install'], {
376+
stdio: 'pipe',
377+
env: (<unknown>{
378+
__proto__: null,
379+
...process.env,
380+
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
381+
}) as NodeJS.ProcessEnv
382+
})
383+
} catch {
384+
console.log(
385+
'✘ socket npm install: Failed to update package-lock.json'
386+
)
387+
}
388+
spinner.stop()
389+
}
381390
} else {
382391
console.log('Congratulations! Already Socket.dev optimized 🎉')
383392
}

0 commit comments

Comments
 (0)