![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/lib/node_modules/npm/lib/workspaces/ |
Upload File : |
const { resolve } = require('path') const mapWorkspaces = require('@npmcli/map-workspaces') const minimatch = require('minimatch') const rpj = require('read-package-json-fast') // Returns an Map of paths to workspaces indexed by workspace name // { foo => '/path/to/foo' } const getWorkspaces = async (filters, { path, includeWorkspaceRoot }) => { // TODO we need a better error to be bubbled up here if this rpj call fails const pkg = await rpj(resolve(path, 'package.json')) const workspaces = await mapWorkspaces({ cwd: path, pkg }) let res = new Map() if (includeWorkspaceRoot) res.set(pkg.name, path) if (!filters.length) res = new Map([...res, ...workspaces]) for (const filterArg of filters) { for (const [workspaceName, workspacePath] of workspaces.entries()) { if (filterArg === workspaceName || resolve(path, filterArg) === workspacePath || minimatch(workspacePath, `${resolve(path, filterArg)}/*`)) res.set(workspaceName, workspacePath) } } if (!res.size) { let msg = '!' if (filters.length) { msg = `:\n ${filters.reduce( (res, filterArg) => `${res} --workspace=${filterArg}`, '')}` } throw new Error(`No workspaces found${msg}`) } return res } module.exports = getWorkspaces