@@ -34,24 +34,33 @@ class Exec extends BaseCommand {
34
34
for ( const [ name , path ] of this . workspaces ) {
35
35
const locationMsg =
36
36
`in workspace ${ this . npm . chalk . green ( name ) } at location:\n${ this . npm . chalk . dim ( path ) } `
37
- await this . callExec ( args , { locationMsg, runPath : path } )
37
+ await this . callExec ( args , { name , locationMsg, runPath : path } )
38
38
}
39
39
}
40
40
41
- async callExec ( args , { locationMsg, runPath } = { } ) {
42
- // This is where libnpmexec will look for locally installed packages
41
+ async callExec ( args , { name , locationMsg, runPath } = { } ) {
42
+ // This is where libnpmexec will look for locally installed packages at the project level
43
43
const localPrefix = this . npm . localPrefix
44
+ // This is where libnpmexec will look for locally installed packages at the workspace level
45
+ let localBin = this . npm . localBin
46
+ let path = localPrefix
44
47
45
48
// This is where libnpmexec will actually run the scripts from
46
49
if ( ! runPath ) {
47
50
runPath = process . cwd ( )
51
+ } else {
52
+ // We have to consider if the workspace has its own separate versions
53
+ // libnpmexec will walk up to localDir after looking here
54
+ localBin = resolve ( this . npm . localDir , name , 'node_modules' , '.bin' )
55
+ // We also need to look for `bin` entries in the workspace package.json
56
+ // libnpmexec will NOT look in the project root for the bin entry
57
+ path = runPath
48
58
}
49
59
50
60
const call = this . npm . config . get ( 'call' )
51
61
let globalPath
52
62
const {
53
63
flatOptions,
54
- localBin,
55
64
globalBin,
56
65
globalDir,
57
66
chalk,
@@ -79,14 +88,14 @@ class Exec extends BaseCommand {
79
88
// copy args so they dont get mutated
80
89
args : [ ...args ] ,
81
90
call,
82
- localBin,
83
- locationMsg,
91
+ chalk,
84
92
globalBin,
85
93
globalPath,
94
+ localBin,
95
+ locationMsg,
86
96
output,
87
- chalk,
88
97
packages,
89
- path : localPrefix ,
98
+ path,
90
99
runPath,
91
100
scriptShell,
92
101
yes,
0 commit comments