fix(env): unify Node.js related expressions (#7356)

This commit is contained in:
Hyunbin
2023-12-04 02:34:39 +09:00
committed by GitHub
parent c883f8120c
commit b9c7fb91f3
5 changed files with 13 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-env": patch
---
chore: unify expressions

View File

@@ -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')

View File

@@ -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}`
}

View File

@@ -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 })
}

View File

@@ -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')
})