@@ -26,6 +26,7 @@ const dashedVersionRegExp = /[0-9]+-[0-9]+-[0-9]+/g;
26
26
export async function updatePackageDependencies ( ) : Promise < void > {
27
27
const newPrimaryUrls = process . env [ 'NEW_DEPS_URLS' ] ;
28
28
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.
29
30
const packageId = process . env [ 'NEW_DEPS_ID' ] ;
30
31
31
32
if ( ( ! packageId && ! newPrimaryUrls ) || ! newVersion ) {
@@ -51,6 +52,10 @@ export async function updatePackageDependencies(): Promise<void> {
51
52
throw new Error ( "Unexpected 'NEW_DEPS_VERSION' value. Expected format similar to: 1.2.3." ) ;
52
53
}
53
54
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
+
54
59
const packageJSON : PackageJSONFile = JSON . parse ( fs . readFileSync ( 'package.json' ) . toString ( ) ) ;
55
60
56
61
const eventStream = new EventStream ( ) ;
@@ -72,9 +77,9 @@ export async function updatePackageDependencies(): Promise<void> {
72
77
73
78
const updateDependency = async ( dependency : Package ) : Promise < void > => {
74
79
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 ) ;
78
83
Object . keys ( packageJSON . defaults ) . forEach ( ( key ) => {
79
84
//Update the version present in the defaults
80
85
if ( key . toLowerCase ( ) == dependency . id . toLowerCase ( ) ) {
@@ -169,7 +174,7 @@ export async function updatePackageDependencies(): Promise<void> {
169
174
continue ;
170
175
}
171
176
172
- dependency . url = replaceVersion ( dependency . url , newVersion ) ;
177
+ dependency . url = replaceVersion ( dependency . url , oldVersion , newVersion ) ;
173
178
await updateDependency ( dependency ) ;
174
179
}
175
180
}
@@ -186,14 +191,18 @@ export async function updatePackageDependencies(): Promise<void> {
186
191
fs . writeFileSync ( 'package.json' , content ) ;
187
192
}
188
193
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 {
193
198
if ( fileName === undefined ) {
194
199
return undefined ; // If the file name is undefined, no version to replace
195
200
}
196
201
202
+ if ( oldVersion . length > 0 ) {
203
+ return fileName . replaceAll ( oldVersion , newVersion ) ;
204
+ }
205
+
197
206
let regex : RegExp = dottedVersionRegExp ;
198
207
let newValue : string = newVersion ;
199
208
if ( ! dottedVersionRegExp . test ( fileName ) ) {
0 commit comments