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

Adds support for corepack install -g yarn #338

Merged
merged 5 commits into from
Dec 29, 2023
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ This command doesn't change the global version used when running the package
manager from outside the project (use the \`-g,--global\` flag if you wish
to do this).

### `corepack install <-g,--global> [--all] [... name@version]`
### `corepack install <-g,--global> [--all] [... name[@<version>]]`

| Option | Description |
| --------------------- | ------------------------------------------ |
Expand All @@ -189,7 +189,7 @@ Package managers thus installed will be configured as the new default when
calling their respective binaries outside of projects defining the
`packageManager` field.

### `corepack pack [--all] [... name@version]`
### `corepack pack [--all] [... name[@<version>]]`

| Option | Description |
| --------------------- | ------------------------------------------ |
Expand All @@ -200,7 +200,7 @@ calling their respective binaries outside of projects defining the
Download the selected package managers and store them inside a tarball
suitable for use with `corepack install -g`.

### `corepack use <name@version>`
### `corepack use <name[@<version>]>`

When run, this command will retrieve the latest release matching the provided
descriptor, assign it to the project's package.json file, and automatically
Expand All @@ -215,7 +215,7 @@ it.
Unlike `corepack use` this command doesn't take a package manager name nor a
version range, as it will always select the latest available version from the
same major line. Should you need to upgrade to a new major, use an explicit
`corepack use {name}@latest` call.
`corepack use {name}@latest` call (or simply `corepack use {name}`).

## Environment Variables

Expand Down
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.
Loading