@@ -4,6 +4,7 @@ import { spawnSync } from "node:child_process";
|
4 | 4 | import fs from "node:fs"; |
5 | 5 | import path from "node:path"; |
6 | 6 | import { pathToFileURL } from "node:url"; |
| 7 | +import { parseReleaseVersion } from "../../../lib/npm-publish-plan.mjs"; |
7 | 8 | import { buildCmdExeCommandLine } from "../../../windows-cmd-helpers.mjs"; |
8 | 9 | |
9 | 10 | const args = process.argv.slice(2); |
@@ -40,28 +41,39 @@ function readConfigSection(fileName) {
|
40 | 41 | return JSON.stringify(JSON.parse(fs.readFileSync(fileUrl, "utf8"))); |
41 | 42 | } |
42 | 43 | |
43 | | -function parseReleaseVersion(version) { |
44 | | -const match = /^([0-9]{4})\.([0-9]+)\.([0-9]+)/u.exec(String(version ?? "")); |
45 | | -if (!match) { |
46 | | -return null; |
47 | | -} |
48 | | -return match.slice(1).map((part) => Number.parseInt(part, 10)); |
49 | | -} |
50 | | - |
51 | | -function isReleaseBefore(version, minimum) { |
52 | | -const parsed = parseReleaseVersion(version); |
53 | | -const minimumParsed = parseReleaseVersion(minimum); |
| 44 | +export function isReleaseBefore(version, minimum) { |
| 45 | +const parsed = parseReleaseVersion(String(version ?? "")); |
| 46 | +const minimumParsed = parseReleaseFloor(minimum); |
54 | 47 | if (!parsed || !minimumParsed) { |
55 | 48 | return false; |
56 | 49 | } |
57 | | -for (let index = 0; index < parsed.length; index += 1) { |
58 | | -if (parsed[index] !== minimumParsed[index]) { |
59 | | -return parsed[index] < minimumParsed[index]; |
| 50 | +for (const key of ["year", "month", "patch"]) { |
| 51 | +const delta = parsed[key] - minimumParsed[key]; |
| 52 | +if (delta !== 0) { |
| 53 | +return delta < 0; |
60 | 54 | } |
61 | 55 | } |
62 | 56 | return false; |
63 | 57 | } |
64 | 58 | |
| 59 | +function parseReleaseFloor(version) { |
| 60 | +const match = /^([0-9]{4})\.([1-9][0-9]?)\.([0-9]+)$/u.exec(String(version ?? "")); |
| 61 | +if (!match) { |
| 62 | +return null; |
| 63 | +} |
| 64 | +const [year, month, patch] = match.slice(1).map((part) => Number(part)); |
| 65 | +if ( |
| 66 | +!Number.isSafeInteger(year) || |
| 67 | +!Number.isSafeInteger(month) || |
| 68 | +!Number.isSafeInteger(patch) || |
| 69 | +month < 1 || |
| 70 | +month > 12 |
| 71 | +) { |
| 72 | +return null; |
| 73 | +} |
| 74 | +return { year, month, patch }; |
| 75 | +} |
| 76 | + |
65 | 77 | function configSetJsonFile(id, intent, configPath, fileName) { |
66 | 78 | return { |
67 | 79 | id, |
|