-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to shorten dependency lists: wildcards or auto-dependencies #119
Comments
#23 covers adding a That's basically equivalent to I do have a feeling some of the "I need to build everything" use cases might actually come up less frequently than we are used to in Wireit projects, because the dependencies are now more explicit. E.g. we are used to typing "npm run build" in the root of our monorepo before we do anything, but you probably don't want to do that anymore. You would instead just jump straight to the package you want to work on, type A top-level |
I was thinking top-level build would be good for CI, but with caching even that might not be necessary. I could see it being used to check things after updating dependencies, but |
Nx is able to automatically determine package dependencies within a monorepo, so building one package builds all of its dependencies without having to specify what those dependencies are beyond just adding them via a package.json (or direct import in their default setup which doesn't use workspaces, but that's not really relevant here). Automatically inferring dependencies from a package.json in a workspace seems desirable so that you don't need to specify those dependencies (effectively) twice. |
Another thing Nx does is let you specify default dependencies across all workspaces - ie, in a root configuration file you can note that for the build target in all workspaces, the build target of any dependencies within the package also need to be run |
Automatic package-level dependencies are convenient, but there's tradeoffs there too. Script level dependencies can be more granular. e.g. suppose |
That's where configurability comes in. As I said, what Nx does is let you specify default dependencies across all workspaces for a given script. So you can say the build script in a workspace always depends on the build scripts of its dependencies - that doesn't affect the dependencies of the test scripts. I think it is relatively common for this configuration to work without issues - I'm hard pressed to imagine a situation where a build of a package would not require the dependencies being built. But even if there is some such situation, I'm sure there's other ways to make the configuration more flexible (or at worst, just don't use automatic dependency discovery) |
I'm testing wireit for a monorepo at Capital One and will say having automatic dependency checking and script utilities are going to be a huge factor for us in determining our monorepo management tool. If wireit could replicate a feature like I'd be happy with any of the proposals @justinfagnani put forward in the original post, but numbers one and three (really the second "2") make the most sense to me. Big fan of this feature. |
You can ignore scripts that don't exist using npm workspaces like this: npm run build -ws --if-present https://docs.npmjs.com/cli/v7/using-npm/workspaces#ignoring-missing-scripts
See also #23, which would provide an explicit way to say "run <script> in all of my workspaces". Do either or both of those sound like they would work for your use case, @calebdwilliams ? |
@aomarks that would work assuming it follows the If we can somehow opt in to caching across all packages inside the workspace that would be ideal. And if we could have a dependencies keyword that opted in to assumed script dependencies based on the package dependencies, that would be 🔥. |
I've moved from |
Could you provide an example of where you would like to use this feature? I am curious about whether #23 (support |
Closing in favor of #23 |
I think a lot of monorepos will have scripts that depend on basically all subpackages. Take lit.dev's
build
script:This list is prone to getting out of sync as packages are added. That might be caught quickly when the project doesn't build correctly, but the list is still cumbersome.
Lerna and npm solve this by allowing you to run a script by name in any package that has that script. I could see wireit supporting something similar in a few ways:
"workspaces"
fieldThis would read the
"workspaces"
field as a single source of truth for the list of all subpackages and run thebuild
script in each:This version of the idea would really only be useful on the top-level package. To work in workspaces automatically would require some magic around looking at which dependencies are local to the monorepo and running scripts in them. Maybe that's doable.
Since packages would still need their scripts and dependencies specified, even if auto, it seems like this wouldn't require wireit to topo-sort the packages.
The text was updated successfully, but these errors were encountered: