@@ -22,19 +22,36 @@ const deglob = (v) => makePosix(v).replace(/[/*]+$/, '')
22
22
const posixDir = ( v ) => `${ v === '.' ? '' : deglob ( v ) . replace ( / \/ $ / , '' ) } ${ posix . sep } `
23
23
const posixGlob = ( str ) => `${ posixDir ( str ) } **`
24
24
25
- const getCmdPath = ( key , { rootConfig, defaultConfig, isRoot, pkg, rootPkg } ) => {
26
- // Make a path relative from a workspace to the root if we are in a workspace
27
- const wsToRoot = ( p ) => isRoot ? p : makePosix ( join ( relative ( pkg . path , rootPkg . path ) , p ) )
25
+ const getCmdPath = ( key , { pkgConfig, rootConfig, isRoot, pkg, rootPkg } ) => {
26
+ const result = ( local , isRelative ) => {
27
+ let root = local
28
+ const isLocal = local . startsWith ( '.' ) || local . startsWith ( '/' )
29
+
30
+ if ( isLocal ) {
31
+ if ( isRelative ) {
32
+ // Make a path relative from a workspace to the root if we are in a workspace
33
+ local = makePosix ( join ( relative ( pkg . path , rootPkg . path ) , local ) )
34
+ }
35
+ local = `node ${ local } `
36
+ root = `node ${ root } `
37
+ }
28
38
29
- const rootPath = rootConfig [ key ]
30
- const defaultPath = defaultConfig [ key ]
31
- const isLocal = rootPath && rootPath !== defaultPath
39
+ return {
40
+ isLocal,
41
+ local,
42
+ root,
43
+ }
44
+ }
32
45
33
- return {
34
- isLocal,
35
- root : ! isLocal ? defaultPath : `node ${ rootPath } ` ,
36
- local : ! isLocal ? defaultPath : `node ${ wsToRoot ( rootPath ) } ` ,
46
+ if ( pkgConfig [ key ] ) {
47
+ return result ( pkgConfig [ key ] )
37
48
}
49
+
50
+ if ( rootConfig [ key ] ) {
51
+ return result ( rootConfig [ key ] , ! isRoot )
52
+ }
53
+
54
+ return result ( key )
38
55
}
39
56
40
57
const mergeConfigs = ( ...configs ) => {
@@ -138,9 +155,8 @@ const getFullConfig = async ({
138
155
] : [ ] ,
139
156
]
140
157
141
- // root only configs
142
- const npmPath = getCmdPath ( 'npm' , { rootConfig, defaultConfig, isRoot, pkg, rootPkg } )
143
- const npxPath = getCmdPath ( 'npx' , { rootConfig, defaultConfig, isRoot, pkg, rootPkg } )
158
+ const npmPath = getCmdPath ( 'npm' , { pkgConfig, rootConfig, isRoot, pkg, rootPkg } )
159
+ const npxPath = getCmdPath ( 'npx' , { pkgConfig, rootConfig, isRoot, pkg, rootPkg } )
144
160
145
161
// these are written to ci yml files so it needs to always use posix
146
162
const pkgPath = makePosix ( relative ( rootPkg . path , pkg . path ) ) || '.'
0 commit comments