I'd like to organise a large NPM monorepo such that I can run commands on many (but not all) workspaces according to a category or pattern.
This could be by subdirectory, or by a pattern in the workspace names like a prefix or suffix, but I can't see any way to do either in NPM alone.
In Yarn >= 2, this is possible using --include or --exclude flags with glob patterns on yarn workspaces foreach, for example:
yarn workspaces foreach --include "@namespace/plugin-*" --include "@namespace/preset-*" run build
...and that builds all your workspaces with that namespace and either the plugin- or preset- prefix.
In lerna, the --scope flag also took globs allowing patterns, for example:
lerna run --scope "@namespace/plugin-*" --scope "@namespace/preset-*" run build
But in NPM, as far I can see in NPM's workspaces documentation for v7 and for v8, it doesn't seem to have the same feature:
- It has a flag
--workspacewhich may be used multiple times to create an array but appears to only accept exact workspace names, - ...and a flag
--workspaceswhich appears to run in all workspaces,
...but I can't see any way to either run on all workspaces in a directory or all workspaces matching a pattern. I really don't want to have to list every workspace by name in every script, as there's going to be a lot of them.