Skip to content
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

feat(core): add glob support for project-level implicit dependencies #13138

Merged

Conversation

AgentEnder
Copy link
Member

Current Behavior

There is no way to specify all other projects as an implicit dependency of project {x}.

Expected Behavior

You can specify "*" in implicit dependencies to specify all other projects as a dependency. This is especially useful in the case of the root project, which may depend on all other projects.

Additionally, if you wanted to specify all other projects, except {x} as a dependency of {y}, then in {y}'s project configuration you could specify:

implicitDependencies: ['*', '!x']

Related Issue(s)

Fixes #

@vercel
Copy link

vercel bot commented Nov 11, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview Dec 29, 2022 at 10:39PM (UTC)

Copy link
Member

@vsavkin vsavkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention this in the docs

Copy link
Collaborator

@FrozenPandaz FrozenPandaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk offline about this.

@AgentEnder AgentEnder force-pushed the feat/core/implicit-dependencies-all branch from b9ed938 to 65ac73c Compare December 22, 2022 22:31
@AgentEnder AgentEnder changed the title feat(core): add implicitDependencies: '*' feat(core): add glob support for project-level implicit dependencies Dec 22, 2022
@AgentEnder AgentEnder force-pushed the feat/core/implicit-dependencies-all branch from 65ac73c to d0123c1 Compare December 22, 2022 22:36
@@ -0,0 +1,35 @@
import minimatch = require('minimatch');

export function findMatchingProjects(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you extracted this into a separate utility which is used in more than place, you can add some tests for this utility

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thats a good shout out. I'll get them added.

implicitDependencies: ProjectConfiguration['implicitDependencies'],
context: ProjectGraphProcessorContext
) {
return findMatchingProjects(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rewrite this function. Currently the normalization of implicit dependencies is O(N^2), where N is the number of projects. In the worst case scenario it will be O(N^2) if say every project depends on every other project via '*', but his worst case scenario is unlikely.

What I would do is:

  • Check if implicitDependencies is empty and skip the whole thing altogether.
  • Check if there are some implicitDependencies using say '*', and if not, just assign them as project names.
  • And only if there are implicitDeps that have special characters, I'd filter our the source and do the matching.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can add some of the short-circuiting logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pushing up the changes here now. To summarize, this is the approach I took:

  • Updated findMatchingProjects to short circuit if the nameOrPattern doesn't contain special characters. In this case, it will add it if its a valid project, and skip the glob matching entirely regardless.
  • If implicit dependencies is null or an empty array, we don't call into findMatchingProjects at all and simply return an empty array.
  • We pass in the list of projectNames to normalizeImplicitDependencies. This should be the biggest boost in perf compared to the last pass at this. Now we find any matching projects, and then filter the source project out of the matches. This should mean filtering a much smaller array for large workspaces.

@AgentEnder AgentEnder enabled auto-merge (squash) December 29, 2022 21:43
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants