@@ -26,6 +26,7 @@ const dashedVersionRegExp = /[0-9]+-[0-9]+-[0-9]+/g;
2626export async function updatePackageDependencies ( ) : Promise < void > {
2727 const newPrimaryUrls = process . env [ 'NEW_DEPS_URLS' ] ;
2828 const newVersion = process . env [ 'NEW_DEPS_VERSION' ] ;
29+ const oldVersion = process . env [ 'OLD_DEPS_VERSION' ] ?? '' ; // Optional: Will fallback to trying to replace version with a regex.
2930 const packageId = process . env [ 'NEW_DEPS_ID' ] ;
3031
3132 if ( ( ! packageId && ! newPrimaryUrls ) || ! newVersion ) {
@@ -51,6 +52,10 @@ export async function updatePackageDependencies(): Promise<void> {
5152 throw new Error ( "Unexpected 'NEW_DEPS_VERSION' value. Expected format similar to: 1.2.3." ) ;
5253 }
5354
55+ if ( oldVersion . length > 0 && ! / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + [ - a - z A - Z 0 - 9 . ] * $ / . test ( oldVersion ) ) {
56+ throw new Error ( "Unexpected 'OLD_DEPS_VERSION' value. Expected format similar to: 1.2.2." ) ;
57+ }
58+
5459 const packageJSON : PackageJSONFile = JSON . parse ( fs . readFileSync ( 'package.json' ) . toString ( ) ) ;
5560
5661 const eventStream = new EventStream ( ) ;
@@ -72,9 +77,9 @@ export async function updatePackageDependencies(): Promise<void> {
7277
7378 const updateDependency = async ( dependency : Package ) : Promise < void > => {
7479 dependency . integrity = await downloadAndGetHash ( dependency . url ) ;
75- dependency . fallbackUrl = replaceVersion ( dependency . fallbackUrl , newVersion ) ;
76- dependency . installPath = replaceVersion ( dependency . installPath , newVersion ) ;
77- dependency . installTestPath = replaceVersion ( dependency . installTestPath , newVersion ) ;
80+ dependency . fallbackUrl = replaceVersion ( dependency . fallbackUrl , oldVersion , newVersion ) ;
81+ dependency . installPath = replaceVersion ( dependency . installPath , oldVersion , newVersion ) ;
82+ dependency . installTestPath = replaceVersion ( dependency . installTestPath , oldVersion , newVersion ) ;
7883 Object . keys ( packageJSON . defaults ) . forEach ( ( key ) => {
7984 //Update the version present in the defaults
8085 if ( key . toLowerCase ( ) == dependency . id . toLowerCase ( ) ) {
@@ -169,7 +174,7 @@ export async function updatePackageDependencies(): Promise<void> {
169174 continue ;
170175 }
171176
172- dependency . url = replaceVersion ( dependency . url , newVersion ) ;
177+ dependency . url = replaceVersion ( dependency . url , oldVersion , newVersion ) ;
173178 await updateDependency ( dependency ) ;
174179 }
175180 }
@@ -186,14 +191,18 @@ export async function updatePackageDependencies(): Promise<void> {
186191 fs . writeFileSync ( 'package.json' , content ) ;
187192}
188193
189- function replaceVersion ( fileName : string , newVersion : string ) : string ;
190- function replaceVersion ( fileName : undefined , newVersion : string ) : undefined ;
191- function replaceVersion ( fileName : string | undefined , newVersion : string ) : string | undefined ;
192- function replaceVersion ( fileName : string | undefined , newVersion : string ) : string | undefined {
194+ function replaceVersion ( fileName : string , oldVersion : string , newVersion : string ) : string ;
195+ function replaceVersion ( fileName : undefined , oldVersion : string , newVersion : string ) : undefined ;
196+ function replaceVersion ( fileName : string | undefined , oldVersion : string , newVersion : string ) : string | undefined ;
197+ function replaceVersion ( fileName : string | undefined , oldVersion : string , newVersion : string ) : string | undefined {
193198 if ( fileName === undefined ) {
194199 return undefined ; // If the file name is undefined, no version to replace
195200 }
196201
202+ if ( oldVersion . length > 0 ) {
203+ return fileName . replaceAll ( oldVersion , newVersion ) ;
204+ }
205+
197206 let regex : RegExp = dottedVersionRegExp ;
198207 let newValue : string = newVersion ;
199208 if ( ! dottedVersionRegExp . test ( fileName ) ) {
0 commit comments