File tree 4 files changed +15
-13
lines changed
4 files changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export abstract class BaseCommand extends Command<Context> {
14
14
15
15
const resolvedSpecs = all
16
16
? 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` ) ) ;
18
18
19
19
if ( resolvedSpecs . length === 0 ) {
20
20
const lookup = await specUtils . loadSpec ( this . context . cwd ) ;
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ export class InstallGlobalCommand extends BaseCommand {
52
52
if ( arg . endsWith ( `.tgz` ) ) {
53
53
await this . installFromTarball ( path . resolve ( this . context . cwd , arg ) ) ;
54
54
} else {
55
- await this . installFromDescriptor ( specUtils . parseSpec ( arg , `CLI arguments` , { enforceExactVersion : false } ) ) ;
55
+ await this . installFromDescriptor ( specUtils . parseSpec ( arg , `CLI arguments` ) ) ;
56
56
}
57
57
}
58
58
} else {
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export class PrepareCommand extends Command<Context> {
58
58
59
59
for ( const request of specs ) {
60
60
const spec = typeof request === `string`
61
- ? specUtils . parseSpec ( request , `CLI arguments` , { enforceExactVersion : false } )
61
+ ? specUtils . parseSpec ( request , `CLI arguments` )
62
62
: request ;
63
63
64
64
const resolved = await this . context . engine . resolveDescriptor ( spec , { allowTags : true } ) ;
Original file line number Diff line number Diff line change 1
1
import { UsageError } from 'clipanion' ;
2
2
import fs from 'fs' ;
3
3
import path from 'path' ;
4
- import semver from 'semver' ;
5
4
6
5
import { Descriptor , Locator , isSupportedPackageManager } from './types' ;
7
6
8
7
const nodeModulesRegExp = / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ [ ^ \\ / ] * [ \\ / ] ) ? ( [ ^ @ \\ / ] [ ^ \\ / ] * ) $ / ;
9
8
10
- export function parseSpec ( raw : unknown , source : string , { enforceExactVersion = true } = { } ) : Descriptor {
9
+ export function parseSpec ( raw : unknown , source : string ) : Descriptor {
11
10
if ( typeof raw !== `string` )
12
11
throw new UsageError ( `Invalid package manager specification in ${ source } ; expected a string` ) ;
13
12
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 ] ?? `*` ;
17
16
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 ) )
19
24
throw new UsageError ( `Unsupported package manager specification (${ match } )` ) ;
20
25
21
- return {
22
- name : match [ 1 ] ,
23
- range : match [ 2 ] ,
24
- } ;
26
+ return { name, range} ;
25
27
}
26
28
27
29
/**
You can’t perform that action at this time.
0 commit comments