@@ -22,6 +22,7 @@ import type {
2222
2323const distPath = __dirname
2424
25+ const COMMAND_TITLE = 'Socket Optimize'
2526const OVERRIDES_FIELD_NAME = 'overrides'
2627const RESOLUTIONS_FIELD_NAME = 'resolutions'
2728
@@ -230,6 +231,7 @@ export const optimize: CliSubcommand = {
230231 importMeta
231232 )
232233 if ( commandContext ) {
234+ const cwd = process . cwd ( )
233235 const {
234236 agent,
235237 agentExecPath,
@@ -242,21 +244,30 @@ export const optimize: CliSubcommand = {
242244 pkgJson,
243245 supported
244246 } = await detect ( {
245- cwd : process . cwd ( ) ,
247+ cwd,
246248 onUnknown ( pkgManager : string | undefined ) {
247249 console . log (
248- `⚠️ Unknown package manager${ pkgManager ? ` ${ pkgManager } ` : '' } : Defaulting to npm`
250+ `⚠️ ${ COMMAND_TITLE } : Unknown package manager${ pkgManager ? ` ${ pkgManager } ` : '' } , defaulting to npm`
249251 )
250252 }
251253 } )
252254 if ( ! supported ) {
253- console . log ( '✘ The engines.node range is not supported.' )
255+ console . log ( `✘ ${ COMMAND_TITLE } : Package engines.node range is not supported` )
256+ return
257+ }
258+ const lockName = lockPath ? path . basename ( lockPath ) : 'lock file'
259+ if ( lockSrc === undefined ) {
260+ console . log ( `✘ ${ COMMAND_TITLE } : No ${ lockName } found` )
254261 return
255262 }
256263 if ( pkgJson === undefined ) {
257- console . log ( '✘ No package.json found.' )
264+ console . log ( `✘ ${ COMMAND_TITLE } : No package.json found` )
258265 return
259266 }
267+ if ( lockPath && path . relative ( cwd , lockPath ) . startsWith ( '.' ) ) {
268+ console . log ( `⚠️ ${ COMMAND_TITLE } : Package ${ lockName } found at ${ lockPath } ` )
269+ }
270+
260271 const aoState : AddOverridesState = {
261272 output : pkgJsonStr ! ,
262273 packageNames : new Set ( )
@@ -288,7 +299,6 @@ export const optimize: CliSubcommand = {
288299 console . log ( 'Congratulations! Already Socket.dev optimized 🎉' )
289300 }
290301
291- const lockName = lockPath ? path . basename ( lockPath ) : 'lock file'
292302 const isNpm = agent === 'npm'
293303 if ( isNpm || count ) {
294304 // Always update package-lock.json until the npm overrides PR lands:
@@ -311,12 +321,12 @@ export const optimize: CliSubcommand = {
311321 spinner . stop ( )
312322 if ( isNpm ) {
313323 console . log (
314- `💡 Re-run Socket Optimize whenever ${ lockName } changes.\n This can be skipped once npm ships https://github.com/npm/cli/pull/7025.`
324+ `💡 Re-run ${ COMMAND_TITLE } whenever ${ lockName } changes.\n This can be skipped once npm ships https://github.com/npm/cli/pull/7025.`
315325 )
316326 }
317327 } catch {
318328 spinner . stop ( )
319- console . log ( `✘ socket ${ agent } install: Failed to update ${ lockName } ` )
329+ console . log ( `✘ ${ COMMAND_TITLE } : ${ agent } install failed to update ${ lockName } ` )
320330 }
321331 }
322332 }
0 commit comments