From 4b6c2ba05a2bc3ba75645988df75993e95986808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Bo=CC=88ge?= Date: Fri, 27 Nov 2026 12:55:52 +0100 Subject: [PATCH 1/2] fix(puppetfile): keep :tag when rendering git modules Since :tag is parsed as an alias for :ref, toText() rendered every git module with :ref, so a Puppetfile that pinned a module by tag came back with :ref after a round-trip. Remember the tag on the module declaration and render :tag when it is set. ref stays populated so the checkout in fetchGitMetadata() is unchanged. --- lib/ModuleDeclaration.ts | 7 ++++++- lib/PuppetFile.ts | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ModuleDeclaration.ts b/lib/ModuleDeclaration.ts index 0b13d4a..9957c9e 100644 --- a/lib/ModuleDeclaration.ts +++ b/lib/ModuleDeclaration.ts @@ -43,6 +43,11 @@ export class ModuleDeclaration { */ public ref?: string + /** + * A git tag (also stored in ref for checkout, kept to render :tag in toText) + */ + public tag?: string + /** * Comments from the Puppetfile */ @@ -104,7 +109,7 @@ export class ModuleDeclaration { if (':ref' in parameters) { this.ref = parameters[':ref'] } else if (':tag' in parameters) { - this.ref = parameters[':tag'] + this.ref = this.tag = parameters[':tag'] } this.forgeModule = false await this.fetchGitMetadata() diff --git a/lib/PuppetFile.ts b/lib/PuppetFile.ts index 2ff0797..93d8b6d 100644 --- a/lib/PuppetFile.ts +++ b/lib/PuppetFile.ts @@ -187,7 +187,8 @@ export class PuppetFile { # {{{this}}} {{/each}} mod '{{author}}-{{name}}', - :git => '{{git}}'{{#if ref}}, + :git => '{{git}}'{{#if tag}}, + :tag => '{{tag}}'{{else if ref}}, :ref => '{{ref}}'{{/if}} {{#unless @last}} @@ -227,6 +228,7 @@ mod '{{author}}-{{name}}', '{{version}}'{{#unless @last}} git: value.git, comments: value.comments, ref: '', + tag: value.tag ?? '', } if (value.ref) { retValue['ref'] = value.ref From 63e033e47b70d1ba8cf7c8b2518dd960ccbf66e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Bo=CC=88ge?= Date: Fri, 27 Nov 2026 12:55:52 +0100 Subject: [PATCH 2/2] test: cover :tag round-trip in PuppetFile.toText --- test/puppetfile.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/puppetfile.test.ts b/test/puppetfile.test.ts index 71d236d..5814616 100644 --- a/test/puppetfile.test.ts +++ b/test/puppetfile.test.ts @@ -180,6 +180,28 @@ mod 'test-default2', '1.2.3' ## dependencies +mod 'test-dependency', '1.2.4'` + + const subject = await new PuppetFile().fromText(puppetfile) + + expect(subject.toText()).toEqual(puppetfile) + }) + + it('should keep :tag when generating the puppet file text', async () => { + const puppetfile = `forge 'http://localhost:${sb.getPort()}' + +# Git modules + +mod 'test-git', + :git => '${tmpDir.path}', + :tag => 'test' + +# Forge modules + +mod 'test-default', '1.2.3' + +## dependencies + mod 'test-dependency', '1.2.4'` const subject = await new PuppetFile().fromText(puppetfile)