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(misc): fix moving projects with standalone configuration #6521

Merged
merged 1 commit into from Jul 29, 2021

Conversation

leosvelperez
Copy link
Member

Current Behavior

Moving a project with a standalone configuration adds the updated configuration to workspace.json instead of updating the corresponding project.json. This happens when not all the projects are using standalone configuration or when the project being moved is the only project in the workspace.

Expected Behavior

Moving a project with a standalone configuration should update the standalone configuration correctly.

Related Issue(s)

Fixes #6512

@leosvelperez leosvelperez self-assigned this Jul 27, 2021
@vercel
Copy link

vercel bot commented Jul 27, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/7HoJ5wg6fbDqkKcSi2skz3JD9uC5
✅ Preview: https://nx-dev-git-fork-leosvelperez-fix-move-standalone-project-nrwl.vercel.app

* @param host - the file system tree
* @param project - the project name
*/
export function isStandaloneProject(host: Tree, project: string): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this and use getWorkspaceLayout(host).standaloneAsDefault instead?

@@ -12,6 +13,7 @@ export function moveProjectConfiguration(
schema: NormalizedSchema,
projectConfig: ProjectConfiguration & NxJsonProjectConfiguration
) {
const isStandalone = isStandaloneProject(tree, schema.projectName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use getWorkspaceLayout(host).standaloneAsDefault so we don't have to add the new function?

It should work in this case because the current move logic already moves the project.json file appropriately.

From what I saw, this could also be solved somewhat hackily by moving addProjectConfiguration after removeProjectConfiguration. But I think reading whether it should be standalone or not and then explicitly saying to add a standalone is a better option.

Copy link
Member Author

Choose a reason for hiding this comment

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

That wouldn't be right for a couple of reasons:

  • getWorkspaceLayout(host).standaloneAsDefault will only be true if all projects in the workspace are configured as standalone, you'd expect that to normally be the case, either all or none, but that's an assumption, not a fact. Even our generator to convert projects into standalone config offers the ability to specify a project, it's not mandatory to convert the whole workspace.
  • It can't be solved by having addProjectConfiguration before removeProjectConfiguration, because there are cases where the project name for the destination is the same as the old destination (e.g. moving domain-project to domain/project, both results in the name domain-project). A couple of issues have been created because of that, and I previously worked on solving those. In that scenario, if you try to add the project first, you get an error because it already exists.

The need here is to know if the project being moved is configured as standalone or not, that doesn't match what getWorkspaceLayout(host).standaloneAsDefault returns (whether all projects in the workspace are configured as standalone).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah okay, I see

@@ -12,6 +13,7 @@ export function moveProjectConfiguration(
schema: NormalizedSchema,
projectConfig: ProjectConfiguration & NxJsonProjectConfiguration
) {
const isStandalone = isStandaloneProject(tree, schema.projectName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah okay, I see

@FrozenPandaz FrozenPandaz merged commit 7d6837c into nrwl:master Jul 29, 2021
@leosvelperez leosvelperez deleted the fix-move-standalone-project branch October 1, 2021 14:12
@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 20, 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.

@nrwl/workspace:move resets standaloneConfig project, deletes project.json
2 participants