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(core): read project name from package json if not set in project json #26386

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

AgentEnder
Copy link
Member

Current Behavior

If project.json exists without a name, we infer one based on the root path. This can be confusing when there exists a package.json alongside it that contains a name which doesn't match our inferred name.

Expected Behavior

If project.json and package.json both exist, the name from package.json will be used if project.json contains no name.

Related Issue(s)

Fixes #26347

@AgentEnder AgentEnder requested a review from a team as a code owner June 5, 2024 14:17
@AgentEnder AgentEnder requested a review from xiongemi June 5, 2024 14:17
Copy link

vercel bot commented Jun 5, 2024

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

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Jun 11, 2024 10:24pm

@AgentEnder AgentEnder force-pushed the fix/project-name-project-json-package-json branch from 12d3bd6 to 8d7724b Compare June 7, 2024 16:52
export function readNameFromPackageJson(path: string): string {
try {
const json = readJsonFile<PackageJson>(path);
return buildProjectConfigurationFromPackageJson(json, path, {}).name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not reuse this function. Just read the correct properties.

@AgentEnder AgentEnder force-pushed the fix/project-name-project-json-package-json branch 2 times, most recently from 2e67567 to 22eb068 Compare June 10, 2024 17:22
@AgentEnder AgentEnder requested a review from FrozenPandaz June 10, 2024 21:24
projectJson.name = toProjectName(root);
writeJson(tree, `${root}/project.json`, projectJson);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please format files.

// For existing projects, if the name is not set, we can inline it
// based on the existing logic. This makes sure folks aren't caught
// off guard by the new behavior.
if (!projectJson.name) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if we have really changed the name before updating.

@@ -83,6 +83,12 @@
"version": "19.2.2-beta.0",
"description": "Updates the nx wrapper.",
"implementation": "./src/migrations/update-17-3-0/update-nxw"
},
"19-2-3-set-project-name": {
"version": "19.2.3-beta.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll have to update the version

@AgentEnder AgentEnder force-pushed the fix/project-name-project-json-package-json branch 3 times, most recently from b1f37e1 to 92b3112 Compare June 11, 2024 22:12
@AgentEnder AgentEnder force-pushed the fix/project-name-project-json-package-json branch from 92b3112 to bea9f46 Compare June 11, 2024 22:22
@AgentEnder AgentEnder requested a review from FrozenPandaz June 12, 2024 14:50
@FrozenPandaz FrozenPandaz merged commit 5d56e21 into master Jun 12, 2024
6 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/project-name-project-json-package-json branch June 12, 2024 15:18
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 Jun 19, 2024
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.

package name is not inferred from scope without project.json file
2 participants