diff options
author | Gar <gar+gh@danger.computer> | 2022-04-05 23:45:47 +0300 |
---|---|---|
committer | Gar <wraithgar@github.com> | 2022-04-07 00:29:40 +0300 |
commit | 1b30c725ecd0f03f55e3c0576962972748eec238 (patch) | |
tree | 3fc1dd6a491ea0bd233973ee4bea1ef00039605a /lib/workspaces | |
parent | e57353c78e798afbd3eb4390a42da5d5076be45d (diff) |
deps: minimatch@5.0.1
Diffstat (limited to 'lib/workspaces')
-rw-r--r-- | lib/workspaces/get-workspaces.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/workspaces/get-workspaces.js b/lib/workspaces/get-workspaces.js index 0cddae2a4..373af1d68 100644 --- a/lib/workspaces/get-workspaces.js +++ b/lib/workspaces/get-workspaces.js @@ -1,8 +1,11 @@ -const { resolve } = require('path') +const { resolve, relative } = require('path') const mapWorkspaces = require('@npmcli/map-workspaces') const minimatch = require('minimatch') const rpj = require('read-package-json-fast') +// minimatch wants forward slashes only for glob patterns +const globify = pattern => pattern.split('\\').join('/') + // Returns an Map of paths to workspaces indexed by workspace name // { foo => '/path/to/foo' } const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom }) => { @@ -20,9 +23,16 @@ const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom for (const filterArg of filters) { for (const [workspaceName, workspacePath] of workspaces.entries()) { + let relativePath = relative(relativeFrom, workspacePath) + if (filterArg.startsWith('./')) { + relativePath = `./${relativePath}` + } + const relativeFilter = relative(path, filterArg) if (filterArg === workspaceName - || resolve(relativeFrom || path, filterArg) === workspacePath - || minimatch(workspacePath, `${resolve(relativeFrom || path, filterArg)}/*`)) { + || resolve(relativeFrom, filterArg) === workspacePath + || minimatch(relativePath, `${globify(relativeFilter)}/*`) + || minimatch(relativePath, `${globify(filterArg)}/*`) + ) { res.set(workspaceName, workspacePath) } } |