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

(JavaScript) Throw a more descriptive error when the package name is missing #21159

Merged

Conversation

krishnan-chandra
Copy link
Contributor

@krishnan-chandra krishnan-chandra commented Jul 11, 2024

Closes #20859.

While this is a simple fix and addresses the linked issue, there is an interesting edge case to discuss:

Internal packages do not necessarily have a name field in package.json (see wireapp/wire-desktop#1692, facebook/react#13107 for examples). The JavaScript backend in Pants does require that each package.json define a name, but I'm not so sure that's necessarily the right behavior.

It's worth considering whether we should make names optional in Pants, given that larger JavaScript monorepos may have internal packages that are not meant to be published. Furthermore, different JS package managers handle this situation differently -

@krishnan-chandra krishnan-chandra added backend: JavaScript JavaScript backend-related issues category:bugfix Bug fixes for released features labels Jul 11, 2024
@krishnan-chandra krishnan-chandra requested review from huonw and tobni July 11, 2024 16:16
Copy link
Contributor

@tobni tobni left a comment

Choose a reason for hiding this comment

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

LGTM!

The reason for requiring it is that it makes it easier for pants to "talk about the packages", we use it to name targets, match for dep-inference, workspace invocations use package names, and also in logs and the like.

We could auto-generate a "description" and use that instead for logs and targets, but I suspect it'll be easier for users to know what pants is talking about if they named the thing.

There are also package manager commands that fail when packages lack names (depends on versions and what fallbacks are in place but workspaces are name based).

The argument of a package being private is valid, but there's a "private": true attribute for that.

@krishnan-chandra
Copy link
Contributor Author

Yeah, it doesn't really seem that there is agreement around the ecosystem about how to deal with this issue, so the safest option is probably to require the package to have a name and call it a day 🤷‍♂️

That's good enough for me, ty for the explanation!

@tobni tobni merged commit 7b2dcad into pantsbuild:main Jul 11, 2024
25 checks passed
@krishnan-chandra krishnan-chandra deleted the raise-error-when-package-name-not-set branch July 11, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: JavaScript JavaScript backend-related issues category:bugfix Bug fixes for released features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cryptic error when package.json is missing a name
2 participants