Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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()
})