fix: handle raw statement for semver pre-release

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-12-06 15:40:44 +01:00
parent 9a42503205
commit 52100c89dd
3 changed files with 77 additions and 2 deletions

View File

@ -143,7 +143,11 @@ export class Meta {
includePrerelease: true
});
if (semver.prerelease(vraw)) {
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
if (Meta.isRawStatement(tag.attrs['pattern'])) {
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
} else {
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
}
} else {
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
latest = true;
@ -307,6 +311,18 @@ export class Meta {
return version;
}
public static isRawStatement(pattern: string): boolean {
try {
const hp = handlebars.parseWithoutProcessing(pattern);
if (hp.body.length == 1 && hp.body[0].type == 'MustacheStatement') {
return hp.body[0]['path']['parts'].length == 1 && hp.body[0]['path']['parts'][0] == 'raw';
}
} catch (err) {
return false;
}
return false;
}
private setValue(val: string, tag: tcl.Tag): string {
if (tag.attrs.hasOwnProperty('prefix')) {
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;