File tree Expand file tree Collapse file tree 4 files changed +15
-13
lines changed Expand file tree Collapse file tree 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> {
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 ) ;
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 } ) ;
Original file line number Diff line number Diff line change 11import { UsageError } from 'clipanion' ;
22import fs from 'fs' ;
33import path from 'path' ;
4- import semver from 'semver' ;
54
65import { Descriptor , Locator , isSupportedPackageManager } from './types' ;
76
87const nodeModulesRegExp = / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ [ ^ \\ / ] * [ \\ / ] ) ? ( [ ^ @ \\ / ] [ ^ \\ / ] * ) $ / ;
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/**
You can’t perform that action at this time.
0 commit comments