Skip to content

Commit 5a0727b

Browse files
teppeisaduh95
andauthored
fix: handle tags including numbers in prepare command (#165)
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c0df287 commit 5a0727b

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

sources/Engine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class Engine {
136136
throw new UsageError(`This package manager (${descriptor.name}) isn't supported by this corepack build`);
137137

138138
let finalDescriptor = descriptor;
139-
if (/^[a-z-]+$/.test(descriptor.range)) {
139+
if (!semver.valid(descriptor.range) && !semver.validRange(descriptor.range)) {
140140
if (!allowTags)
141141
throw new UsageError(`Packages managers can't be referended via tags in this context`);
142142

tests/_runCli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {PortablePath, npath} from '@yarnpkg/fslib';
22
import {spawn} from 'child_process';
33

4-
export async function runCli(cwd: PortablePath, argv: Array<string>) {
4+
export async function runCli(cwd: PortablePath, argv: Array<string>): Promise<{exitCode: number | null, stdout: string, stderr: string}> {
55
const out: Array<Buffer> = [];
66
const err: Array<Buffer> = [];
77

tests/main.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ it(`should allow updating the pinned version using the "prepare" command`, async
208208
});
209209
});
210210

211+
it(`should allow to call "prepare" with a tag`, async () => {
212+
await xfs.mktempPromise(async cwd => {
213+
await expect(runCli(cwd, [`prepare`, `--activate`, `npm@latest-7`])).resolves.toMatchObject({
214+
exitCode: 0,
215+
stderr: ``,
216+
});
217+
218+
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
219+
// empty package.json file
220+
});
221+
222+
const npmVersion = await runCli(cwd, [`npm`, `--version`]);
223+
expect(npmVersion).toMatchObject({
224+
stderr: ``,
225+
exitCode: 0,
226+
});
227+
expect(npmVersion.stdout).toMatch(/^7\./);
228+
});
229+
});
230+
211231
it(`should allow to call "prepare" without arguments within a configured project`, async () => {
212232
await xfs.mktempPromise(async cwd => {
213233
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
7.74 MB
Binary file not shown.
7 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)