@@ -8,6 +8,7 @@ const cwd = resolve('fixtures/binaries');
8
8
const containingFilePath = join ( cwd , 'package.json' ) ;
9
9
const pkgScripts = { cwd, manifestScriptNames : new Set ( [ 'program' ] ) } ;
10
10
const knownOnly = { cwd, knownBinsOnly : true } ;
11
+ const optional = { optional : true } ;
11
12
12
13
const js = toDeferResolveEntry ( './script.js' ) ;
13
14
const ts = toDeferResolveEntry ( './main.ts' ) ;
@@ -132,41 +133,55 @@ test('getInputsFromScripts (npm)', () => {
132
133
test ( 'getInputsFromScripts (npx)' , ( ) => {
133
134
t ( 'npx pkg' , [ toBinary ( 'npx' ) , toBinary ( 'pkg' ) ] ) ;
134
135
t ( 'npx prisma migrate reset --force' , [ toBinary ( 'npx' ) , toBinary ( 'prisma' ) ] ) ;
135
- t ( 'npx @scope/pkg' , [ toBinary ( 'npx' ) , toDependency ( '@scope/pkg' ) ] ) ;
136
+ t ( 'npx @scope/pkg' , [ toBinary ( 'npx' ) , toDependency ( '@scope/pkg' , optional ) ] ) ;
136
137
t ( 'npx tsx watch main' , [ toBinary ( 'npx' ) , toBinary ( 'tsx' ) , toDeferResolveEntry ( 'main' ) ] ) ;
137
138
t ( 'npx -y pkg' , [ toBinary ( 'npx' ) ] ) ;
138
139
t ( 'npx --yes pkg' , [ toBinary ( 'npx' ) ] ) ;
139
140
t ( 'npx --no pkg --edit ${1}' , [ toBinary ( 'npx' ) , toBinary ( 'pkg' ) ] ) ;
140
141
t ( 'npx --no -- pkg --edit ${1}' , [ toBinary ( 'npx' ) , toBinary ( 'pkg' ) ] ) ;
141
142
t ( 'npx pkg install --with-deps' , [ toBinary ( 'npx' ) , toBinary ( 'pkg' ) ] ) ;
142
143
t ( 'npx pkg migrate reset --force' , [ toBinary ( 'npx' ) , toBinary ( 'pkg' ) ] ) ;
143
- t ( 'npx pkg@1.0.0 migrate reset --force' , [ toBinary ( 'npx' ) , toDependency ( 'pkg' ) ] ) ;
144
- t ( 'npx @scope/cli migrate reset --force' , [ toBinary ( 'npx' ) , toDependency ( '@scope/cli' ) ] ) ;
144
+ t ( 'npx pkg@1.0.0 migrate reset --force' , [ toBinary ( 'npx' ) , toDependency ( 'pkg' , optional ) ] ) ;
145
+ t ( 'npx @scope/cli migrate reset --force' , [ toBinary ( 'npx' ) , toDependency ( '@scope/cli' , optional ) ] ) ;
145
146
t ( 'npx -- pkg' , [ toBinary ( 'npx' ) , toBinary ( 'pkg' ) ] ) ;
146
- t ( 'npx -- @scope/cli@1.0.0 migrate reset --force' , [ toBinary ( 'npx' ) , toDependency ( '@scope/cli' ) ] ) ;
147
- t ( 'npx retry-cli@0.6.0 -- curl --output /dev/null ' , [ toBinary ( 'npx' ) , toDependency ( 'retry-cli' ) , toBinary ( 'curl' ) ] ) ;
148
- t ( 'npx --package pkg@0.6.0 -- curl --output /dev/null' , [ toBinary ( 'npx' ) , toBinary ( 'curl' ) , toDependency ( 'pkg' ) ] ) ;
149
- t ( 'npx --package @scope/pkg@0.6.0 --package pkg -- curl' , [ toBinary ( 'npx' ) , toBinary ( 'curl' ) , toDependency ( '@scope/pkg' ) , toDependency ( 'pkg' ) ] ) ;
150
- t ( "npx --package=foo -c 'curl --output /dev/null'" , [ toBinary ( 'npx' ) , toDependency ( 'foo' ) , toBinary ( 'curl' ) ] ) ;
147
+ t ( 'npx -- @scope/cli@1.0.0 migrate reset --force' , [ toBinary ( 'npx' ) , toDependency ( '@scope/cli' , optional ) ] ) ;
148
+ t ( 'npx retry-cli@0.6.0 -- curl --output /dev/null ' , [ toBinary ( 'npx' ) , toDependency ( 'retry-cli' , optional ) , toBinary ( 'curl' ) ] ) ;
149
+ t ( 'npx --package pkg@0.6.0 -- curl --output /dev/null' , [ toBinary ( 'npx' ) , toBinary ( 'curl' ) , toDependency ( 'pkg' , optional ) ] ) ;
150
+ t ( 'npx --package @scope/pkg@0.6.0 --package pkg -- curl' , [ toBinary ( 'npx' ) , toBinary ( 'curl' ) , toDependency ( '@scope/pkg' , optional ) , toDependency ( 'pkg' , optional ) ] ) ;
151
+ t ( "npx --package=foo -c 'curl --output /dev/null'" , [ toBinary ( 'npx' ) , toDependency ( 'foo' , optional ) , toBinary ( 'curl' ) ] ) ;
151
152
t ( 'npx swagger-typescript-api -p http://localhost:3030/swagger.v1.json' , [ toBinary ( 'npx' ) , toBinary ( 'swagger-typescript-api' ) ] ) ;
152
153
t ( 'npx swagger-typescript-api -- -p http://localhost:3030/swagger.v1.json' , [ toBinary ( 'npx' ) , toBinary ( 'swagger-typescript-api' ) ] ) ;
153
154
t ( 'npx tsx main' , [ toBinary ( 'npx' ) , toBinary ( 'tsx' ) , toDeferResolveEntry ( 'main' ) ] ) ;
154
155
t ( 'npx tsx ./main.ts build' , [ toBinary ( 'npx' ) , toBinary ( 'tsx' ) , ts ] ) ;
155
156
t ( 'npx tsx ./main.ts -- build' , [ toBinary ( 'npx' ) , toBinary ( 'tsx' ) , ts ] ) ;
156
157
} ) ;
157
158
159
+ test ( 'getInputsFromScripts (pnpx/pnpm dlx)' , ( ) => {
160
+ t ( 'pnpx pkg' , [ toBinary ( 'pnpx' ) , toDependency ( 'pkg' , optional ) ] ) ;
161
+ const s = [ toDependency ( 'cowsay' , optional ) , toDependency ( 'lolcatjs' , optional ) , toBinary ( 'echo' ) , toBinary ( 'cowsay' ) , toBinary ( 'lolcatjs' ) ] ;
162
+ t ( 'pnpx --package cowsay --package lolcatjs -c \'echo "hi pnpm" | cowsay | lolcatjs\'' , [ toBinary ( 'pnpx' ) , ...s ] ) ;
163
+ t ( 'pnpm --package cowsay --package lolcatjs -c dlx \'echo "hi pnpm" | cowsay | lolcatjs\'' , [ toBinary ( 'pnpm' ) , ...s ] ) ;
164
+ } ) ;
165
+
166
+ test ( 'getInputsFromScripts (bunx/bun x)' , ( ) => {
167
+ t ( 'bunx pkg' , [ toBinary ( 'bunx' ) , toDependency ( 'pkg' , optional ) ] ) ;
168
+ t ( 'bunx cowsay "Hello world!"' , [ toBinary ( 'bunx' ) , toDependency ( 'cowsay' , optional ) ] ) ;
169
+ t ( 'bunx my-cli --foo bar' , [ toBinary ( 'bunx' ) , toDependency ( 'my-cli' , optional ) ] ) ;
170
+ t ( 'bun x pkg' , [ toBinary ( 'bun' ) , toDependency ( 'pkg' , optional ) ] ) ;
171
+ } ) ;
172
+
158
173
test ( 'getInputsFromScripts (pnpm)' , ( ) => {
159
- t ( 'pnpm exec program' , [ toBinary ( 'program' ) ] ) ;
160
- t ( 'pnpm run program' , [ ] ) ;
161
- t ( 'pnpm program' , [ toBinary ( 'program' ) ] ) ;
162
- t ( 'pnpm run program' , [ ] , pkgScripts ) ;
163
- t ( 'pnpm program' , [ ] , pkgScripts ) ;
164
- t ( 'pnpm dlx pkg' , [ ] ) ;
165
- t ( 'pnpm --package=pkg-a dlx pkg' , [ ] ) ;
166
- t ( 'pnpm --recursive --parallel test -- --sequence.seed=1700316221712' , [ ] ) ;
167
- t ( 'pnpm program script.js' , [ ] , pkgScripts ) ;
168
- t ( 'pnpm --silent program script.js' , [ ] , pkgScripts ) ;
169
- t ( 'pnpm --silent run program script.js' , [ ] , pkgScripts ) ;
174
+ t ( 'pnpm exec program' , [ toBinary ( 'pnpm' ) , toBinary ( ' program') ] ) ;
175
+ t ( 'pnpm run program' , [ toBinary ( 'pnpm' ) ] ) ;
176
+ t ( 'pnpm program' , [ toBinary ( 'pnpm' ) , toBinary ( ' program') ] ) ;
177
+ t ( 'pnpm run program' , [ toBinary ( 'pnpm' ) ] , pkgScripts ) ;
178
+ t ( 'pnpm program' , [ toBinary ( 'pnpm' ) ] , pkgScripts ) ;
179
+ t ( 'pnpm dlx pkg' , [ toBinary ( 'pnpm' ) , toDependency ( 'pkg' , optional ) ] ) ;
180
+ t ( 'pnpm --package=pkg-a dlx pkg' , [ toBinary ( 'pnpm' ) , toDependency ( 'pkg' , optional ) , toDependency ( 'pkg-a' , optional ) ] ) ;
181
+ t ( 'pnpm --recursive --parallel test -- --sequence.seed=1700316221712' , [ toBinary ( 'pnpm' ) ] ) ;
182
+ t ( 'pnpm program script.js' , [ toBinary ( 'pnpm' ) ] , pkgScripts ) ;
183
+ t ( 'pnpm --silent program script.js' , [ toBinary ( 'pnpm' ) ] , pkgScripts ) ;
184
+ t ( 'pnpm --silent run program script.js' , [ toBinary ( 'pnpm' ) ] , pkgScripts ) ;
170
185
} ) ;
171
186
172
187
test ( 'getInputsFromScripts (yarn)' , ( ) => {
@@ -229,7 +244,7 @@ test('getInputsFromScripts (bash expansion)', () => {
229
244
230
245
test ( 'getInputsFromScripts (multiline)' , ( ) => {
231
246
t ( '#!/bin/sh\n. "$(dirname "$0")/_/husky.sh"\nnpx lint-staged' , [ toBinary ( 'npx' ) , toBinary ( 'lint-staged' ) ] ) ;
232
- t ( `for S in "s"; do\n\tnpx rc@0.6.0\n\tnpx @scope/rc@0.6.0\ndone` , [ toBinary ( 'npx' ) , toDependency ( 'rc' ) , toBinary ( 'npx' ) , toDependency ( '@scope/rc' ) ] ) ;
247
+ t ( `for S in "s"; do\n\tnpx rc@0.6.0\n\tnpx @scope/rc@0.6.0\ndone` , [ toBinary ( 'npx' ) , toDependency ( 'rc' , optional ) , toBinary ( 'npx' ) , toDependency ( '@scope/rc' , optional ) ] ) ;
233
248
} ) ;
234
249
235
250
test ( 'getInputsFromScripts (bail outs)' , ( ) => {
0 commit comments