Skip to content

Commit

Permalink
Hotfix version parsing breaking build by ignoring non-semver (#55)
Browse files Browse the repository at this point in the history
FIXES #54
  • Loading branch information
hobofan authored Feb 3, 2023
1 parent 107ee8e commit dadcc83
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
24 changes: 21 additions & 3 deletions data/moduleStaticProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import compareVersions from 'compare-versions'
import { compareVersions, validate as validateVersion } from 'compare-versions'
import {
extractModuleInfo,
getModuleMetadata,
Expand All @@ -24,8 +24,8 @@ export const getStaticPropsModulePage = async (
version: string | null
) => {
const metadata = await getModuleMetadata(module)
const { versions } = metadata
versions.sort(compareVersions)
let { versions } = metadata
versions = sortVersions(versions)

const versionInfos: VersionInfo[] = await Promise.all(
versions.map(async (version) => ({
Expand All @@ -48,3 +48,21 @@ export const getStaticPropsModulePage = async (
},
}
}

/**
* Sort versions, by splitting them into sortable and unsortable ones.
*
* The sortable versions will form the start of the list and are sorted, while the unsortable ones will
* form the end of it.
*
* This is mostly a placeholder until we have proper version parsing and comparison
* (see discussion in https://github.com/bazel-contrib/bcr-ui/issues/54).
*/
const sortVersions = (versions: string[]): string[] => {
const sortableVersions = versions.filter((version) => validateVersion(version))
const unsortableVersions = versions.filter((version) => !validateVersion(version))
sortableVersions.sort(compareVersions)
sortableVersions.reverse()

return [...sortableVersions,...unsortableVersions];
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"compare-versions": "^4.1.3",
"compare-versions": "^6.0.0-rc.1",
"date-fns": "^2.28.0",
"execa": "^6.1.0",
"fuse.js": "^6.6.2",
Expand Down
10 changes: 2 additions & 8 deletions pages/modules/[module].tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import type { GetStaticProps, NextPage } from 'next'
import compareVersions from 'compare-versions'
import Head from 'next/head'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { Header, USER_GUIDE_LINK } from '../../components/Header'
import { Footer } from '../../components/Footer'
import {
extractModuleInfo,
getModuleMetadata,
getSubmissionCommitOfVersion,
listModuleNames,
Metadata,
ModuleInfo,
} from '../../data/utils'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faGithub } from '@fortawesome/free-brands-svg-icons'
Expand Down Expand Up @@ -46,7 +41,6 @@ const ModulePage: NextPage<ModulePageProps> = ({
const displayShowAllButton = isQualifiedForShowAll && !triggeredShowAll

const versionInfo = versionInfos.find((n) => n.version === selectedVersion)
const versionsInOrder = versionInfos.slice().reverse()

const githubLink = metadata.repository
?.find((repo) => repo.startsWith('github:'))
Expand All @@ -56,8 +50,8 @@ const ModulePage: NextPage<ModulePageProps> = ({
: undefined

const shownVersions = triggeredShowAll
? versionsInOrder
: versionsInOrder.slice(0, NUM_VERSIONS_ON_PAGE_LOAD)
? versionInfos
: versionInfos.slice(0, NUM_VERSIONS_ON_PAGE_LOAD)

if (!versionInfo) {
throw Error(
Expand Down
4 changes: 0 additions & 4 deletions pages/modules/[module]/[version].tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import ModulePage from '../[module]'
import { GetStaticProps } from 'next'
import {
extractModuleInfo,
getModuleMetadata,
getSubmissionCommitOfVersion,
listModuleNames,
listModuleVersions,
} from '../../../data/utils'
import compareVersions from 'compare-versions'
import { getStaticPropsModulePage } from '../../../data/moduleStaticProps'

export const getStaticProps: GetStaticProps = async ({ params }) => {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dadcc83

Please sign in to comment.