File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -102,12 +102,32 @@ export const CLI_TARGETS: readonly CliTarget[] = [
102102 } ,
103103] as const ;
104104
105- export function parseVersion ( root : string = ROOT ) : string {
106- const cliSource = Deno . readTextFileSync ( join ( root , 'src' , 'cli' , 'cli.ts' ) ) ;
107- const match = cliSource . match ( / e x p o r t c o n s t V E R S I O N = ' ( [ ^ ' ] + ) ' / u) ;
105+ function parseVersionFromSource (
106+ sourceText : string ,
107+ ) : string | null {
108+ const match = sourceText . match ( / e x p o r t c o n s t V E R S I O N = [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / u) ;
108109 if ( ! match ) {
109- throw new Error ( 'Could not find VERSION in src/cli/cli.ts.' ) ;
110+ return null ;
110111 }
111112
112113 return match [ 1 ] ;
113114}
115+
116+ export function parseVersion ( root : string = ROOT ) : string {
117+ for ( const relativePath of [ 'src/version.ts' , 'src/cli/cli.ts' ] ) {
118+ const filePath = join ( root , relativePath ) ;
119+ try {
120+ const sourceText = Deno . readTextFileSync ( filePath ) ;
121+ const version = parseVersionFromSource ( sourceText ) ;
122+ if ( version ) {
123+ return version ;
124+ }
125+ } catch ( error ) {
126+ if ( ! ( error instanceof Deno . errors . NotFound ) ) {
127+ throw error ;
128+ }
129+ }
130+ }
131+
132+ throw new Error ( 'Could not find VERSION in src/version.ts or src/cli/cli.ts.' ) ;
133+ }
You can’t perform that action at this time.
0 commit comments