Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle tags including numbers in prepare command #165

Merged
merged 6 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Engine {
throw new UsageError(`This package manager (${descriptor.name}) isn't supported by this corepack build`);

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

Expand Down
2 changes: 1 addition & 1 deletion tests/_runCli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PortablePath, npath} from '@yarnpkg/fslib';
import {spawn} from 'child_process';

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

Expand Down
20 changes: 20 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ it(`should allow updating the pinned version using the "prepare" command`, async
});
});

it(`should allow to call "prepare" with a tag`, async () => {
await xfs.mktempPromise(async cwd => {
await expect(runCli(cwd, [`prepare`, `--activate`, `npm@latest-7`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
});

await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
// empty package.json file
});

const npmVersion = await runCli(cwd, [`npm`, `--version`]);
expect(npmVersion).toMatchObject({
stderr: ``,
exitCode: 0,
});
expect(npmVersion.stdout).toMatch(/^7\./);
});
});

it(`should allow to call "prepare" without arguments within a configured project`, async () => {
await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
Expand Down
Binary file added tests/nock/ToUs5E5EzXCAwMv31KqJGA-1.dat
Binary file not shown.
Binary file added tests/nock/ToUs5E5EzXCAwMv31KqJGA-2.dat
Binary file not shown.