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 2
2
'use strict'
3
3
4
4
const 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'
10
10
import isInteractive from 'is-interactive'
11
11
import npa from 'npm-package-arg'
12
12
import semver from 'semver'
13
+ import { onExit } from 'signal-exit'
13
14
14
15
import config from '@socketsecurity/config'
15
16
import { isObject } from '@socketsecurity/registry/lib/objects'
@@ -259,6 +260,8 @@ if (npmRootPath === undefined) {
259
260
console . error (
260
261
`Unable to find npm CLI install directory.\nSearched parent directories of ${ npmEntrypoint } .\n\n${ POTENTIAL_BUG_ERROR_MESSAGE } `
261
262
)
263
+ // The exit code 127 indicates that the command or binary being executed
264
+ // could not be found.
262
265
process . exit ( 127 )
263
266
}
264
267
@@ -288,6 +291,8 @@ if (log === undefined) {
288
291
console . error (
289
292
`Unable to integrate with npm CLI logging infrastructure.\n\n${ POTENTIAL_BUG_ERROR_MESSAGE } .`
290
293
)
294
+ // The exit code 127 indicates that the command or binary being executed
295
+ // could not be found.
291
296
process . exit ( 127 )
292
297
}
293
298
@@ -298,6 +303,11 @@ const translations = require(path.join(rootPath, 'translations.json'))
298
303
const abortController = new AbortController ( )
299
304
const { signal : abortSignal } = abortController
300
305
306
+ // Detect ^C, i.e. Ctrl + C.
307
+ onExit ( ( ) => {
308
+ abortController . abort ( )
309
+ } )
310
+
301
311
const Arborist : ArboristClass = require ( arboristClassPath )
302
312
const depValid : (
303
313
child : NodeClass ,
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ export default async function shadow(binName: 'npm' | 'npx') {
27
27
const npmEntrypoint = realpathSync ( binPath )
28
28
const npmRootPath = findRoot ( path . dirname ( npmEntrypoint ) )
29
29
if ( npmRootPath === undefined ) {
30
+ // The exit code 127 indicates that the command or binary being executed
31
+ // could not be found.
30
32
process . exit ( 127 )
31
33
}
32
34
const npmDepPath = path . join ( npmRootPath , 'node_modules' )
You can’t perform that action at this time.
0 commit comments