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): merge more target options from targetDefaults #12435

Merged

Conversation

AgentEnder
Copy link
Member

@AgentEnder AgentEnder commented Oct 5, 2022

Current Behavior

Target defaults may only contain dependsOn, inputs, outputs etc and can only be applied based on the name of the target.

New Behavior

Target defaults may contain any property inside TargetConfiguration, and can be applied based on targetName, executorName, or both.

Keys in the mapping can be any of the following:

  • `${executor}`
  • `${targetName}`

A # symbol is used as a separator between targetName and executorName. This is analogous to how we can specify an export in a module when writing a generator's implementation path. build#nx:run-commands would indicate any target named build that uses nx:run-commands as the executor.

When merging defaults, options are merged 1 layer deep. Additionally, {projectRoot} and {workspaceRoot} are valid within targetDefaults. As an example, merging the defaults

{
  path: "{workspaceRoot}/{projectRoot}
  other: "hello"
  optimization: {
    "a": true
  }
}

with the provided options:

{
  optimization: {
    "b": true
  }
}

would result in:

{
  path: "libs/my-lib"
  other: "hello"
  optimization: {
    "b": true
  }
}

Related Issue(s)

Fixes #12433

@vercel
Copy link

vercel bot commented Oct 5, 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:50PM (UTC)

@AgentEnder AgentEnder force-pushed the feat/merge-more-from-target-defaults branch from d78feda to f797af7 Compare October 6, 2022 18:12
@AgentEnder AgentEnder changed the title feat(core): merge target options from targetDefaults [15.1] feat(core): merge target options from targetDefaults Oct 7, 2022
@minijus
Copy link
Contributor

minijus commented Oct 11, 2022

Nice! This will allow to set executor defaults as suggested in rather old discussion: #8544 (comment)

@luxaritas
Copy link
Contributor

luxaritas commented Oct 22, 2022

Does this also wind up finishing resolution of #9100? Or is there liable to be further work there?

@AgentEnder AgentEnder force-pushed the feat/merge-more-from-target-defaults branch from f797af7 to cb23961 Compare December 23, 2022 04:16
packages/nx/src/config/workspaces.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.ts Outdated Show resolved Hide resolved
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.

This is good. Some comments:

  • The docs don't cover everything. We should update the Nx repo to use this feature, dog food it and then write a recipe. Can you create tasks for it?
  • I think your code can be clearer if you select better names. It's kind of hard to parse cause names appear somewhat random.

packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
packages/nx/src/config/workspaces.spec.ts Outdated Show resolved Hide resolved
docs/shared/reference/nx-json.md Show resolved Hide resolved
@AgentEnder
Copy link
Member Author

The docs don't cover everything. We should update the Nx repo to use this feature, dog food it and then write a recipe. Can you create tasks for it?

Yeah, I'll make them :)

I think your code can be clearer if you select better names. It's kind of hard to parse cause names appear somewhat random.

This is a fair criticism, I'm especially bad about this when writing tests. I'll correct the naming as pointed out. Thanks Victor!

@AgentEnder AgentEnder force-pushed the feat/merge-more-from-target-defaults branch from 63e5abb to d056d03 Compare December 29, 2022 22:41
@AgentEnder AgentEnder changed the title [15.1] feat(core): merge target options from targetDefaults feat(core): merge more target options from targetDefaults Dec 29, 2022
@AgentEnder AgentEnder enabled auto-merge (squash) December 29, 2022 22:45
@AgentEnder AgentEnder merged commit c783ac5 into nrwl:master Dec 29, 2022
@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.

expand scope of allowable fields for targetDefaults
4 participants