From 12c64c705b8e8df75dd89ca0d13ba39b6da58248 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Wed, 4 Nov 2026 16:46:00 +0000 Subject: [PATCH] Handle Node.js alpha releases Create `latest-vN.x` links for Node.js alpha releases. Do not link `latest` to alpha releases. Signed-off-by: Richard Lau --- common.js | 9 ++++--- test.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/common.js b/common.js index cdd5adb..b450e1e 100755 --- a/common.js +++ b/common.js @@ -45,14 +45,17 @@ class Linker { await this.#makeDocsLinks(allDirs.map((d) => d.raw)) - this.#dirs = allDirs.filter((d) => semver.satisfies(d, '~0.10 || ~0.12 || >= 1.0')).map((d) => d.raw) + this.#dirs = allDirs.filter((d) => semver.satisfies(d, '~0.10 || ~0.12 || >= 1.0', { includePrerelease: true })).map((d) => d.raw) this.#dirs.sort((d1, d2) => semver.compare(d1, d2)) this.#link('0.10') this.#link(0.12) + // Stop looking for links at one semver after the highest mapped LTS line. + const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }) + const ceiling = Number(Object.keys(ltsNames).sort(collator.compare).at(-1)) + 1 for (let i = 1; ; i++) { - if (!this.#link(i) && i >= 4) { + if (!this.#link(i) && i >= ceiling) { break } } @@ -92,7 +95,7 @@ class Linker { #link (version) { const line = version && `${version}.x` const range = version ? `${Number(version) < 1 ? '~' : '^'}${line}` : '*' - const max = semver.maxSatisfying(this.#dirs, range) + const max = semver.maxSatisfying(this.#dirs, range, { includePrerelease: version != null }) if (!max) { return false diff --git a/test.js b/test.js index 9adfb07..645517d 100644 --- a/test.js +++ b/test.js @@ -13,6 +13,12 @@ tap.test('Linker', async t => { async () => ['docs/', 'win-x64/', 'node-v20.8.0-aix-ppc64.tar.gz', 'node-v20.8.0-arm64.msi', 'node-v20.8.0-headers.tar.gz', 'node-v20.8.0.tar.gz'] ) t.same(links, new Map([ + ['base/latest-v19.x', 'base/v19.9.0'], + ['docs/latest-v19.x', 'base/v19.9.0/docs'], + ['base/latest-v20.x', 'base/v20.8.0'], + ['docs/latest-v20.x', 'base/v20.8.0/docs'], + ['base/latest-iron', 'base/v20.8.0'], + ['docs/latest-iron', 'base/v20.8.0/docs'], ['docs/v19.8.0', 'base/v19.8.0/docs'], ['docs/v19.8.1', 'base/v19.8.1/docs'], ['docs/v19.9.0', 'base/v19.9.0/docs'], @@ -51,3 +57,69 @@ tap.test('basic test', t => { } t.end() }) + +tap.test('latest does not link to alphas', async t => { + const linker = new Linker({ baseDir: 'base', docsDir: 'docs' }) + const fakeReaddir = async (v) => { + const version = path.basename(v) + // Mimimum expected content are the `docs` directory, and + // the source tarball which gets mapped to `nodejs-latest.tar.gz`. + return ['docs/', `node-${version}.tar.gz`] + } + const expected = [] + const fixtures = [] + for (const version of ['v26.13.0', 'v27.0.0-alpha.0.0.0']) { + const line = version.split('.')[0] + fixtures.push(version) + // Link under docs + expected.push([`docs/${version}`, `base/${version}/docs`]) + // `latest-v.x` links + expected.push([`base/latest-${line}.x`, `base/${version}`]) + expected.push([`docs/latest-${line}.x`, `base/${version}/docs`]) + } + // v26.13.0 should result in `latest-lithium` links + expected.push(['base/latest-lithium', 'base/v26.13.0']) + expected.push(['docs/latest-lithium', 'base/v26.13.0/docs']) + // Expect `latest` to point to the non-alpha release + expected.push(['base/latest', 'base/v26.13.0']) + expected.push(['base/node-latest.tar.gz', 'base/latest/node-v26.13.0.tar.gz']) + expected.push(['docs/latest', 'base/v26.13.0/docs']) + + const links = await linker.getLinks(fixtures, fakeReaddir) + t.same(links, new Map(expected)) + t.end() +}) + +tap.test('alphas are ignored after current release', async t => { + const linker = new Linker({ baseDir: 'base', docsDir: 'docs' }) + const fakeReaddir = async (v) => { + const version = path.basename(v) + // Mimimum expected content are the `docs` directory, and + // the source tarball which gets mapped to `nodejs-latest.tar.gz`. + return ['docs/', `node-${version}.tar.gz`] + } + const expected = [] + const fixtures = [] + for (const version of ['v26.13.0', 'v27.0.0-alpha.0.0.0', 'v27.0.0']) { + const line = version.split('.')[0] + fixtures.push(version) + // Link under docs + expected.push([`docs/${version}`, `base/${version}/docs`]) + // `latest-v.x` links + expected.push([`base/latest-${line}.x`, `base/${version}`]) + expected.push([`docs/latest-${line}.x`, `base/${version}/docs`]) + } + // v26.13.0 should result in `latest-lithium` links + expected.push(['base/latest-lithium', 'base/v26.13.0']) + expected.push(['docs/latest-lithium', 'base/v26.13.0/docs']) + // TODO: test will need to be updated to expect `latest-magnesium` + // when mapping in `common.js` is in place for `27: 'magnesium'`. + // Expect `latest` to point to the non-alpha 27.0.0 release + expected.push(['base/latest', 'base/v27.0.0']) + expected.push(['base/node-latest.tar.gz', 'base/latest/node-v27.0.0.tar.gz']) + expected.push(['docs/latest', 'base/v27.0.0/docs']) + + const links = await linker.getLinks(fixtures, fakeReaddir) + t.same(links, new Map(expected)) + t.end() +})