MCPcopy Index your code
hub / github.com/nodejs/node / getWorkspaces

Function getWorkspaces

deps/npm/lib/utils/get-workspaces.js:11–52  ·  view source on GitHub ↗
(filters, { path, includeWorkspaceRoot, relativeFrom })

Source from the content-addressed store, hash-verified

9// Returns an Map of paths to workspaces indexed by workspace name
10// { foo => '/path/to/foo' }
11const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom }) => {
12 // TODO we need a better error to be bubbled up here if this call fails
13 const { content: pkg } = await pkgJson.normalize(path)
14 const workspaces = await mapWorkspaces({ cwd: path, pkg })
15 let res = new Map()
16 if (includeWorkspaceRoot) {
17 res.set(pkg.name, path)
18 }
19
20 if (!filters.length) {
21 res = new Map([...res, ...workspaces])
22 }
23
24 for (const filterArg of filters) {
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)
31 if (filterArg === workspaceName
32 || resolve(relativeFrom, filterArg) === workspacePath
33 || minimatch(relativePath, `${globify(relativeFilter)}/*`)
34 || minimatch(relativePath, `${globify(filterArg)}/*`)
35 ) {
36 res.set(workspaceName, workspacePath)
37 }
38 }
39 }
40
41 if (!res.size) {
42 let msg = '!'
43 if (filters.length) {
44 msg = `:\n ${filters.reduce(
45 (acc, filterArg) => `${acc} --workspace=${filterArg}`, '')}`
46 }
47
48 throw new Error(`No workspaces found${msg}`)
49 }
50
51 return res
52}
53
54module.exports = getWorkspaces

Callers 3

setWorkspacesMethod · 0.85
execMethod · 0.85
get-workspaces.jsFile · 0.85

Calls 7

relativeFunction · 0.85
minimatchFunction · 0.85
reduceMethod · 0.80
globifyFunction · 0.70
resolveFunction · 0.50
setMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…