Skip to content

Commit 5fad692

Browse files
committed
refactor(customUpdater): Improve regex for version update
- Simplified regex for better clarity. - Fixed potential issues with capturing groups. - Improved regex to handle various version formats. - Enhanced robustness of version matching. - Updated regex to correctly handle variable assignment.
1 parent 55ba55b commit 5fad692

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

src/updaters/customUpdater.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ export class CustomUpdater implements UpdaterInterface {
3838
// console.log(extension, this.filePath);
3939

4040
const regex: RegExp = new RegExp(
41-
`(${this.variableName}\\s*(?:=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`,
41+
`\\$${this.variableName}\\s*(?:=|=>|:)\\s*['"]([0-9]+\\.[0-9]+\\.[0-9]+(?:-[A-Za-z0-9_.-]+)?(?:\\+[A-Za-z0-9_.-]+)?)['"]`,
4242
);
43-
4443
this.currentVersion = this.manifestParser.getVersion(this.filePath, 'regex', {
4544
regex,
4645
});
@@ -69,7 +68,7 @@ export class CustomUpdater implements UpdaterInterface {
6968
} else {
7069
// eslint-disable-next-line no-useless-escape
7170
const regexReplace: RegExp = new RegExp(
72-
`(${this.variableName}\\s*(?:=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`,
71+
`(.*?\\$${this.variableName}\\s*(?:=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[A-Za-z0-9_.-]+)?(?:\\+[A-Za-z0-9_.-]+)?)(['"];?)`,
7372
);
7473

7574
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {

0 commit comments

Comments
 (0)