const getWorkspaces = require("get-workspaces");
const spawnDamnit = require("spawn-damnit");
async function execInOnePkg(matchString, command) {
const workspaces = await getWorkspaces();
// regex match or globby match
// against name for actual matches, or dir in case they are different
let matchingWorkspaces = workspaces.filter(({ name, dir }) =>
name.includes(matchString, command)
);
if (matchingWorkspaces.length > 1) {
console.error(
"This matched multiple workspaces:",
matchingWorkspaces.map(({ name }) => name).join(", ")
);
console.error("please narrow your search so only one workspace is matched");
throw new Error("stahp");
} else if (matchingWorkspaces.length === 0) {
console.warn("no matching packages");
} else {
let [workspace] = matchingWorkspaces;
// I do not know this API at all
// We want to spawn a new shell at the workspace.dir and execute whatever was passed as 'command'
await spawnDamnit(workspace.dir, command);
}
}
execInOnePkg();
`manypkg next-app run start`;
// Runs yarn start in the package