From a4309191babec40ae6580b62cca796928afb5961 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 26 Jan 2024 13:30:46 +0100 Subject: [PATCH] Cope with missing `version` attribute on module --- e2e/fixtures/unversioned/MODULE.bazel | 5 +---- src/domain/create-entry.ts | 3 ++- src/domain/module-file.ts | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/e2e/fixtures/unversioned/MODULE.bazel b/e2e/fixtures/unversioned/MODULE.bazel index 38276ac..e00336e 100644 --- a/e2e/fixtures/unversioned/MODULE.bazel +++ b/e2e/fixtures/unversioned/MODULE.bazel @@ -1,4 +1 @@ -module( - name = "unversioned", - version = "0.0.0", -) \ No newline at end of file +module(name = "unversioned") diff --git a/src/domain/create-entry.ts b/src/domain/create-entry.ts index fea6ee0..9d93949 100644 --- a/src/domain/create-entry.ts +++ b/src/domain/create-entry.ts @@ -231,7 +231,8 @@ export class CreateEntryService { ): void { if (moduleFile.version !== version) { console.log( - "Archived MODULE.bazel version does not match release version. Creating a version patch." + `Archived MODULE.bazel version ${moduleFile.version} does not match release version ${version}.`, + "Creating a version patch.", ); const patchFileName = "module_dot_bazel_version.patch"; const existingContent = moduleFile.content; diff --git a/src/domain/module-file.ts b/src/domain/module-file.ts index ef66ea7..1d5cbe0 100644 --- a/src/domain/module-file.ts +++ b/src/domain/module-file.ts @@ -23,8 +23,8 @@ export class ModuleFile { public get version(): string { const regex = /module\([^)]*?version\s*=\s*"(.+?)"/s; - const version = this.moduleContent.match(regex)[1]; - return version; + const match = this.moduleContent.match(regex); + return match ? match[1] : "(unversioned)"; } public get content(): string {