Skip to content

Commit

Permalink
fix(env): unify Node.js related expressions (#7356)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunbinseo authored Dec 3, 2023
1 parent c883f81 commit b9c7fb9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-bulldogs-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-env": patch
---

chore: unify expressions
2 changes: 1 addition & 1 deletion env/plugin-commands-env/src/envRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion env/plugin-commands-env/src/envUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}

Expand Down
6 changes: 3 additions & 3 deletions env/plugin-commands-env/src/parseNodeSpecifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 })
}
6 changes: 3 additions & 3 deletions env/plugin-commands-env/test/parseNodeSpecifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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`)
})

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

0 comments on commit b9c7fb9

Please sign in to comment.