1
0
mirror of synced 2025-12-20 10:28:40 -05:00

Remove versions feature flag code (#15793)

* remove FEATURE_NEW_VERSIONS from feature-flags.json

* remove process.env.FEATURE_NEW_VERSIONS from include files

* remove process.env.FEATURE_NEW_VERSIONS from lib files

* remove process.env.FEATURE_NEW_VERSIONS from middleware files

* remove process.env.FEATURE_NEW_VERSIONS from script files

* remove process.env.FEATURE_NEW_VERSIONS from test files

* update test fixtures to use new versions as canonical fixtures
This commit is contained in:
Sarah Schneider
2020-09-29 13:36:07 -04:00
committed by GitHub
parent 6762f8c1b7
commit aa5a62d49d
95 changed files with 1333 additions and 3965 deletions

View File

@@ -1,107 +1,47 @@
const slash = require('slash')
const path = require('path')
const patterns = require('./patterns')
const { latest, deprecated } = require('./enterprise-server-releases')
const internalProducts = Object.values(require('./all-products'))
.filter(prod => !prod.external)
const { deprecated } = require('./enterprise-server-releases')
const allProducts = require('./all-products')
const allVersions = require('./all-versions')
const { getNewVersionedPath } = require('./old-versions-utils')
let pathsThatHaveEnterpriseUserVersions, pathsThatDoNotHaveEnterpriseUserVersions
if (!process.env.FEATURE_NEW_VERSIONS) {
pathsThatHaveEnterpriseUserVersions = internalProducts
.filter(prod => prod.hasEnterpriseUserVersions)
.map(prod => prod.href)
.concat(['/articles', '/categories'])
pathsThatDoNotHaveEnterpriseUserVersions = internalProducts
.filter(prod => !prod.hasEnterpriseUserVersions)
.map(prod => prod.href)
.concat(['/enterprise'])
}
// construct appropriate versioned path for any given HREF
function getVersionedPathWithoutLanguage (href, version) {
// start clean without language code or trailing slash
href = getPathWithoutLanguage(href.replace(patterns.trailingSlash, '$1'))
if (!process.env.FEATURE_NEW_VERSIONS) {
// does href need an enterprise user path?
// e.g., /articles/foo -> /en/enterprise/2.15/user/articles/foo
// also redirects like /common-issues-and-questions
// but NOT /actions, /desktop, /enterprise, etc.
const needsEnterpriseUserPath = (
pathsThatHaveEnterpriseUserVersions.some(path => href.startsWith(path)) ||
!pathsThatDoNotHaveEnterpriseUserVersions.some(path => href.startsWith(path))
)
// construct enterprise user path
if (needsEnterpriseUserPath && version !== 'dotcom') {
href = `/enterprise/${version}/user/${href}`
}
// hack fix for double slash bug
href = href.replace('//', '/')
// does href need an enterprise version added to path?
const needsEnterpriseVersion = (
href.match(patterns.enterprise) &&
href.match(patterns.getEnterpriseVersionNumber) === null
)
// add the enterprise version
if (needsEnterpriseVersion) {
// if current page version is dotcom, use the latest version of enterprise
href = version === 'dotcom'
? href.replace(/(\/enterprise)/, `$1/${latest}`)
: href.replace(/(\/enterprise)/, `$1/${version}`)
}
// is this an enterprise user path on dotcom?
const isEnterpriseUsePath = href.match(patterns.enterprise) && !href.match(patterns.admin)
// if so, replace enterprise user part of path with /github/
if (isEnterpriseUsePath && version === 'dotcom') {
href = href.replace(/\/enterprise\/.+?\/user\//, '')
}
return slash(href.replace(patterns.trailingSlash, '$1'))
// if this is an old versioned path that includes a deprecated version, do not change!
// example: /enterprise/11.10.340/admin/articles/upgrading-to-the-latest-release
const oldEnterpriseVersionNumber = href.match(patterns.getEnterpriseVersionNumber)
if (oldEnterpriseVersionNumber && deprecated.includes(oldEnterpriseVersionNumber[1])) {
return href
}
if (process.env.FEATURE_NEW_VERSIONS) {
// if this is an old versioned path that includes a deprecated version, do not change!
// example: /enterprise/11.10.340/admin/articles/upgrading-to-the-latest-release
const oldEnterpriseVersionNumber = href.match(patterns.getEnterpriseVersionNumber)
if (oldEnterpriseVersionNumber && deprecated.includes(oldEnterpriseVersionNumber[1])) {
return href
}
// try to derive the current version from the path
// example: enterprise-server@2.22 or free-pro-team@latest
let versionFromPath = getVersionStringFromPath(href)
// try to derive the current version from the path
// example: enterprise-server@2.22 or free-pro-team@latest
let versionFromPath = getVersionStringFromPath(href)
// if this is an old versioned path, convert to new versioned path
// OLD: /enterprise/2.22/admin/installation or /enterprise/admin/installation
// NEW: /enterprise-server@2.22/admin/installation
// OLD: /desktop/installing-and-configuring-github-desktop
// NEW: /free-pro-team@latest/desktop/installing-and-configuring-github-desktop
if (!Object.keys(allVersions).includes(versionFromPath)) {
href = getNewVersionedPath(href)
versionFromPath = getVersionStringFromPath(href)
}
// derive the product from the path (e.g., github or admin) and get corresponding object
const productObjectFromPath = getProductObjectFromPath(href)
// if the product's versions don't include the specified version, nothing to change!
if (productObjectFromPath && !productObjectFromPath.versions.includes(version)) {
return slash(href)
}
// update the version
return slash(href.replace(versionFromPath, version))
// if this is an old versioned path, convert to new versioned path
// OLD: /enterprise/2.22/admin/installation or /enterprise/admin/installation
// NEW: /enterprise-server@2.22/admin/installation
// OLD: /desktop/installing-and-configuring-github-desktop
// NEW: /free-pro-team@latest/desktop/installing-and-configuring-github-desktop
if (!Object.keys(allVersions).includes(versionFromPath)) {
href = getNewVersionedPath(href)
versionFromPath = getVersionStringFromPath(href)
}
// derive the product from the path (e.g., github or admin) and get corresponding object
const productObjectFromPath = getProductObjectFromPath(href)
// if the product's versions don't include the specified version, nothing to change!
if (productObjectFromPath && !productObjectFromPath.versions.includes(version)) {
return slash(href)
}
// update the version
return slash(href.replace(versionFromPath, version))
}
// add language code
@@ -127,16 +67,7 @@ function getPathWithoutLanguage (href) {
}
function getPathWithoutVersion (href) {
if (!process.env.FEATURE_NEW_VERSIONS) {
const number = href.match(patterns.getEnterpriseVersionNumber)
if (!number) return href
return slash(href.replace('/' + number[1], ''))
}
if (process.env.FEATURE_NEW_VERSIONS) {
return href.replace(`/${getVersionStringFromPath(href)}`, '')
}
return href.replace(`/${getVersionStringFromPath(href)}`, '')
}
function getVersionStringFromPath (href) {