Skip to content

Commit 29da06c

Browse files
authored
feat: add support for tags and ranges in prepare command (#136)
Fixes: #72
1 parent 9a153d2 commit 29da06c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

sources/commands/Prepare.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class PrepareCommand extends Command<Context> {
2424
], [
2525
`Prepare a specific Yarn version`,
2626
`$0 prepare yarn@2.2.2`,
27+
], [
28+
`Prepare the latest available pnpm version`,
29+
`$0 prepare pnpm@latest --activate`,
2730
], [
2831
`Generate an archive for a specific Yarn version`,
2932
`$0 prepare yarn@2.2.2 -o`,
@@ -50,7 +53,7 @@ export class PrepareCommand extends Command<Context> {
5053
tolerateBoolean: true,
5154
});
5255

53-
specs = Option.Rest()
56+
specs = Option.Rest();
5457

5558
async execute() {
5659
if (this.all && this.specs.length > 0)
@@ -79,10 +82,10 @@ export class PrepareCommand extends Command<Context> {
7982

8083
for (const request of specs) {
8184
const spec = typeof request === `string`
82-
? specUtils.parseSpec(request, `CLI arguments`)
85+
? specUtils.parseSpec(request, `CLI arguments`, {enforceExactVersion: false})
8386
: request;
8487

85-
const resolved = await this.context.engine.resolveDescriptor(spec);
88+
const resolved = await this.context.engine.resolveDescriptor(spec, {allowTags: true});
8689
if (resolved === null)
8790
throw new UsageError(`Failed to successfully resolve '${spec.range}' to a valid ${spec.name} release`);
8891

sources/specUtils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import {Descriptor, Locator, isSupportedPackageManager} from './types';
77

88
const nodeModulesRegExp = /[\\/]node_modules[\\/](@[^\\/]*[\\/])?([^@\\/][^\\/]*)$/;
99

10-
export function parseSpec(raw: unknown, source?: string): Descriptor {
10+
export function parseSpec(raw: unknown, source: string, {enforceExactVersion = true} = {}): Descriptor {
1111
if (typeof raw !== `string`)
1212
throw new UsageError(`Invalid package manager specification in ${source}; expected a string`);
1313

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

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

0 commit comments

Comments
 (0)