@@ -2,6 +2,7 @@ import child_process from 'node:child_process';
22import fs from 'node:fs' ;
33import path from 'node:path' ;
44import { fileURLToPath } from 'node:url' ;
5+ import semver from 'semver' ;
56
67const PROJECT_ROOT = path
78 . resolve ( path . dirname ( fileURLToPath ( import . meta. url ) ) , '..' , '..' )
@@ -18,8 +19,30 @@ const VERSIONS = JSON.parse(fs.readFileSync(`${DATADIR}/versions.json`));
1819if ( ! fs . existsSync ( `${ DATADIR } /versions` ) ) {
1920 fs . mkdirSync ( `${ DATADIR } /versions` ) ;
2021}
22+ if ( VERSIONS . length === 0 ) {
23+ throw new Error ( 'No versions found in versions.json' ) ;
24+ }
25+ VERSIONS . forEach ( ( version , index ) => {
26+ if ( index <= 0 ) {
27+ return ;
28+ }
29+ const previousVersion = VERSIONS [ index - 1 ] ;
30+ const previousVersionCoerced = semver . coerce ( previousVersion , { includePrerelease : true } ) ;
31+ if ( ! previousVersionCoerced ) {
32+ throw new Error ( `Invalid version in ${ DATADIR } /versions.json: ${ previousVersion } ` ) ;
33+ }
34+ const versionCoerced = semver . coerce ( version , { includePrerelease : true } ) ;
35+ if ( ! versionCoerced ) {
36+ throw new Error ( `Invalid version in ${ DATADIR } /versions.json: ${ version } ` ) ;
37+ }
38+ if ( semver . lte ( previousVersionCoerced . version , versionCoerced . version ) ) {
39+ throw new Error (
40+ `Versions in ${ DATADIR } /versions.json are not in descending order: ${ previousVersion } is greater than ${ version } ` ,
41+ ) ;
42+ }
43+ } ) ;
2144
22- for ( let version of VERSIONS ) {
45+ for ( let version of VERSIONS . reverse ( ) ) {
2346 const outputFileCompressed = `${ DATADIR } /versions/${ version } .min.json` ;
2447 const outputFileUncompressed = `${ DATADIR } /versions/${ version } .json` ;
2548 if (
0 commit comments