mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-25 15:07:06 -04:00
fix(env): unify Node.js related expressions (#7356)
This commit is contained in:
5
.changeset/big-bulldogs-drop.md
Normal file
5
.changeset/big-bulldogs-drop.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-env": patch
|
||||
---
|
||||
|
||||
chore: unify expressions
|
||||
2
env/plugin-commands-env/src/envRemove.ts
vendored
2
env/plugin-commands-env/src/envRemove.ts
vendored
@@ -42,7 +42,7 @@ async function removeNodeVersion (opts: NvmNodeCommandOptions, version: string):
|
||||
const { nodePath, nodeLink } = await getNodeExecPathAndTargetDir(opts.pnpmHomeDir)
|
||||
|
||||
if (nodeLink?.includes(versionDir)) {
|
||||
globalInfo(`Node.js version ${nodeVersion as string} was detected as the default one, removing ...`)
|
||||
globalInfo(`Node.js ${nodeVersion as string} was detected as the default one, removing ...`)
|
||||
|
||||
const npmPath = path.resolve(opts.pnpmHomeDir, 'npm')
|
||||
const npxPath = path.resolve(opts.pnpmHomeDir, 'npx')
|
||||
|
||||
2
env/plugin-commands-env/src/envUse.ts
vendored
2
env/plugin-commands-env/src/envUse.ts
vendored
@@ -45,7 +45,7 @@ export async function envUse (opts: NvmNodeCommandOptions, params: string[]) {
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
// ignore
|
||||
}
|
||||
return `Node.js ${nodeVersion as string} is activated
|
||||
return `Node.js ${nodeVersion as string} was activated
|
||||
${dest} -> ${src}`
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ export function parseNodeSpecifier (specifier: string): NodeSpecifier {
|
||||
|
||||
if (releaseChannel === 'release') {
|
||||
if (!isStableVersion(useNodeVersion)) {
|
||||
throw new PnpmError('INVALID_NODE_VERSION', `"${specifier}" is not a valid node version`, {
|
||||
throw new PnpmError('INVALID_NODE_VERSION', `"${specifier}" is not a valid Node.js version`, {
|
||||
hint: STABLE_RELEASE_ERROR_HINT,
|
||||
})
|
||||
}
|
||||
} else if (!useNodeVersion.includes(releaseChannel)) {
|
||||
throw new PnpmError('MISMATCHED_RELEASE_CHANNEL', `The node version (${useNodeVersion}) must contain the release channel (${releaseChannel})`)
|
||||
throw new PnpmError('MISMATCHED_RELEASE_CHANNEL', `Node.js version (${useNodeVersion}) must contain the release channel (${releaseChannel})`)
|
||||
}
|
||||
|
||||
return { releaseChannel, useNodeVersion }
|
||||
@@ -40,5 +40,5 @@ export function parseNodeSpecifier (specifier: string): NodeSpecifier {
|
||||
} else if (/^[0-9]+\.[0-9]+$/.test(specifier) || /^[0-9]+$/.test(specifier) || ['release', 'stable', 'latest'].includes(specifier)) {
|
||||
hint = STABLE_RELEASE_ERROR_HINT
|
||||
}
|
||||
throw new PnpmError('INVALID_NODE_VERSION', `"${specifier}" is not a valid node version`, { hint })
|
||||
throw new PnpmError('INVALID_NODE_VERSION', `"${specifier}" is not a valid Node.js version`, { hint })
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ test.each([
|
||||
['rc/10.0.0', '10.0.0', 'rc'],
|
||||
['rc/10.0.0.test.0', '10.0.0.test.0', 'rc'],
|
||||
])('invalid Node.js specifier', (editionSpecifier, useNodeVersion, releaseChannel) => {
|
||||
expect(() => parseNodeSpecifier(editionSpecifier)).toThrow(`The node version (${useNodeVersion}) must contain the release channel (${releaseChannel})`)
|
||||
expect(() => parseNodeSpecifier(editionSpecifier)).toThrow(`Node.js version (${useNodeVersion}) must contain the release channel (${releaseChannel})`)
|
||||
})
|
||||
|
||||
test.each([
|
||||
@@ -27,7 +27,7 @@ test.each([
|
||||
['v8-canary'],
|
||||
])('invalid Node.js specifier', async (specifier) => {
|
||||
const promise = Promise.resolve().then(() => parseNodeSpecifier(specifier))
|
||||
await expect(promise).rejects.toThrow(`"${specifier}" is not a valid node version`)
|
||||
await expect(promise).rejects.toThrow(`"${specifier}" is not a valid Node.js version`)
|
||||
await expect(promise).rejects.toHaveProperty('hint', `The correct syntax for ${specifier} release is strictly X.Y.Z-${specifier}.W`)
|
||||
})
|
||||
|
||||
@@ -40,6 +40,6 @@ test.each([
|
||||
['16.0'],
|
||||
])('invalid Node.js specifier', async (specifier) => {
|
||||
const promise = Promise.resolve().then(() => parseNodeSpecifier(specifier))
|
||||
await expect(promise).rejects.toThrow(`"${specifier}" is not a valid node version`)
|
||||
await expect(promise).rejects.toThrow(`"${specifier}" is not a valid Node.js version`)
|
||||
await expect(promise).rejects.toHaveProperty('hint', 'The correct syntax for stable release is strictly X.Y.Z or release/X.Y.Z')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user