diff --git a/lib/ModuleDeclaration.ts b/lib/ModuleDeclaration.ts index d3e7f11..0b13d4a 100644 --- a/lib/ModuleDeclaration.ts +++ b/lib/ModuleDeclaration.ts @@ -103,6 +103,8 @@ export class ModuleDeclaration { this.git = parameters[':git'] if (':ref' in parameters) { this.ref = parameters[':ref'] + } else if (':tag' in parameters) { + this.ref = parameters[':tag'] } this.forgeModule = false await this.fetchGitMetadata() diff --git a/test/module.declaration.test.ts b/test/module.declaration.test.ts new file mode 100644 index 0000000..042c892 --- /dev/null +++ b/test/module.declaration.test.ts @@ -0,0 +1,38 @@ +import tmp from 'tmp-promise' +import simpleGit from 'simple-git' +import { writeFile } from 'fs/promises' +import path from 'path' +import { ModuleDeclaration } from '../lib/ModuleDeclaration' +import { expect } from '@jest/globals' + +jest.setTimeout(30000) + +describe('ModuleDeclaration.fromText', () => { + let tmpDir: tmp.DirectoryResult + + beforeEach(async () => { + tmpDir = await tmp.dir({ unsafeCleanup: true }) + const git = simpleGit(tmpDir.path, { + config: ['user.email=test@test.com', 'user.name=Tester', 'init.defaultBranch=main'], + }) + await git.init() + await writeFile( + path.join(tmpDir.path, 'metadata.json'), + '{"name":"test-tagged","version":"0.1.0","dependencies":[]}' + ) + await git.add(path.join(tmpDir.path, 'metadata.json')) + await git.commit('tagged release') + await git.addTag('v1.0.0') + }) + + afterEach(async () => { + await tmpDir.cleanup() + }) + + it('accepts :tag as an alias for :ref on a git-sourced module', async () => { + const declaration = await new ModuleDeclaration().fromText( + `mod 'test-tagged', :git => '${tmpDir.path}', :tag => 'v1.0.0'` + ) + expect(declaration.ref).toEqual('v1.0.0') + }) +})