@@ -4,7 +4,22 @@ import { writeFileSync, readFileSync } from 'node:fs';
44import { dirname , join } from 'node:path' ;
55import sortPackageJson from 'sort-package-json' ;
66
7- async function updateAllDeps ( ) {
7+ type PackageJson = {
8+ name : string ;
9+ version : string ;
10+ dependencies ?: Record < string , string > ;
11+ devDependencies ?: Record < string , string > ;
12+ [ key : string ] : unknown ;
13+ } ;
14+
15+ type VersionEntry = {
16+ name : string ;
17+ version : string ;
18+ } ;
19+
20+ type VersionsJson = Record < string , Record < string , Record < string , VersionEntry [ ] > > > ;
21+
22+ async function updateAllDeps ( ) : Promise < void > {
823 const paths = [
924 './e2e/babel-e2e/package.json' ,
1025 './e2e/starter-e2e/package.json' ,
@@ -46,24 +61,21 @@ async function updateAllDeps() {
4661 './packages/utils/package.json' ,
4762 ] ;
4863
49- const fields = [ 'dependencies' , 'devDependencies' ] ;
64+ const fields : ReadonlyArray < 'dependencies' | 'devDependencies' > = [ 'dependencies' , 'devDependencies' ] ;
5065
51- const pkgs = paths . map ( ( p ) => {
52- const data = readFileSync ( p , 'utf8' ) ;
53- return {
54- data : JSON . parse ( data ) ,
55- path : p ,
56- } ;
57- } ) ;
66+ const pkgs = paths . map ( ( p ) => ( {
67+ data : JSON . parse ( readFileSync ( p , 'utf8' ) ) as PackageJson ,
68+ path : p ,
69+ } ) ) ;
5870
5971 for ( let i = 0 ; i < pkgs . length ; i ++ ) {
6072 const pkg = pkgs [ i ] . data ;
6173 const p = pkgs [ i ] . path ;
6274 for ( let y = 0 ; y < fields . length ; y ++ ) {
6375 const field = fields [ y ] ;
64- const deps = pkg [ field ] || { } ;
76+ const deps = pkg [ field ] ?? { } ;
6577 const names = Object . keys ( deps ) ;
66- const forUpdate = { } ;
78+ const forUpdate : Record < string , string > = { } ;
6779 for ( let j = 0 ; j < names . length ; j ++ ) {
6880 const dep = names [ j ] ;
6981 if ( dep . indexOf ( '@rockpack/' ) !== - 1 ) {
@@ -88,9 +100,7 @@ async function updateAllDeps() {
88100 console . warn ( `[${ pkg . name } ] package.json will be updated` ) ;
89101 const sorted = sortPackageJson ( {
90102 ...pkg ,
91- ...{
92- [ field ] : { ...deps , ...forUpdate } ,
93- } ,
103+ [ field ] : { ...deps , ...forUpdate } ,
94104 } ) ;
95105
96106 if ( p . indexOf ( 'starter-e2e' ) > 0 ) {
@@ -110,7 +120,9 @@ async function updateAllDeps() {
110120
111121 if ( indexA >= 0 && indexB >= 0 ) {
112122 [ orderedKeys [ indexA ] , orderedKeys [ indexB ] ] = [ orderedKeys [ indexB ] , orderedKeys [ indexA ] ] ;
113- sorted . devDependencies = Object . fromEntries ( orderedKeys . map ( ( key ) => [ key , sorted . devDependencies [ key ] ] ) ) ;
123+ sorted . devDependencies = Object . fromEntries (
124+ orderedKeys . map ( ( key ) => [ key , ( sorted . devDependencies as Record < string , string > ) [ key ] ] ) ,
125+ ) ;
114126 }
115127 }
116128 }
@@ -122,29 +134,30 @@ async function updateAllDeps() {
122134 }
123135}
124136
125- async function updateStarterDeps ( ) {
137+ async function updateStarterDeps ( ) : Promise < void > {
126138 const pth = './packages/starter/src/versions.json' ;
127139
128- const data = JSON . parse ( readFileSync ( pth , 'utf8' ) ) ;
140+ const data = JSON . parse ( readFileSync ( pth , 'utf8' ) ) as VersionsJson ;
129141 let wasUpdated = false ;
130142
131143 console . log ( '---' ) ;
132144 console . log ( 'Dependencies checking in @rockpack/starter' ) ;
133145 console . log ( '---' ) ;
134146
135- for ( let type in data ) {
136- for ( let variations in data [ type ] ) {
137- for ( let depType in data [ type ] [ variations ] ) {
147+ for ( const type in data ) {
148+ for ( const variations in data [ type ] ) {
149+ for ( const depType in data [ type ] [ variations ] ) {
138150 const dependencies = data [ type ] [ variations ] [ depType ] ;
139151
140- for ( let dependency of dependencies ) {
152+ for ( const dependency of dependencies ) {
141153 const { name, version } = dependency ;
142154 const newVersion = await latestVersion ( name ) ;
143- const { major } = parse ( newVersion ) ;
155+ const parsed = parse ( newVersion ) ;
156+ const major = parsed ?. major ?? 0 ;
144157
145- if ( major > version ) {
158+ if ( major > Number ( version ) ) {
146159 console . log ( `[${ name } ] will be updated from ${ version } to ${ major } ` ) ;
147- const index = dependencies . findIndex ( ( { name } ) => name === dependency . name ) ;
160+ const index = dependencies . findIndex ( ( { name : n } ) => n === dependency . name ) ;
148161 dependencies [ index ] = { name, version : `${ major } ` } ;
149162 wasUpdated = true ;
150163 }
@@ -158,7 +171,7 @@ async function updateStarterDeps() {
158171 }
159172}
160173
161- async function bootstrap ( ) {
174+ async function bootstrap ( ) : Promise < void > {
162175 await updateAllDeps ( ) ;
163176 await updateStarterDeps ( ) ;
164177}
0 commit comments