Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions sources/specUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export function parseSpec(raw: unknown, source: string, {enforceExactVersion = t
if (typeof raw !== `string`)
throw new UsageError(`Invalid package manager specification in ${source}; expected a string`);

const match = raw.match(/^(?!_)(.+)@(.+)$/);
if (match === null || (enforceExactVersion && !semver.valid(match[2])))
throw new UsageError(`Invalid package manager specification in ${source}; expected a semver version${enforceExactVersion ? `` : `, range, or tag`}`);
const match = raw.match(/^(?!_)([^@]+)(?:@(.+))?$/);
if (match === null || (enforceExactVersion && (!match[2] || !semver.valid(match[2]))))
throw new UsageError(`Invalid package manager specification in ${source} (${raw}); expected a semver version${enforceExactVersion ? `` : `, range, or tag`}`);

if (!isSupportedPackageManager(match[1]))
throw new UsageError(`Unsupported package manager specification (${match})`);

return {
name: match[1],
range: match[2],
range: match[2] ?? `*`,
};
}

Expand Down Expand Up @@ -57,7 +57,7 @@ export async function findProjectSpec(initialCwd: string, locator: Locator, {tra
case `NoProject`:
case `NoSpec`: {
return fallbackLocator;
} break;
}

case `Found`: {
if (result.spec.name !== locator.name) {
Expand All @@ -69,7 +69,7 @@ export async function findProjectSpec(initialCwd: string, locator: Locator, {tra
} else {
return result.spec;
}
} break;
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,25 @@ it(`should allow to call "corepack install -g" with a tag`, async () => {
});
});

it(`should allow to call "corepack install -g" without any range`, async () => {
await xfs.mktempPromise(async cwd => {
await expect(runCli(cwd, [`install`, `-g`, `yarn`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
});

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

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
stdout: expect.not.stringMatching(/^[123]\./),
stderr: ``,
exitCode: 0,
});
});
});

it(`should allow to call "corepack install" 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/8LXMft4IyEWeaqoiynS5FA-1.dat
Binary file not shown.
Binary file added tests/nock/8LXMft4IyEWeaqoiynS5FA-2.dat
Binary file not shown.
Binary file modified tests/nock/AL__3okpCdfjA6kGuG2rFQ-1.dat
Binary file not shown.
Binary file modified tests/nock/bNE0FYc3WlnFGzjHaIdf5A-1.dat
Binary file not shown.