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
feat(env): add remove command to pnpm env #5263
Conversation
💖 Thanks for opening this pull request! 💖 |
you can do refactoring if you want. |
@zkochan I'll do the refactoring in a separate PR, maybe together with the I've noticed that one of the CI for Node.js 14.6 was failing, I went to check and figured there's Node.js API I was using that didn't exist back then, I've added a workaround for that specific API, hope that was worth it. |
I think |
- Fix broken node path for the windows platform - Notify user when removing default Node.JS - Remove `await` on `fs.unlink` in `Promise.all` - Add support for Node.JS v14.13 and earlier
- Add `rm, un, uninstall` aliases to the `remove` command - Update CLI help message - Ignore only `ENOENT` errors
5ea3769
to
31e4d25
Compare
@zkochan, I've made the necessary changes and adjusted the tests to pass on the Windows platform. I don't have one available for testing locally, will have to see if it's working on the CI. |
name: 'remove\nuninstall', | ||
shortAlias: 'rm,\nun', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just write remove and rm
name: 'remove\nuninstall', | |
shortAlias: 'rm,\nun', | |
name: 'remove', | |
shortAlias: 'rm', |
.changeset/long-trainers-share.md
Outdated
"@pnpm/plugin-commands-env": minor | ||
--- | ||
|
||
Enhance `pnpm env` with the `uninstall` command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhance `pnpm env` with the `uninstall` command. | |
Enhance `pnpm env` with the `remove` command. |
name: 'use', | ||
}, | ||
{ | ||
description: 'Uninstalls the specified version of Node.JS.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: 'Uninstalls the specified version of Node.JS.', | |
description: 'Removes the specified version of Node.JS.', |
]).catch(err => { | ||
const { code = '' } = err | ||
|
||
if (code.toLowerCase() !== 'enoent') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be also upper case. No need to lower it
if (code.toLowerCase() !== 'enoent') { | |
if (code !== 'ENOENT') { |
await Promise.all([ | ||
fs.unlink(nodePath), | ||
fs.unlink(npmPath), | ||
fs.unlink(npxPath), | ||
]).catch(err => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use a try/catch syntax
await Promise.all([ | |
fs.unlink(nodePath), | |
fs.unlink(npmPath), | |
fs.unlink(npxPath), | |
]).catch(err => { | |
try { | |
await Promise.all([ | |
fs.unlink(nodePath), | |
fs.unlink(npmPath), | |
fs.unlink(npxPath), | |
]) | |
} catch (err) { | |
if (err.code !== 'ENOENT') throw err |
/** | ||
* Support for earlier Node.JS versions | ||
* `fs.rmdir` is deprecated and `fs.rm` was added in v14.14.0 | ||
* @see https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fsrmpath-options-callback | ||
*/ | ||
if (Number(processMajorVersion) === 14 && Number(processMinorVersion) <= 13) { | ||
await fs.rmdir(versionDir, { recursive: true }) | ||
} else { | ||
await fs.rm(versionDir, { recursive: true }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use this rimraf lib:
pnpm/packages/core/package.json
Line 56 in d904b83
"@zkochan/rimraf": "^2.1.2", |
- Use `remove` with `rm` alias only - Update CLI help message - Update tests to use `remove` command - Replace custom support for older Node.JS versions with `@zkochan/rimraf`
|
||
const opts = { | ||
env: { | ||
[PATH]: `${process.cwd()}${path.delimiter}${process.env[PATH] as string}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this test works. Even if you remove the node.js from home path, won't execa pick the system installed node.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I didn't have the capacity to respond yesterday.
So, you're correct, it should have picked other (in my case nvm) installed versions. I was going to restrict path to only the current folder, but I see that you've done that already.
I think it's worth mentioning that execa, for some reason (I didn't get the chance to investigate further yet) tries to resolve the "node" in the temp folder first, I'm not sure why that's happening exactly.
Anyway, thanks for merging!
Congrats on merging your first pull request! 🎉🎉🎉 |
my pnpm is died 😭 help |
Summary
This PR enhances the
pnpm env
functionality with theuninstall
command, allowing to uninstall Node.JS globally, that was previously installed withpnpm env use <version>
.Partially closes #5155
Listing installed Node.JS will be done in a separate PR, I'm trying to keep this one short.
Note to reviewers
I think there's room for refactoring, but for now, I just tried to follow what's already in place. If refactoring is an option, I could work on it furthermore.