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

Restore npm 6 ability to install one package #364

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

dandv
Copy link
Contributor

@dandv dandv commented Apr 8, 2021

No description provided.

@ljharb
Copy link
Contributor

ljharb commented Apr 8, 2021

In a few projects, I have scripts to explicitly install and uninstall single packages, for the purposes of testing different combinations. For example, enzyme needs to test on a number of combinations of react, react-dom, and a few other packages - but every time I install one of them, other unrelated changes happen to the package tree.

@darcyclarke darcyclarke added the Agenda will be discussed at the Open RFC call label Apr 14, 2021
@isaacs
Copy link
Contributor

isaacs commented Apr 20, 2021

Is this solved by npm i --workspace=foo, which links the foo workspace and only installs its portion of the dependency graph?

It wouldn't be too hard to apply a similar filter to non-workspace package names, now that Arborist.reify can do this for workspaces. Just would need to figure out the best way to express it in the API surface.

@isaacs isaacs changed the title Create 0000-install-single-package.md Restore NPM 6 ability to install one package May 5, 2021
@isaacs isaacs changed the title Restore NPM 6 ability to install one package Restore npm 6 ability to install one package May 5, 2021
@isaacs
Copy link
Contributor

isaacs commented May 5, 2021

Adding context here:

This was only the behavior in npm v6 if a package-lock.json file is not present. Otherwise, it'll still install everything in the lockfile.

npm v7 is by design more consistent in its behavior when a lockfile is present vs when it is not.

If we are going to add this, it will have to be an opt-in feature. Breaking the default (which was the default in v6, since lockfiles were created by default in v6) would be too disruptive. Making npm v7 behave differently based on the presence of a lockfile (beyond the difference of "using that as a starting point for the idealTree") is not something we're going to want to do.

All that said, it won't be hard to do. Just need to figure out the UX for which flags to use, how to opt in, etc., and then build up the set of filterNodes in Arborist.reify()

dandv and others added 2 commits May 5, 2021 22:21
Co-authored-by: Tierney Cyren <accounts@bnb.im>
Co-authored-by: Tierney Cyren <accounts@bnb.im>
@darcyclarke darcyclarke added Agenda will be discussed at the Open RFC call and removed Agenda will be discussed at the Open RFC call labels Jun 9, 2021
@darcyclarke
Copy link
Contributor

I feel like this will be succeeded by the npm add RFC @ruyadorno is going to write (ref. #395) - If I'm wrong let me know, but we don't have any immediate action items to introduce a net-new flag to do this vs. implementing add in a way that unlocks this again.

@darcyclarke darcyclarke removed the Agenda will be discussed at the Open RFC call label Jun 16, 2021
@kgryte
Copy link

kgryte commented Aug 12, 2021

In projects that I work on, we'd also like to be able to install only one package (or a subset of packages) without needing to install the whole dependency tree as suggested in a package.json file.

Similar to @ljharb, we want to be able to dynamically uninstall and install dependencies for testing, benchmarking, etc. Not being able to do so (as in npm v6 in the absence of a package-lock.json file) makes npm v7 unusable for us.

@cbn-falias
Copy link

cbn-falias commented Aug 19, 2021

Another usecase:
A very simple job should check if all files of a Pull Request are correctly formatted with Prettier. So I only need this single package and nothing else.
The prettier package is installed in some seconds while installing all the packages takes over one minute (and eats up precious processing time).

@bnb
Copy link

bnb commented Aug 20, 2021

@cbn-falias would npm exec prettier not be a better solution in that case?

@louh
Copy link

louh commented Aug 21, 2021

I have a Node.js script that will require packages that it needs, so I'd like to install just those packages beforehand in test environments. I don't think I can run npm exec on a script and have it dynamically fetch the packages I require.

@ljharb
Copy link
Contributor

ljharb commented Aug 21, 2021

@louh you can run npm exec --yes in a script and have it dynamically fetch the packages, assuming it has internet access.

@cbn-falias
Copy link

@bnb Yes this would also work but I don't see a way to use it with configurations from package.json. (without writing my own shell-script or similar)

  • Use version defined in package.json
  • Run a script defined in scripts

@bnb
Copy link

bnb commented Aug 23, 2021

@cbn-falias I can understand that use case, but I don't know how this would solve that problem as proposed - you'd still need to get the version from the package.json if you passed --only to ensure you don't overwrite the package's version the way npm would normally when it installs a module.

@kgryte
Copy link

kgryte commented Aug 24, 2021

Another use case we have is that we periodically need to investigate issues in older Node.js versions which are not officially supported. Various dependencies may have dropped support for such versions, so we've taken to maintaining a set of config files listing versions of those dependencies which are compatible with the older Node.js versions. We then have scripts which read those config files and selectively try to install those dependencies so that we can run in older Node.js versions.

With npm v7, we have to introduce workarounds, such as temporarily copying and overwriting the main package.json which is not desirable. Ideally, we should be able to install, uninstall, and reinstall without needing to touch the package meta data which is published to the npm package registry.

@aleen42
Copy link

aleen42 commented Dec 21, 2021

Any progress?

@cbn-falias
Copy link

I ended up extracting the version with a powershell-script and then calling it this way:

npm exec --package=$(prettierXmlPckg) --package=$(prettierPckg) --call="npm run formatter-list-diff"

// $(prettierXmlPckg) -> "@prettier/plugin-xml@1.0.2"
// $(prettierPckg) -> "prettier@2.3.2"

@bnb
Copy link

bnb commented Dec 27, 2021

@darcyclarke (when you're back from vacation): perhaps worth putting this on the agenda again?

@ljharb
Copy link
Contributor

ljharb commented Dec 27, 2021

Yes please; it continues to be a massive annoyance and inconvenience to be unable to have an atomic command do a thing atomically.

@nielspruis
Copy link

Is there any update on how this feature will be implemented?

@darcyclarke
Copy link
Contributor

No detail given but we have a tracking issue right now for v9 here: npm/statusboard#464

At a high-level though (from previous discussions) I believe we'd start warning when npm install <pkg> is used (vs. npm add <pkg>) & then we'd likely start remove that feature in v9 & have npm add be a completely separate command (as right now it's an alias to install).

@ljharb
Copy link
Contributor

ljharb commented May 25, 2022

@darcyclarke hopefully we'd add npm add pkg before warning on npm install pkg?

@ljharb
Copy link
Contributor

ljharb commented May 25, 2022

although i'm not clear on why npm install pkg wouldn't be Just Fine, considering that's how it always worked prior to npm 7?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants