diff --git a/release.config.js b/release.config.js index ec267cf..3b179b4 100644 --- a/release.config.js +++ b/release.config.js @@ -1,4 +1,4 @@ -const { existsSync } = require("node:fs"); +const { existsSync, readFileSync } = require("node:fs"); const { execSync } = require('node:child_process'); const log = require("npmlog"); @@ -131,44 +131,41 @@ if (pkgExists && SR_DISABLE_NPM === undefined) { }); } +const hasVersionLine = (file, pattern) => + (readFileSync(file, "utf8").match(new RegExp(pattern, "gm")) || []).length === 1; + const denoExists = existsSync("./deno.json"); if (denoExists && SR_DISABLE_DENO === undefined) { - addPlugin("semantic-release-replace-plugin", { - "replacements": [{ - "files": [ - "deno.json" - ], - "from": `"version":.*".*"`, - "to": `"version": "\${nextRelease.version}"`, - "results": [{ - "file": "deno.json", - "hasChanged": true, - "numMatches": 1, - "numReplacements": 1 - }], - "countMatches": true - }] - }); + if (!hasVersionLine("deno.json", `"version":.*".*"`)) { + log.warn(`deno.json has no single "version" line, so its version is not updated`); + } else { + addPlugin("semantic-release-replace-plugin", { + "replacements": [{ + "files": [ + "deno.json" + ], + "from": `"version":.*".*"`, + "to": `"version": "\${nextRelease.version}"` + }] + }); + } } const pythonExists = existsSync("./pyproject.toml"); if (pythonExists && SR_DISABLE_PYTHON === undefined) { - addPlugin("semantic-release-replace-plugin", { - "replacements": [{ - "files": [ - "pyproject.toml" - ], - "from": `^version.*=.*".*"$`, - "to": `version = "\${nextRelease.version}"`, - "results": [{ - "file": "pyproject.toml", - "hasChanged": true, - "numMatches": 1, - "numReplacements": 1 - }], - "countMatches": true - }] - }); + if (!hasVersionLine("pyproject.toml", `^version.*=.*".*"$`)) { + log.warn(`pyproject.toml has no single version line, so its version is not updated`); + } else { + addPlugin("semantic-release-replace-plugin", { + "replacements": [{ + "files": [ + "pyproject.toml" + ], + "from": `^version.*=.*".*"$`, + "to": `version = "\${nextRelease.version}"` + }] + }); + } const uvLockExists = existsSync("./uv.lock"); if (uvLockExists) {