File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 22'use strict'
33
44const constants = require ( '../dist/constants' )
5- require ( `../dist/${ constants . DIST_TYPE } /cli.js` )
5+
6+ const { DIST_TYPE , execPath } = constants
7+
8+ if ( DIST_TYPE === 'require' ) {
9+ require ( `../dist/require/cli.js` )
10+ } else {
11+ const path = require ( 'node:path' )
12+ const spawn = require ( '@npmcli/promise-spawn' )
13+ const { onExit } = require ( 'signal-exit' )
14+
15+ const abortController = new AbortController ( )
16+ const { signal : abortSignal } = abortController
17+
18+ // Detect ^C, i.e. Ctrl + C.
19+ onExit ( ( ) => {
20+ abortController . abort ( )
21+ } )
22+
23+ const spawnPromise = spawn (
24+ execPath ,
25+ [
26+ // Lazily access constants.nodeNoWarningsFlags.
27+ ...constants . nodeNoWarningsFlags ,
28+ path . join ( constants . rootDistPath , DIST_TYPE , 'cli.js' ) ,
29+ ...process . argv . slice ( 2 )
30+ ] ,
31+ {
32+ stdio : 'inherit' ,
33+ signal : abortSignal
34+ }
35+ )
36+ spawnPromise . process . on ( 'exit' , ( code , signal ) => {
37+ if ( signal ) {
38+ process . kill ( process . pid , signal )
39+ } else if ( code !== null ) {
40+ process . exit ( code )
41+ }
42+ } )
43+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import yoctoSpinner from '@socketregistry/yocto-spinner'
1010import isInteractive from 'is-interactive'
1111import npa from 'npm-package-arg'
1212import semver from 'semver'
13+ import { onExit } from 'signal-exit'
1314
1415import config from '@socketsecurity/config'
1516import { isObject } from '@socketsecurity/registry/lib/objects'
@@ -259,6 +260,8 @@ if (npmRootPath === undefined) {
259260 console . error (
260261 `Unable to find npm CLI install directory.\nSearched parent directories of ${ npmEntrypoint } .\n\n${ POTENTIAL_BUG_ERROR_MESSAGE } `
261262 )
263+ // The exit code 127 indicates that the command or binary being executed
264+ // could not be found.
262265 process . exit ( 127 )
263266}
264267
@@ -288,6 +291,8 @@ if (log === undefined) {
288291 console . error (
289292 `Unable to integrate with npm CLI logging infrastructure.\n\n${ POTENTIAL_BUG_ERROR_MESSAGE } .`
290293 )
294+ // The exit code 127 indicates that the command or binary being executed
295+ // could not be found.
291296 process . exit ( 127 )
292297}
293298
@@ -298,6 +303,11 @@ const translations = require(path.join(rootPath, 'translations.json'))
298303const abortController = new AbortController ( )
299304const { signal : abortSignal } = abortController
300305
306+ // Detect ^C, i.e. Ctrl + C.
307+ onExit ( ( ) => {
308+ abortController . abort ( )
309+ } )
310+
301311const Arborist : ArboristClass = require ( arboristClassPath )
302312const depValid : (
303313 child : NodeClass ,
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ export default async function shadow(binName: 'npm' | 'npx') {
2727 const npmEntrypoint = realpathSync ( binPath )
2828 const npmRootPath = findRoot ( path . dirname ( npmEntrypoint ) )
2929 if ( npmRootPath === undefined ) {
30+ // The exit code 127 indicates that the command or binary being executed
31+ // could not be found.
3032 process . exit ( 127 )
3133 }
3234 const npmDepPath = path . join ( npmRootPath , 'node_modules' )
You can’t perform that action at this time.
0 commit comments