Skip to content

Commit

Permalink
Adds support for corepack install -g yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Dec 11, 2023
1 parent b7aa576 commit 3f29492
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 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])))
const match = raw.match(/^(?!_)(.+)(@(.+))?$/);
if (match === null || (enforceExactVersion && (!match[2] || !semver.valid(match[2]))))
throw new UsageError(`Invalid package manager specification in ${source}; 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

0 comments on commit 3f29492

Please sign in to comment.