Skip to content

Commit 01e507f

Browse files
committed
refactor(updaters): improve regex in customUpdater
- Updated regex for version matching. - Improved regex readability and accuracy. - Removed unnecessary capturing group.
1 parent d1d2840 commit 01e507f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/updaters/customUpdater.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ 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+
4344
this.currentVersion = this.manifestParser.getVersion(this.filePath, 'regex', {
4445
regex,
4546
});
@@ -68,8 +69,9 @@ export class CustomUpdater implements UpdaterInterface {
6869
} else {
6970
// eslint-disable-next-line no-useless-escape
7071
const regexReplace: RegExp = new RegExp(
71-
`(${this.variableName}\\s*(=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`,
72+
`(${this.variableName}\\s*(?:=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`,
7273
);
74+
7375
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {
7476
regexReplace,
7577
});

0 commit comments

Comments
 (0)