11const allVersions = require ( './all-versions' )
2+ const { next } = require ( './enterprise-server-releases' )
23const versionSatisfiesRange = require ( './version-satisfies-range' )
34
45// return an array of versions that an article's product versions encompasses
@@ -15,6 +16,8 @@ function getApplicableVersions (frontmatterVersions, filepath) {
1516 // get an array like: [ 'free-pro-team@latest', 'enterprise-server@2.21', 'enterprise-cloud@latest' ]
1617 const applicableVersions = [ ]
1718
19+ let nextVersion = false
20+
1821 // where frontmatter is something like:
1922 // free-pro-team: '*'
2023 // enterprise-server: '>=2.19'
@@ -23,6 +26,15 @@ function getApplicableVersions (frontmatterVersions, filepath) {
2326 // ^ where each key corresponds to a plan
2427 Object . entries ( frontmatterVersions )
2528 . forEach ( ( [ plan , planValue ] ) => {
29+ // Special handling for frontmatter that evalues to the next GHES release number or a hardcoded `next`:
30+ // we don't want to return it in the applicable versions array or it will become a permalink,
31+ // but we also don't want to throw an error if no other versions are found.
32+ if ( planValue !== '*' ) {
33+ if ( versionSatisfiesRange ( next , planValue ) || planValue === 'next' ) {
34+ nextVersion = true
35+ }
36+ }
37+
2638 // for each plan (e.g., enterprise-server), get matching versions from allVersions object
2739 const relevantVersions = Object . values ( allVersions ) . filter ( v => v . plan === plan )
2840
@@ -42,7 +54,7 @@ function getApplicableVersions (frontmatterVersions, filepath) {
4254 } )
4355 } )
4456
45- if ( ! applicableVersions . length ) {
57+ if ( ! applicableVersions . length && ! nextVersion ) {
4658 throw new Error ( `No applicable versions found for ${ filepath } . Please double-check the page's \`versions\` frontmatter.` )
4759 }
4860
0 commit comments