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

fix(js): properly identify buildable project #17798

Closed
wants to merge 1 commit into from

Conversation

mandarini
Copy link
Member

@mandarini mandarini commented Jun 26, 2023

Current Behavior

Right now, we identify if a project is buildable like this:

function isBuildable(target: string, node: ProjectGraphProjectNode): boolean {
  return (
    node.data.targets &&
    node.data.targets[target] &&
    node.data.targets[target].executor !== ''
  );

The target there is the name of the build target of a parent project. In that function, we try to understand if a project's dependency is buildable. This technique is flawed, since we cannot know for sure the name of the build target, and we cannot assume it's the same as the parent project's build target name.

This results in this: If one project imports another project, both projects' build targets need to have the same name. If projects have different names for the build target, then you get an irrelevant error.

Expected Behavior

isBuildable should not rely on a parent project's build target name, but rather look through the child project's executors, and find if it has an executor which is a build executor.

Retain existing behaviour to avoid breaking changes, and also allow it to work for build executors of other plugins (not @nx/*).

Related Issue(s)

Fixes #17764

@mandarini mandarini requested a review from jaysoo June 26, 2023 17:01
@mandarini mandarini requested a review from a team as a code owner June 26, 2023 17:01
@mandarini mandarini self-assigned this Jun 26, 2023
@vercel
Copy link

vercel bot commented Jun 26, 2023

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

Name Status Preview Comments Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2023 8:36am

@nx-cloud
Copy link

nx-cloud bot commented Jun 26, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1306531. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@mandarini mandarini force-pushed the fix/identify-buildable branch from 8d7798b to 3bbd80a Compare June 27, 2023 08:10
Copy link
Member

@leosvelperez leosvelperez left a comment

Choose a reason for hiding this comment

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

One thing to consider is that while this addresses the issue for projects using that list of executors, it leaves out projects that might be using executors from third-party plugins or even nx:run-commands.

This would be a breaking change for any workspace using such a setup. Maybe that was never intended to be supported and it was meant to be used only with executors from first-party plugins (I don't know), but the implementation allowed using others and folks might be using it.

If we don't want to add such a constraint and make a breaking change now, what about we add this new solution as a fallback to the previous one? The previous solution is quicker and would correctly catch the buildable dependency for some scenarios. If we don't find the target, then we look for known executors.

That would still address the issue while keeping the existing behavior. I would avoid changing the current behavior because we might change this later by using the TaskGraph instead of the ProjectGraph. The executor context now contains the task graph, so we can use it now. The project graph knows nothing about target dependencies, but the task graph does.

@mandarini
Copy link
Member Author

mandarini commented Jun 27, 2023

@leosvelperez sure, I'll keep the old way in there, too, as a fallback to the new way! Sounds like a good practice, indeed! Maybe this should somehow be in the docs, though, too? @juristr what do you think? For a later addition, of course, not as part of this PR. Like, if you have dependencies, keep the name of the build target consistent, to make sure third-party plugins work?

@leosvelperez
Copy link
Member

leosvelperez commented Jun 27, 2023

Maybe this should somehow be in the docs, though, too? @juristr what do you think? For a later addition, of course, not as part of this PR. Like, if you have dependencies, keep the name of the build target consistent, to make sure third-party plugins work?

It's in some docs https://nx.dev/recipes/other/setup-incremental-builds-angular#build-target-name, but it should probably be generalized here https://nx.dev/more-concepts/incremental-builds. That said, the requirement might change soon, if we get to refactor this to use the task graph. When that happens, the target name will no longer be relevant and I think the only relevant thing will be the outputs which is what is consumed with buildable libraries. So maybe we don't rush updating the docs because they might change soon.

@mandarini mandarini requested review from jaysoo and leosvelperez June 27, 2023 08:23
@mandarini mandarini force-pushed the fix/identify-buildable branch 3 times, most recently from 761507e to cd6a5fa Compare June 27, 2023 08:29
@mandarini mandarini force-pushed the fix/identify-buildable branch from cd6a5fa to e371193 Compare June 27, 2023 08:30
@mandarini
Copy link
Member Author

Closing this, and will incorporate in a new effort to refactor some things. For now, the solution to this issue is one of the two:

  1. Both build targets should have the same name

OR

  1. In the child project, create a "dummy" build target that depends on the intended build target, like so:
    "new-build": {
      "dependsOn": ["build"],
      "command": "echo dummy build",
      "options": {
        "outputPath": "dist/libs/mylib",
        "tsConfig": "libs/mylib/tsconfig.lib.json"
      }
    },
    "build": {
      "executor": "@nx/js:tsc",
...

@mandarini mandarini closed this Jun 27, 2023
@github-actions
Copy link

github-actions bot commented Jul 3, 2023

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 Jul 3, 2023
@mandarini mandarini deleted the fix/identify-buildable branch August 22, 2023 12:32
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.

js:tsc executor fails when run in a target not named "build"
4 participants