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): expand support for projectRoot token to include project.json #18302

Merged

Conversation

AgentEnder
Copy link
Member

Current Behavior

{projectRoot}, {projectName}, and {workspaceRoot} only work inside options or configurations blocks as part of targetDefaults in nx.json, but works in inputs / outputs in project.json already.

Expected Behavior

{projectRoot}, {projectName}, and {workspaceRoot} only work inside inputs, outputs, options, and configurations everywhere.

Related Issue(s)

Fixes #13272

@AgentEnder AgentEnder requested a review from a team as a code owner July 25, 2023 15:14
@vercel
Copy link

vercel bot commented Jul 25, 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 Aug 3, 2023 8:13pm

Comment on lines 614 to 434
const workspaceRootMatch = /^(\{workspaceRoot\}\/?)/.exec(value);
if (workspaceRootMatch?.length) {
value = value.replace(workspaceRootMatch[0], '');
} else if (value.includes('{workspaceRoot}')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The handling for this changed a bit as I noticed a potential bug when doing it. If an option represented a path to a directory, {workspaceRoot} may be a valid value for that, and this would throw as before we required it to have a / after it.

@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from e4410ca to 67a5d78 Compare July 25, 2023 18:09
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from 67a5d78 to 8a9cdcc Compare July 25, 2023 19:20
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from 8a9cdcc to 588a7cc Compare July 26, 2023 15:22
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from 588a7cc to 32937fc Compare July 26, 2023 16:00
@AgentEnder AgentEnder self-assigned this Jul 26, 2023
@AgentEnder AgentEnder added the scope: core core nx functionality label Jul 26, 2023
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from 32937fc to f5ffb28 Compare July 26, 2023 16:31
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from f5ffb28 to f035cb2 Compare July 26, 2023 18:30
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from f035cb2 to 62407ab Compare July 26, 2023 18:39
@AgentEnder AgentEnder force-pushed the feat/allow-tokens-in-project-json branch from 62407ab to ca37e30 Compare July 26, 2023 20:28
Comment on lines 406 to 425
const result: T = { ...defaults };
for (const key in options) {
// Deep merge options objects, but not arrays.
if (
typeof options[key] === 'object' &&
typeof defaults?.[key] === 'object' &&
!Array.isArray(options[key]) &&
!Array.isArray(defaults?.[key])
) {
result[key] = mergeOptions(defaults[key], options[key]);
} else {
// The types are either:
// - primitive (string, number, boolean, etc.)
// - arrays
// - different types (e.g. string vs array)
// In any case, we want to override the default with the options.
result[key] = options[key];
}
}
return result;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not have deep-merging in this PR. It should be separate

const workspaceRootMatch = /^(\{workspaceRoot\}\/?)/.exec(value);
if (workspaceRootMatch?.length) {
value = value.replace(workspaceRootMatch[0], '');
} else if (value.includes('{workspaceRoot}')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to remain 2 if blocks

@AgentEnder AgentEnder merged commit 1a1cb4f into nrwl:master Aug 3, 2023
15 checks passed
@divideby0
Copy link

nice! thank you for your work on this. i was running into this exact challenge earlier in the day with package/api/some/path/file.ts hard-coded in a number of command arguments. will this be out in the next release?

@github-actions
Copy link

github-actions bot commented Aug 9, 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 Aug 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope: core core nx functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using {projectRoot} in my commands
3 participants