Skip to content

Commit 8f95df0

Browse files
committed
fix(custom): handle json and other file types
- Handle JSON files for version updates. - Support other file types using regex. - Improve error handling for version lookup. - Add more robust version detection regex. - Update documentation for custom updaters.
1 parent b9e1c96 commit 8f95df0

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

dist/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: Taj <[email protected]>
77
* Homepage: https://github.com/taj54/universal-version-bump#readme
88
* License: MIT
9-
* Generated on Tue, 02 Sep 2025 13:11:06 GMT
9+
* Generated on Tue, 02 Sep 2025 13:17:46 GMT
1010
*/
1111
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
1212
/******/ var __webpack_modules__ = ({
@@ -33468,11 +33468,20 @@ class CustomUpdater {
3346833468
throw new Error(`Could not find current version for variable '${this.variableName}' in file '${this.filePath}'`);
3346933469
}
3347033470
const newVersion = (0, utils_1.calculateNextVersion)(oldVersion, releaseType);
33471-
// eslint-disable-next-line no-useless-escape
33472-
const regexReplace = new RegExp(`(${this.variableName}\\s*(=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`);
33473-
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {
33474-
regexReplace,
33475-
});
33471+
const lastPath = this.filePath.split('/').pop() || '';
33472+
const extension = lastPath.split('.').pop() || '';
33473+
if (extension === 'json') {
33474+
this.manifestParser.updateVersion(this.filePath, newVersion, 'json', {
33475+
jsonPath: [this.variableName],
33476+
});
33477+
}
33478+
else {
33479+
// eslint-disable-next-line no-useless-escape
33480+
const regexReplace = new RegExp(`(${this.variableName}\\s*(=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`);
33481+
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {
33482+
regexReplace,
33483+
});
33484+
}
3347633485
core.info(`Bumped ${this.variableName} in ${this.filePath} from ${oldVersion} to ${newVersion}`);
3347733486
return newVersion;
3347833487
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/updaters/customUpdater.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ export class CustomUpdater implements UpdaterInterface {
5959
}
6060

6161
const newVersion = calculateNextVersion(oldVersion, releaseType);
62-
// eslint-disable-next-line no-useless-escape
63-
const regexReplace: RegExp = new RegExp(
64-
`(${this.variableName}\\s*(=|=>|:)\\s*['"])([0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-zA-Z0-9_.-]+)?(?:\\+[a-zA-Z0-9_.-]+)?)(['"])`,
65-
);
66-
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {
67-
regexReplace,
68-
});
69-
62+
const lastPath = this.filePath.split('/').pop() || '';
63+
const extension = lastPath.split('.').pop() || '';
64+
if (extension === 'json') {
65+
this.manifestParser.updateVersion(this.filePath, newVersion, 'json', {
66+
jsonPath: [this.variableName],
67+
});
68+
} else {
69+
// eslint-disable-next-line no-useless-escape
70+
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+
);
73+
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {
74+
regexReplace,
75+
});
76+
}
7077
core.info(
7178
`Bumped ${this.variableName} in ${this.filePath} from ${oldVersion} to ${newVersion}`,
7279
);

0 commit comments

Comments
 (0)