@@ -114,10 +114,9 @@ t.test('do not run scripts if ignoreScripts=true', async t => {
114114 t . throws ( ( ) => fs . statSync ( file ) , 'bundle build script not run' )
115115} )
116116
117- t . test ( 'allowScripts deny entry skips the build set entry for that node' , async t => {
118- // Verifies the deny gate in #addToBuildSet: when `allowScripts` resolves
119- // a node's policy to `false`, that node's scripts are skipped while
120- // others continue to run.
117+ t . test ( 'allowScripts deny entry skips scripts for the denied node' , async t => {
118+ // Deny gate in #buildQueues: a `false` policy skips that node's
119+ // scripts while others still run.
121120 const path = fixture ( t , 'testing-rebuild-script-env-flags' )
122121 const arb = newArb ( {
123122 path,
@@ -154,6 +153,46 @@ t.test('dangerouslyAllowAllScripts bypasses the deny gate', async t => {
154153 )
155154} )
156155
156+ t . test ( 'allowScripts deny keeps the bin link (npm/cli#9681)' , async t => {
157+ // Denying a package's scripts must not drop its bin links: the script
158+ // is skipped but `.bin/<name>` is still created, like --ignore-scripts.
159+ const path = t . testdir ( {
160+ 'package.json' : JSON . stringify ( {
161+ name : 'project' ,
162+ version : '1.0.0' ,
163+ dependencies : { 'denied-dep' : '1.0.0' } ,
164+ } ) ,
165+ node_modules : {
166+ 'denied-dep' : {
167+ 'package.json' : JSON . stringify ( {
168+ name : 'denied-dep' ,
169+ version : '1.0.0' ,
170+ bin : { 'denied-bin' : 'index.js' } ,
171+ scripts : {
172+ postinstall : `node -e "require('fs').writeFileSync('ran', '1')"` ,
173+ } ,
174+ } ) ,
175+ 'index.js' : '#!/usr/bin/env node\nconsole.log("hi")\n' ,
176+ } ,
177+ } ,
178+ } )
179+ const arb = newArb ( {
180+ path,
181+ allowScripts : { 'denied-dep' : false } ,
182+ } )
183+ await arb . rebuild ( )
184+
185+ t . throws (
186+ ( ) => fs . statSync ( resolve ( path , 'node_modules/denied-dep/ran' ) ) ,
187+ 'denied postinstall did not run'
188+ )
189+ t . equal (
190+ fs . statSync ( resolve ( path , 'node_modules/.bin/denied-bin' ) ) . isFile ( ) ,
191+ true ,
192+ 'denied package bin link is still created'
193+ )
194+ } )
195+
157196t . test ( 'do nothing if ignoreScripts=true and binLinks=false' , async t => {
158197 const path = fixture ( t , 'testing-rebuild-bundle-reified' )
159198 const file = resolve ( path , 'node_modules/@isaacs/testing-rebuild-bundle-a/node_modules/@isaacs/testing-rebuild-bundle-b/cwd' )
0 commit comments