1
- const { resolve } = require ( 'path' )
1
+ const path = require ( 'path' )
2
2
const mapWorkspaces = require ( '@npmcli/map-workspaces' )
3
3
const minimatch = require ( 'minimatch' )
4
4
const rpj = require ( 'read-package-json-fast' )
5
5
6
6
// Returns an Map of paths to workspaces indexed by workspace name
7
7
// { foo => '/path/to/foo' }
8
- const getWorkspaces = async ( filters , { path, includeWorkspaceRoot, relativeFrom } ) => {
8
+ const getWorkspaces = async ( filters , { path : filePath , includeWorkspaceRoot, relativeFrom } ) => {
9
9
// TODO we need a better error to be bubbled up here if this rpj call fails
10
- const pkg = await rpj ( resolve ( path , 'package.json' ) )
11
- const workspaces = await mapWorkspaces ( { cwd : path , pkg } )
10
+ const pkg = await rpj ( path . resolve ( filePath , 'package.json' ) )
11
+ const workspaces = await mapWorkspaces ( { cwd : filePath , pkg } )
12
12
let res = new Map ( )
13
13
if ( includeWorkspaceRoot ) {
14
- res . set ( pkg . name , path )
14
+ res . set ( pkg . name , filePath )
15
15
}
16
16
17
17
if ( ! filters . length ) {
@@ -20,9 +20,16 @@ const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom
20
20
21
21
for ( const filterArg of filters ) {
22
22
for ( const [ workspaceName , workspacePath ] of workspaces . entries ( ) ) {
23
- if ( filterArg === workspaceName
24
- || resolve ( relativeFrom || path , filterArg ) === workspacePath
25
- || minimatch ( workspacePath , `${ resolve ( relativeFrom || path , filterArg ) } /*` ) ) {
23
+ if (
24
+ filterArg === workspaceName
25
+ || path . resolve ( relativeFrom || filePath , filterArg ) === workspacePath
26
+ // path.posix is used here because minimatch wants forward slashes only
27
+ // for glob patterns
28
+ || minimatch (
29
+ workspacePath ,
30
+ `${ path . posix . resolve ( relativeFrom || filePath , filterArg ) } /*`
31
+ )
32
+ ) {
26
33
res . set ( workspaceName , workspacePath )
27
34
}
28
35
}
0 commit comments