1
- const { resolve } = require ( 'path' )
1
+ const { resolve, relative } = 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
+ // minimatch wants forward slashes only for glob patterns
7
+ const globify = pattern => pattern . split ( '\\' ) . join ( '/' )
8
+
6
9
// Returns an Map of paths to workspaces indexed by workspace name
7
10
// { foo => '/path/to/foo' }
8
11
const getWorkspaces = async ( filters , { path, includeWorkspaceRoot, relativeFrom } ) => {
@@ -20,9 +23,16 @@ const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom
20
23
21
24
for ( const filterArg of filters ) {
22
25
for ( const [ workspaceName , workspacePath ] of workspaces . entries ( ) ) {
26
+ let relativePath = relative ( relativeFrom , workspacePath )
27
+ if ( filterArg . startsWith ( './' ) ) {
28
+ relativePath = `./${ relativePath } `
29
+ }
30
+ const relativeFilter = relative ( path , filterArg )
23
31
if ( filterArg === workspaceName
24
- || resolve ( relativeFrom || path , filterArg ) === workspacePath
25
- || minimatch ( workspacePath , `${ resolve ( relativeFrom || path , filterArg ) } /*` ) ) {
32
+ || resolve ( relativeFrom , filterArg ) === workspacePath
33
+ || minimatch ( relativePath , `${ globify ( relativeFilter ) } /*` )
34
+ || minimatch ( relativePath , `${ globify ( filterArg ) } /*` )
35
+ ) {
26
36
res . set ( workspaceName , workspacePath )
27
37
}
28
38
}
0 commit comments