@@ -13,6 +13,9 @@ export interface RemoteFileAddress {
1313 ref : string ;
1414}
1515
16+ /** The default ref to use in configuration file shorthands. */
17+ export const DEFAULT_CONFIG_FILE_REF = "main" ;
18+
1619/**
1720 * Attempts to parse `configFile` into an array of `RemoteFileAddress` components.
1821 *
@@ -23,12 +26,16 @@ export interface RemoteFileAddress {
2326export function parseRemoteFileAddress ( configFile : string ) : RemoteFileAddress {
2427 // retrieve the various parts of the config location, and ensure they're present
2528 const format = new RegExp (
26- "(?<owner>[^/]+)/(?<repo>[^/]+)/(?<path>[^@]+)@(?<ref>.*)" ,
29+ "(?<owner>[^/]+)/(?<repo>[^/]+)/(?<path>[^@]+)( @(?<ref>.*))? " ,
2730 ) ;
2831 const pieces = format . exec ( configFile ) ;
2932
30- // 5 = 4 groups + the whole expression
31- if ( pieces ?. groups === undefined || pieces . length < 5 ) {
33+ // Check that the regular expression matched and that we have at least the required components.
34+ if (
35+ ! pieces ?. groups ?. owner ||
36+ ! pieces ?. groups ?. repo ||
37+ ! pieces ?. groups ?. path
38+ ) {
3239 throw new ConfigurationError (
3340 errorMessages . getConfigFileRepoFormatInvalidMessage ( configFile ) ,
3441 ) ;
@@ -38,6 +45,6 @@ export function parseRemoteFileAddress(configFile: string): RemoteFileAddress {
3845 owner : pieces . groups . owner ,
3946 repo : pieces . groups . repo ,
4047 path : pieces . groups . path ,
41- ref : pieces . groups . ref ,
48+ ref : pieces . groups . ref || DEFAULT_CONFIG_FILE_REF ,
4249 } ;
4350}
0 commit comments