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

[RRFC] Query Installs #638

Open
jamiebuilds-signal opened this issue Sep 22, 2022 · 5 comments
Open

[RRFC] Query Installs #638

jamiebuilds-signal opened this issue Sep 22, 2022 · 5 comments
Labels
Agenda will be discussed at the Open RFC call

Comments

@jamiebuilds-signal
Copy link

Motivation ("The Why")

1. Extending the usefulness of npm query

With the new npm query command it's now possible to select subtrees of your dependencies for many different purposes, auditing, inspecting, upgrading dependencies, funding, etc.

For all of these purposes, you sometimes also want the contents of these dependencies as well, even a full install. You can run a full install today, but that tends to take awhile and if you're auditing or want to do something sensitive

2. Allow users to install just the packages they need for a task

For users with sizable installs, npm install is one of the longest steps in their CI process. And oftentimes its not worthwhile to parallelize running separate npm scripts across CI nodes, simply because npm install takes much longer than the script itself.

If you could run:

npm install --query "eslint, [name^=eslint-plugin-], [name^=@typescript-eslint/], typescript"

And get the subtree of your dependencies queried, it would be much faster than trying to run a full npm install/ci and splitting tasks across ci nodes would be much more impactful.

Other tools could be written around npm install --query to make this more powerful by generating queries for you.

3. "Explain" existing features like --production

Features like --production could be implemented via queries, it could be called an alias.

4. Avoid building one-off features in installs

By giving users a powerful querying syntax in installs, many feature requests related to installs could point to this instead.

Example

npm install --query <query>
npm install --query "*:attr(contributors, :attr([name~=Jordan]))"
npm install --query "eslint, [name^=eslint-plugin-], [name^=@typescript-eslint/], typescript"
npm install --query ".prod" # same as `npm install --production`

How

Current Behaviour

N/A, only options are npm install [--production]

Desired Behaviour

  • npm install --query <query>
  • Build the minimal tree that includes all of the dependencies matched by <query>
  • Preserve npm install's other behaviors otherwise

References

Related to #360, #592

@ljharb
Copy link
Contributor

ljharb commented Sep 22, 2022

Queries work on an installed node_modules dir, i thought - it definitely seems like a reasonable addition to npm prune, regardless.

@jamiebuilds-signal
Copy link
Author

Arborist has a loadVirtual() function that works off of the lockfile so I presume the logic is close to there already

@ljharb
Copy link
Contributor

ljharb commented Sep 22, 2022

True - presumably it could also function off the ideal tree in the absence of a lockfile.

@darcyclarke
Copy link
Contributor

@jamiebuilds-signal love that you see the value of the Dependency Selector Syntax/Queries & 100% +1 your understanding/hope for install to support queries. If you read through the original RFC, you can see that pretty much every npm command is on our radar to augment with --query at some point but it may take a bit to fully virtualize @npmcli/arborist so it can use the query syntax when in a state prior to an initial installation/reification.

Love how you've framed this though & appreciate that you're able to see the value here (it may just take some time to implement).

@darcyclarke darcyclarke added the Agenda will be discussed at the Open RFC call label Sep 28, 2022
@rondales
Copy link

Motivation ("The Why")

1. Extending the usefulness of npm query

With the new npm query command it's now possible to select subtrees of your dependencies for many different purposes, auditing, inspecting, upgrading dependencies, funding, etc.

For all of these purposes, you sometimes also want the contents of these dependencies as well, even a full install. You can run a full install today, but that tends to take awhile and if you're auditing or want to do something sensitive

2. Allow users to install just the packages they need for a task

For users with sizable installs, npm install is one of the longest steps in their CI process. And oftentimes its not worthwhile to parallelize running separate npm scripts across CI nodes, simply because npm install takes much longer than the script itself.

If you could run:

npm install --query "eslint, [name^=eslint-plugin-], [name^=@typescript-eslint/], typescript"

And get the subtree of your dependencies queried, it would be much faster than trying to run a full npm install/ci and splitting tasks across ci nodes would be much more impactful.

Other tools could be written around npm install --query to make this more powerful by generating queries for you.

3. "Explain" existing features like --production

Features like --production could be implemented via queries, it could be called an alias.

4. Avoid building one-off features in installs

By giving users a powerful querying syntax in installs, many feature requests related to installs could point to this instead.

Example

npm install --query <query>
npm install --query "*:attr(contributors, :attr([name~=Jordan]))"
npm install --query "eslint, [name^=eslint-plugin-], [name^=@typescript-eslint/], typescript"
npm install --query ".prod" # same as `npm install --production`

How

Current Behaviour

N/A, only options are npm install [--production]

Desired Behaviour

  • npm install --query <query>
  • Build the minimal tree that includes all of the dependencies matched by <query>
  • Preserve npm install's other behaviors otherwise

References

Related to #360, #592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agenda will be discussed at the Open RFC call
Projects
None yet
Development

No branches or pull requests

4 participants