File tree 2 files changed +40
-3
lines changed
workspaces/libnpmexec/lib
2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -129,3 +129,38 @@ t.test('workspaces', async t => {
129
129
const exists = await fs . stat ( path . join ( npm . prefix , 'workspace-a' , 'npm-exec-test-success' ) )
130
130
t . ok ( exists . isFile ( ) , 'bin ran, creating file inside workspace' )
131
131
} )
132
+
133
+ t . test ( 'npx --no-install @npmcli/npx-test' , async t => {
134
+ const registry = new MockRegistry ( {
135
+ tap : t ,
136
+ registry : 'https://registry.npmjs.org/' ,
137
+ } )
138
+
139
+ const manifest = registry . manifest ( { name : '@npmcli/npx-test' } )
140
+ manifest . versions [ '1.0.0' ] . bin = { 'npx-test' : 'index.js' }
141
+
142
+ const { npm } = await loadMockNpm ( t , {
143
+ config : {
144
+ audit : false ,
145
+ yes : false ,
146
+ } ,
147
+ prefixDir : {
148
+ 'npm-exec-test' : {
149
+ 'package.json' : JSON . stringify ( manifest ) ,
150
+ 'index.js' : `#!/usr/bin/env node
151
+ require('fs').writeFileSync('npm-exec-test-success', '')` ,
152
+ } ,
153
+ } ,
154
+ } )
155
+
156
+ try {
157
+ await npm . exec ( 'exec' , [ '@npmcli/npx-test' ] )
158
+ t . fail ( 'Expected error was not thrown' )
159
+ } catch ( error ) {
160
+ t . match (
161
+ error . message ,
162
+ 'npx canceled due to missing packages and no YES option: ' ,
163
+ 'Expected error message thrown'
164
+ )
165
+ }
166
+ } )
Original file line number Diff line number Diff line change @@ -245,9 +245,12 @@ const exec = async (opts) => {
245
245
246
246
if ( add . length ) {
247
247
if ( ! yes ) {
248
+ const missingPackages = add . map ( a => `${ a . replace ( / @ $ / , '' ) } ` )
248
249
// set -n to always say no
249
250
if ( yes === false ) {
250
- throw new Error ( 'canceled' )
251
+ // Error message lists missing package(s) when process is canceled
252
+ /* eslint-disable-next-line max-len */
253
+ throw new Error ( `npx canceled due to missing packages and no YES option: ${ JSON . stringify ( missingPackages ) } ` )
251
254
}
252
255
253
256
if ( noTTY ( ) || ciInfo . isCI ) {
@@ -257,8 +260,7 @@ const exec = async (opts) => {
257
260
add . map ( ( pkg ) => pkg . replace ( / @ $ / , '' ) ) . join ( ', ' )
258
261
} `)
259
262
} else {
260
- const addList = add . map ( a => ` ${ a . replace ( / @ $ / , '' ) } ` )
261
- . join ( '\n' ) + '\n'
263
+ const addList = missingPackages . join ( '\n' ) + '\n'
262
264
const prompt = `Need to install the following packages:\n${
263
265
addList
264
266
} Ok to proceed? `
You can’t perform that action at this time.
0 commit comments