-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspaces support to `npm exec` - Refactored logic to read and filter workspaces into `lib/workspaces/get-workspaces.js` - Add ability to execute a package in the context of each configured workspace Fixes: npm/statusboard#288
- Loading branch information
Showing
5 changed files
with
330 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { resolve } = require('path') | ||
const mapWorkspaces = require('@npmcli/map-workspaces') | ||
const minimatch = require('minimatch') | ||
const rpj = require('read-package-json-fast') | ||
|
||
const getWorkspaces = async (filters, { path }) => { | ||
const pkg = await rpj(resolve(path, 'package.json')) | ||
const workspaces = await mapWorkspaces({ cwd: path, pkg }) | ||
const res = filters.length ? new Map() : 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.