Skip to content

Commit 4edc5e0

Browse files
committed
Don't require version range
1 parent 2bf76c9 commit 4edc5e0

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

Diff for: sources/commands/Base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export abstract class BaseCommand extends Command<Context> {
1414

1515
const resolvedSpecs = all
1616
? await this.context.engine.getDefaultDescriptors()
17-
: patterns.map(pattern => specUtils.parseSpec(pattern, `CLI arguments`, {enforceExactVersion: false}));
17+
: patterns.map(pattern => specUtils.parseSpec(pattern, `CLI arguments`));
1818

1919
if (resolvedSpecs.length === 0) {
2020
const lookup = await specUtils.loadSpec(this.context.cwd);

Diff for: sources/commands/InstallGlobal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class InstallGlobalCommand extends BaseCommand {
5252
if (arg.endsWith(`.tgz`)) {
5353
await this.installFromTarball(path.resolve(this.context.cwd, arg));
5454
} else {
55-
await this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
55+
await this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`));
5656
}
5757
}
5858
} else {

Diff for: sources/commands/deprecated/Prepare.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class PrepareCommand extends Command<Context> {
5858

5959
for (const request of specs) {
6060
const spec = typeof request === `string`
61-
? specUtils.parseSpec(request, `CLI arguments`, {enforceExactVersion: false})
61+
? specUtils.parseSpec(request, `CLI arguments`)
6262
: request;
6363

6464
const resolved = await this.context.engine.resolveDescriptor(spec, {allowTags: true});

Diff for: sources/specUtils.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import {UsageError} from 'clipanion';
22
import fs from 'fs';
33
import path from 'path';
4-
import semver from 'semver';
54

65
import {Descriptor, Locator, isSupportedPackageManager} from './types';
76

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

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

14-
const match = raw.match(/^(?!_)(.+)@(.+)$/);
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`}`);
13+
const match = /^(@?[^@]+)(?:@(.+))?$/.exec(raw);
14+
const name = match?.[1];
15+
const range = match?.[2] ?? `*`;
1716

18-
if (!isSupportedPackageManager(match[1]))
17+
if (!name) {
18+
throw new UsageError(
19+
`Invalid package manager specification in ${source}. Could not determine package manager name`,
20+
);
21+
}
22+
23+
if (!isSupportedPackageManager(name))
1924
throw new UsageError(`Unsupported package manager specification (${match})`);
2025

21-
return {
22-
name: match[1],
23-
range: match[2],
24-
};
26+
return {name, range};
2527
}
2628

2729
/**

0 commit comments

Comments
 (0)