diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 3bb9c9355ba..b226f441971 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -4,8 +4,8 @@ import { apiPages } from './api-pages'; import { algoliaIndex, currentVersion, - oldVersions, versionBannerInfix, + versionLinks, } from './versions'; type SidebarItem = DefaultTheme.SidebarItem; @@ -225,7 +225,7 @@ const config: UserConfig = { text: 'Release Notes', link: 'https://github.com/faker-js/faker/releases', }, - ...oldVersions.map(({ version, link }) => ({ + ...versionLinks.map(({ version, link }) => ({ text: version, link, })), diff --git a/docs/.vitepress/versions.ts b/docs/.vitepress/versions.ts index a44b65c39ba..9d693e3d730 100644 --- a/docs/.vitepress/versions.ts +++ b/docs/.vitepress/versions.ts @@ -9,17 +9,13 @@ function readBranchName(): string { } function readOtherLatestReleaseTagNames(): string[] { - const currentMajorVersion = semver.major(version); const latestReleaseTagNames = execSync('git tag -l') .toString('utf8') .split('\n') .filter((tag) => semver.valid(tag)) - .filter((tag) => { - // Only consider tags for our deployed website versions, - // excluding the current major version. - const majorVersion = semver.major(tag); - return majorVersion >= 6 && majorVersion !== currentMajorVersion; - }) + // Only consider tags for our deployed website versions + .filter((tag) => semver.major(tag) >= 6) + // Find the latest tag for each major version .reduce>((latestTagByMajor, tag) => { const majorVersion = semver.major(tag); @@ -39,10 +35,6 @@ const { BRANCH: branchName = readBranchName(), } = process.env; -const hiddenLink = - deployContext === 'production' - ? 'https://fakerjs.dev/' - : `https://${branchName}.fakerjs.dev/`; const otherVersions = readOtherLatestReleaseTagNames(); const isReleaseBranch = /^v\d+$/.test(branchName); @@ -60,11 +52,7 @@ export const versionBannerInfix: string | null = (() => { })(); export const currentVersion = isReleaseBranch ? `v${version}` : branchName; -export const oldVersions = [ - { - version: 'latest', - link: 'https://fakerjs.dev/', - }, +export const versionLinks = [ { version: 'next', link: 'https://next.fakerjs.dev/', @@ -73,7 +61,9 @@ export const oldVersions = [ version, link: `https://v${semver.major(version)}.fakerjs.dev/`, })), -].filter(({ link }) => link !== hiddenLink); +] + // Don't link to the current branch's version. + .filter(({ link }) => link !== `https://${branchName}.fakerjs.dev/`); export const algoliaIndex = isReleaseBranch ? `fakerjs-v${semver.major(version)}` diff --git a/test/docs/versions.spec.ts b/test/docs/versions.spec.ts index 777efcb2c9c..5567fd7323f 100644 --- a/test/docs/versions.spec.ts +++ b/test/docs/versions.spec.ts @@ -1,7 +1,7 @@ import { execSync } from 'node:child_process'; import * as semver from 'semver'; import { describe, expect, it } from 'vitest'; -import { oldVersions } from '../../docs/.vitepress/versions'; +import { versionLinks } from '../../docs/.vitepress/versions'; function isFakerOrigin(): boolean { try { @@ -22,19 +22,14 @@ function isFakerOrigin(): boolean { describe.runIf(isFakerOrigin())('docs versions', () => { describe('oldVersions', () => { it('should have a complete set of oldVersions', () => { - expect(oldVersions.length).toBeGreaterThanOrEqual(2); + expect(versionLinks.length).toBeGreaterThanOrEqual(1); - expect(oldVersions[0]).toEqual({ - version: 'latest', - link: 'https://fakerjs.dev/', - }); - - const versionEntry = oldVersions[1]; + const versionEntry = versionLinks[0]; if (versionEntry.version === 'next') { expect(versionEntry.link).toBe('https://next.fakerjs.dev/'); } - const releaseVersions = oldVersions.filter(({ version }) => + const releaseVersions = versionLinks.filter(({ version }) => semver.valid(version) ); const latestMajorRelease = semver.major(releaseVersions[0].version); diff --git a/tsconfig.json b/tsconfig.json index a949c9c3bf2..6d3b09b3e82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "noEmit": true, "declaration": true, "stripInternal": true, + "verbatimModuleSyntax": true, // These are configs specifically for !build and have to be reverted in the tsconfig.build.json "skipLibCheck": true,