mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-11 09:28:24 -04:00
feat(env): installing the latest Node.js version (#3879)
ref https://github.com/pnpm/pnpm/discussions/3857
This commit is contained in:
5
.changeset/smart-crabs-attend.md
Normal file
5
.changeset/smart-crabs-attend.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-env": minor
|
||||
---
|
||||
|
||||
Allow to install the latest Node.js version by running `pnpm env use -g latest`.
|
||||
@@ -43,6 +43,7 @@ export function help () {
|
||||
'pnpm env use --global 16',
|
||||
'pnpm env use --global lts',
|
||||
'pnpm env use --global argon',
|
||||
'pnpm env use --global latest',
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -105,6 +106,9 @@ interface NodeVersion {
|
||||
async function resolveNodeVersion (rawVersionSelector: string) {
|
||||
const response = await fetch('https://nodejs.org/download/release/index.json')
|
||||
const allVersions = (await response.json()) as NodeVersion[]
|
||||
if (rawVersionSelector === 'latest') {
|
||||
return allVersions[0].version.substring(1)
|
||||
}
|
||||
const { versions, versionSelector } = filterVersions(allVersions, rawVersionSelector)
|
||||
const pickedVersion = semver.maxSatisfying(versions.map(({ version }) => version), versionSelector)
|
||||
if (!pickedVersion) return null
|
||||
|
||||
@@ -112,6 +112,24 @@ test('install Node by its LTS name', async () => {
|
||||
expect(dirs).toEqual([version.substring(1)])
|
||||
})
|
||||
|
||||
test('install the latest Node.js', async () => {
|
||||
tempDir()
|
||||
|
||||
await env.handler({
|
||||
bin: process.cwd(),
|
||||
global: true,
|
||||
pnpmHomeDir: process.cwd(),
|
||||
rawConfig: {},
|
||||
}, ['use', 'latest'])
|
||||
|
||||
const { stdout } = execa.sync('node', ['-v'], {
|
||||
env: {
|
||||
[PATH]: `${process.cwd()}${path.delimiter}${process.env[PATH] as string}`,
|
||||
},
|
||||
})
|
||||
expect(stdout.toString()).toMatch(/^v/)
|
||||
})
|
||||
|
||||
test('fail if a non-existend Node.js version is tried to be installed', async () => {
|
||||
tempDir()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user