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

Created an NpxToolBase as an inheritable Subsystem for nodejs tools #17567

Merged
merged 3 commits into from
Nov 18, 2022

Conversation

sureshjoshi
Copy link
Member

Added support for a version option to Prettier and Pyright via an NpxToolBase.

Some day in the future, I would like to see Subsystem mixins for this type of common, repeated functionality - but that's a longer discussion.

Closes (#17557)

[ci skip-rust]
[ci skip-build-wheels]

from pants.option.subsystem import Subsystem


class NpxToolBase(Subsystem):
Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to bikeshed on this name. NpxToolBase, NodeToolBase, NpmToolBase - I'm not sure which is the most precise, but extensible... Also may not matter, since it can always be changed later if need be.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say NodeToolBase? We call the Python equivalent PythonToolBase, not PipToolBase or PyPIToolBase.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is somewhat complicated -- I suggest NpxToolBase, as npx is a tool launcher, and node is not (it's an arbitrary script launcher).

Copy link
Member Author

Choose a reason for hiding this comment

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

it's an arbitrary script launcher

Feels like that would line up more with PythonToolBase in that case.

The only reason I was thinking NodeToolBase is that fundamentally, all of the tools need to be NodeJS tools. However, the same logic applies to npm and npx since it's the same ecosystem and suite of tools.

In Slack, @kaos mentioned

I’m not sure if there’ll ever be a risk for another node tool to not fit under that subsystem.
That's a point I just never thought about - and I don't know if it's the case or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Things launched by yarn come to mind as a good reason for being specific about the launcher.

Copy link
Contributor

Choose a reason for hiding this comment

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

Node is a runtime, so these are "tools that run on node" in the same way that PythonToolBases "run on the python interpreter" and JvmToolBases run on the JVM. So I think NodeToolBase is the right parallel?

Very roughly, Npx is to Node as Pip is to Python as Coursier is to JVM?

Copy link
Member Author

Choose a reason for hiding this comment

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

Leaving NpxToolBase for now. Down the road when we think about potentially incorporating yarn, pnpm, or whatever the flavour of the month is in the future - we can revisit.

@benjyw npx isn't a package manager per se, but (more or less) an alias for "npm install" and then "npm exec" (https://docs.npmjs.com/cli/v7/commands/npx#npx-vs-npm-exec). So, npm is the pip.

This line of thinking has gotten me to the conclusion that NpxToolBase is better for now, specifically because it brings with it one piece of implicit info. The package MUST be executable with a bin folder/file specified in the package.json.

For example: npx dayjs errors out with npm ERR! could not determine executable to run.

So, NpmToolBase is incorrect, because the intention is an executable package. And for the same reason, I think NodeToolBase is incorrect, as you can put in Node packages which aren't executable, and then this ToolBase would be useless (without adding some extra flags, options, and shenanigans).

@sureshjoshi sureshjoshi added backend: JavaScript JavaScript backend-related issues category:bugfix Bug fixes for released features labels Nov 17, 2022
@stuhood stuhood requested review from chrisjrn and removed request for stuhood November 17, 2022 21:45
@stuhood
Copy link
Member

stuhood commented Nov 17, 2022

Thanks! I'll bow out in favor of @chrisjrn, who is looking at stuff in this area.

@sureshjoshi
Copy link
Member Author

Thanks! I'll bow out in favor of @chrisjrn, who is looking at stuff in this area.

Cool beans - I added you for those test/query/subsystem shenanigans you just taught me about.

I actually don't know which maintainers to add on which languages. Like, not sure who the resident node or js person is...

Copy link
Contributor

@chrisjrn chrisjrn left a comment

Choose a reason for hiding this comment

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

This seems fine (and I think NpxToolBase is the right name for now)

Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

@sureshjoshi I'll leave it to you to decide re name.

@sureshjoshi sureshjoshi merged commit 800d4bc into pantsbuild:main Nov 18, 2022
@sureshjoshi sureshjoshi deleted the 17557-npx-dep-version branch November 18, 2022 01:52
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Very exciting :D Thanks SJ!

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.

5 participants