corepack is not removed when downgrading node
Tobbe opened this issue · comments
Bug Report
Summary
corepack is not removed when downgrading node
If I understand correctly corepack should be available with node v >= 16.9 (from reading n's changelog https://github.com/tj/n/blob/master/CHANGELOG.md#750-2021-09-26)
So if/when I downgrade to node 16.0 I should no longer have access to corepack
Steps to Reproduce
❯ n 18
installing : node-v18.18.2
mkdir : /usr/local/n/versions/node/18.18.2
fetch : https://nodejs.org/dist/v18.18.2/node-v18.18.2-darwin-arm64.tar.xz
copying : node/18.18.2
installed : v18.18.2 (with npm 9.8.1)
❯ corepack -v
0.19.0
❯ n 20
installing : node-v20.10.0
mkdir : /usr/local/n/versions/node/20.10.0
fetch : https://nodejs.org/dist/v20.10.0/node-v20.10.0-darwin-arm64.tar.xz
copying : node/20.10.0
installed : v20.10.0 (with npm 10.2.3)
❯ corepack -v
0.22.0
❯ n 16.0
installing : node-v16.0.0
mkdir : /usr/local/n/versions/node/16.0.0
fetch : https://nodejs.org/dist/v16.0.0/node-v16.0.0-darwin-arm64.tar.xz
copying : node/16.0.0
installed : v16.0.0 (with npm 7.10.0)
❯ corepack -v
0.22.0
Expected Behaviour
corepack should not be available when downgrading to a version of node that didn't ship with corepack
Actual Behaviour
corepack is left at whatever version it was before downgrading. So if I previously was on node 18.18.2 I keep corepack v 0.19.0. If I downgrade from node 20.10.0 I keep corepack v 0.22.0
Other Information
n was initially installed by homebrew. I kept the default directories for where it wants to manage node versions. I updated permissions on those directories to allow access.
❯ realpath $(which corepack)
/usr/local/lib/node_modules/corepack/dist/corepack.js
Configuration Details
❯ n --version
v9.2.0
❯ command -v node
/usr/local/bin/node
❯ node -p process.platform
darwin
(Thanks for the clear description.)
Simplifying a bit, n
installs the specified version of Node.js over whatever is there. corepack
is included as a global npm package rather than a separate binary. While earlier versions of Node.js did not include corepack
, the user may have installed it themselves.
The current implementation of n
just leaves corepack
alone when you install older Node.js
versions without core pack
.
Here is an example scenario where it would not make sense for n
to delete corepack
:
% n 15
copying : node/15.14.0
installed : v15.14.0 (with npm 7.7.6)
% corepack --version
zsh: command not found: corepack
% npm install -g corepack@0.17.2
added 1 package in 1s
% corepack --version
0.17.2
% n 16.0.0
copying : node/16.0.0
installed : v16.0.0 (with npm 7.10.0)
% corepack --version
0.17.2
% n lts
copying : node/20.10.0
installed : v20.10.0 (with npm 10.2.3)
% corepack --version
0.22.0
Thanks for getting back to me.
corepack is included as a global npm package rather than a separate binary.
So to simulate a "clean" Node 15 installation I can just do this?
% n 15
% npm -g rm corepack
Yes. (I would suggest doing the commands in the other order just in case the version of node makes a difference to the result of the uninstall.)
% npm -g rm corepack
% n 15
Thank you!
I ran into this because I was debugging an issue that involved yarn, corepack and homebrew. That's now in a good enough state, so I'm (probably) not going to be messing with corepack at this level any more.
Thanks again for taking the time to assist here 🙏