Skip to content

Commit 8ee5cd7

Browse files
authored
Update ghes deprecation code (#53910)
1 parent a3b00ef commit 8ee5cd7

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

src/archives/middleware/archived-enterprise-versions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ export default async function archivedEnterpriseVersions(
226226
// Releases 3.2 and higher contain image asset paths with the
227227
// old Azure Blob Storage URL. These need to be rewritten to
228228
// the new archived enterprise repo URL.
229-
if (versionSatisfiesRange(requestedVersion, `>=${firstReleaseStoredInBlobStorage}`)) {
229+
if (
230+
versionSatisfiesRange(requestedVersion, `>=${firstReleaseStoredInBlobStorage}`) &&
231+
versionSatisfiesRange(requestedVersion, `<=3.9`)
232+
) {
230233
// `x-host` is a custom header set by Fastly.
231234
// GLB automatically deletes the `x-forwarded-host` header.
232235
const host = req.get('x-host') || req.get('x-forwarded-host') || req.get('host')

src/frame/middleware/helmet.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ const DEFAULT_OPTIONS = {
3636
// For use during development only!
3737
// `unsafe-eval` allows us to use a performant webpack devtool setting (eval)
3838
// https://webpack.js.org/configuration/devtool/#devtool
39-
scriptSrc: ["'self'", 'data:', isDev && "'unsafe-eval'"].filter(Boolean) as string[],
39+
scriptSrc: [...GITHUB_DOMAINS, "'self'", 'data:', isDev && "'unsafe-eval'"].filter(
40+
Boolean,
41+
) as string[],
4042
scriptSrcAttr: ["'self'"],
4143
frameSrc: [
4244
...GITHUB_DOMAINS,
@@ -49,7 +51,7 @@ const DEFAULT_OPTIONS = {
4951
'https://www.youtube-nocookie.com',
5052
].filter(Boolean) as string[],
5153
frameAncestors: isDev ? ['*'] : [...GITHUB_DOMAINS],
52-
styleSrc: ["'self'", "'unsafe-inline'", 'data:'],
54+
styleSrc: [...GITHUB_DOMAINS, "'self'", "'unsafe-inline'", 'data:'],
5355
childSrc: ["'self'"], // exception for search in deprecated GHE versions
5456
manifestSrc: ["'self'"],
5557
upgradeInsecureRequests: isDev ? null : [],

src/ghes-releases/scripts/archive-version.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { RewriteAssetPathsPlugin } from '@/ghes-releases/scripts/rewrite-asset-p
2525
const port = '4001'
2626
const host = `http://localhost:${port}`
2727
const version = EnterpriseServerReleases.oldestSupported
28-
const REMOTE_ENTERPRISE_STORAGE_URL = 'https://githubdocs.azureedge.net/enterprise'
28+
const GH_PAGES_URL = `https://github.github.com/docs-ghes-${version}`
2929

3030
// Once page-data.js is converted to TS,
3131
// we can import the more comprehesive type
@@ -108,14 +108,7 @@ async function main() {
108108
directory: tmpArchivalDirectory,
109109
filenameGenerator: 'bySiteStructure',
110110
requestConcurrency: 6,
111-
plugins: [
112-
new RewriteAssetPathsPlugin(
113-
version,
114-
tmpArchivalDirectory,
115-
localDev,
116-
REMOTE_ENTERPRISE_STORAGE_URL,
117-
),
118-
],
111+
plugins: [new RewriteAssetPathsPlugin(tmpArchivalDirectory, localDev, GH_PAGES_URL)],
119112
}).catch((err: Error) => {
120113
console.error('scraping error')
121114
console.error(err)

src/ghes-releases/scripts/rewrite-asset-paths.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import fs from 'fs'
22
import path from 'path'
33

44
export class RewriteAssetPathsPlugin {
5-
version: string
65
tempDirectory: string
76
localDev: boolean
87
replaceUrl: string
98

10-
constructor(version: string, tempDirectory: string, localDev: boolean, replaceUrl: string) {
11-
this.version = version
9+
constructor(tempDirectory: string, localDev: boolean, replaceUrl: string) {
1210
this.tempDirectory = tempDirectory
1311
this.localDev = localDev
1412
this.replaceUrl = replaceUrl
@@ -28,7 +26,7 @@ export class RewriteAssetPathsPlugin {
2826

2927
// Rewrite HTML asset paths. Example:
3028
// ../assets/images/foo/bar.png ->
31-
// https://githubdocs.azureedge.net/github-images/enterprise/2.17/assets/images/foo/bar.png
29+
// https://github.github.com/docs-ghes-3.10/assets/images/foo/bar.png
3230

3331
if (resource.isHtml()) {
3432
// Remove nextjs scripts and manifest.json link
@@ -42,8 +40,8 @@ export class RewriteAssetPathsPlugin {
4240
// Rewrite asset paths
4341
newBody = newBody.replace(
4442
/(?<attribute>src|href)="(?:\.\.\/|\/)*(?<basepath>_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g,
45-
(attribute: string, basepath: string) => {
46-
const replaced = `${this.replaceUrl}/${this.version}/${basepath}`
43+
(match: string, attribute: string, basepath: string) => {
44+
const replaced = `${this.replaceUrl}/${basepath}`
4745
return `${attribute}="${replaced}`
4846
},
4947
)
@@ -52,15 +50,15 @@ export class RewriteAssetPathsPlugin {
5250

5351
// Rewrite CSS asset paths. Example
5452
// url("../assets/fonts/alliance/alliance-no-1-regular.woff") ->
55-
// url("https://githubdocs.azureedge.net/github-images/enterprise/2.20/assets/fonts/alliance/alliance-no-1-regular.woff")
53+
// url("https://github.github.com/docs-ghes-3.10/assets/fonts/alliance/alliance-no-1-regular.woff")
5654
// url(../../../assets/cb-303/images/octicons/search-24.svg) ->
57-
// url(https://githubdocs.azureedge.net/github-images/enterprise/2.20/assets/cb-303/images/octicons/search-24.svg)
55+
// url(https://github.github.com/docs-ghes-3.10/assets/cb-303/images/octicons/search-24.svg)
5856
if (resource.isCss()) {
5957
if (!this.localDev) {
6058
newBody = newBody.replace(
6159
/(?<attribute>url)(?<paren>\("|\()(?:\.\.\/)*(?<basepath>_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g,
62-
(attribute: string, paren: string, basepath: string) => {
63-
const replaced = `${this.replaceUrl}/${this.version}/${basepath}`
60+
(match: string, attribute: string, paren: string, basepath: string) => {
61+
const replaced = `${this.replaceUrl}/${basepath}`
6462
return `${attribute}${paren}${replaced}`
6563
},
6664
)

0 commit comments

Comments
 (0)