@@ -1,8 +1,12 @@
|
||||
const parse = require('./read-frontmatter')
|
||||
const layoutNames = Object.keys(require('./layouts')).concat([false])
|
||||
const semver = require('semver')
|
||||
const layouts = require('./layouts')
|
||||
|
||||
const semverValidRange = semver.validRange
|
||||
const layoutNames = Object.keys(layouts).concat([false])
|
||||
const semverRange = {
|
||||
type: 'string',
|
||||
conform: require('semver').validRange,
|
||||
conform: semverValidRange,
|
||||
message: 'Must be a valid SemVer range'
|
||||
}
|
||||
const versionIds = Object.keys(require('./all-versions'))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const path = require('path')
|
||||
const patterns = require('../patterns')
|
||||
const supportedVersions = new Set(Object.keys(require('../all-versions')))
|
||||
const allVersions = require('../all-versions')
|
||||
const supportedVersions = new Set(Object.keys(allVersions))
|
||||
const getOldPathsFromPermalink = require('./get-old-paths-from-permalink')
|
||||
const { getVersionStringFromPath } = require('../path-utils')
|
||||
const { getNewVersionedPath } = require('../old-versions-utils')
|
||||
|
||||
@@ -6,7 +6,7 @@ const operations = {}
|
||||
fs.readdirSync(schemasPath)
|
||||
.forEach(filename => {
|
||||
const key = filename.replace('.json', '')
|
||||
const value = require(path.join(schemasPath, filename))
|
||||
const value = JSON.parse(fs.readFileSync(path.join(schemasPath, filename)))
|
||||
operations[key] = value
|
||||
})
|
||||
const allVersions = require('../all-versions')
|
||||
|
||||
@@ -19,7 +19,7 @@ versions.forEach(version => {
|
||||
// payload file: /path/to/check_run.completed.payload.json
|
||||
// payload path: check_run.completed
|
||||
const payloadPath = path.basename(payloadFile).replace('.payload.json', '')
|
||||
set(payloadsPerVersion, payloadPath, formatAsJsonCodeBlock(require(payloadFile)))
|
||||
set(payloadsPerVersion, payloadPath, formatAsJsonCodeBlock(JSON.parse(fs.readFileSync(payloadFile))))
|
||||
})
|
||||
|
||||
payloads[version] = payloadsPerVersion
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const previews = require('../../lib/graphql/static/previews')
|
||||
const upcomingChanges = require('../../lib/graphql/static/upcoming-changes')
|
||||
const changelog = require('../../lib/graphql/static/changelog')
|
||||
@@ -23,7 +25,7 @@ module.exports = function graphqlContext (req, res, next) {
|
||||
const graphqlVersion = currentVersionObj.miscVersionName
|
||||
|
||||
req.context.graphql = {
|
||||
schemaForCurrentVersion: require(`../../lib/graphql/static/schema-${graphqlVersion}`),
|
||||
schemaForCurrentVersion: JSON.parse(fs.readFileSync(path.join(process.cwd(), `lib/graphql/static/schema-${graphqlVersion}.json`))),
|
||||
previewsForCurrentVersion: previews[graphqlVersion],
|
||||
upcomingChangesForCurrentVersion: upcomingChanges[graphqlVersion],
|
||||
prerenderedObjectsForCurrentVersion: prerenderedObjects[graphqlVersion],
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const cookieSettings = require('../lib/cookie-settings')
|
||||
|
||||
module.exports = require('csurf')({
|
||||
cookie: require('../lib/cookie-settings'),
|
||||
cookie: cookieSettings,
|
||||
ignoreMethods: ['GET', 'HEAD', 'OPTIONS']
|
||||
})
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
const express = require('express')
|
||||
const instrument = require('../lib/instrument-middleware')
|
||||
const haltOnDroppedConnection = require('./halt-on-dropped-connection')
|
||||
const abort = require('./abort')
|
||||
const timeout = require('./timeout')
|
||||
const morgan = require('morgan')
|
||||
const datadog = require('./connect-datadog')
|
||||
const rateLimit = require('./rate-limit')
|
||||
const cors = require('./cors')
|
||||
const helmet = require('helmet')
|
||||
const csp = require('./csp')
|
||||
const cookieParser = require('./cookie-parser')
|
||||
const csrf = require('./csrf')
|
||||
const handleCsrfErrors = require('./handle-csrf-errors')
|
||||
const compression = require('compression')
|
||||
const disableCachingOnSafari = require('./disable-caching-on-safari')
|
||||
const setFastlySurrogateKey = require('./set-fastly-surrogate-key')
|
||||
const setFastlyCacheHeaders = require('./set-fastly-cache-headers')
|
||||
const catchBadAcceptLanguage = require('./catch-bad-accept-language')
|
||||
const reqUtils = require('./req-utils')
|
||||
const recordRedirect = require('./record-redirect')
|
||||
const connectSlashes = require('connect-slashes')
|
||||
const handleErrors = require('./handle-errors')
|
||||
|
||||
const { NODE_ENV } = process.env
|
||||
const isDevelopment = NODE_ENV === 'development'
|
||||
@@ -15,58 +35,57 @@ const asyncMiddleware = fn =>
|
||||
|
||||
module.exports = function (app) {
|
||||
// *** Request connection management ***
|
||||
if (!isTest) app.use(require('./timeout'))
|
||||
app.use(require('./abort'))
|
||||
if (!isTest) app.use(timeout)
|
||||
app.use(abort)
|
||||
|
||||
// *** Development tools ***
|
||||
app.use(require('morgan')('dev', { skip: (req, res) => !isDevelopment }))
|
||||
if (isDevelopment) app.use(require('./webpack'))
|
||||
app.use(morgan('dev', { skip: (req, res) => !isDevelopment }))
|
||||
|
||||
// *** Observability ***
|
||||
if (process.env.DD_API_KEY) {
|
||||
app.use(require('./connect-datadog'))
|
||||
app.use(datadog)
|
||||
}
|
||||
|
||||
// *** Early exits ***
|
||||
// Don't use the proxy's IP, use the requester's for rate limiting
|
||||
// See https://expressjs.com/en/guide/behind-proxies.html
|
||||
app.set('trust proxy', 1)
|
||||
app.use(require('./rate-limit'))
|
||||
app.use(rateLimit)
|
||||
app.use(instrument('./handle-invalid-paths'))
|
||||
app.use(instrument('./handle-next-data-path'))
|
||||
|
||||
// *** Security ***
|
||||
app.use(require('./cors'))
|
||||
app.use(require('helmet')({
|
||||
app.use(cors)
|
||||
app.use(helmet({
|
||||
// Override referrerPolicy to match the browser's default: "strict-origin-when-cross-origin".
|
||||
// Helmet now defaults to "no-referrer", which is a problem for our archived assets proxying.
|
||||
referrerPolicy: {
|
||||
policy: 'strict-origin-when-cross-origin'
|
||||
}
|
||||
}))
|
||||
app.use(require('./csp')) // Must come after helmet
|
||||
app.use(require('./cookie-parser')) // Must come before csrf
|
||||
app.use(csp) // Must come after helmet
|
||||
app.use(cookieParser) // Must come before csrf
|
||||
app.use(express.json()) // Must come before csrf
|
||||
app.use(require('./csrf'))
|
||||
app.use(require('./handle-csrf-errors')) // Must come before regular handle-errors
|
||||
app.use(csrf)
|
||||
app.use(handleCsrfErrors) // Must come before regular handle-errors
|
||||
|
||||
// *** Headers ***
|
||||
app.set('etag', false) // We will manage our own ETags if desired
|
||||
app.use(require('compression')())
|
||||
app.use(require('./disable-caching-on-safari'))
|
||||
app.use(require('./set-fastly-surrogate-key'))
|
||||
app.use(require('./catch-bad-accept-language'))
|
||||
app.use(compression())
|
||||
app.use(disableCachingOnSafari)
|
||||
app.use(setFastlySurrogateKey)
|
||||
app.use(catchBadAcceptLanguage)
|
||||
|
||||
// *** Config and context for redirects ***
|
||||
app.use(require('./req-utils')) // Must come before record-redirect and events
|
||||
app.use(require('./record-redirect'))
|
||||
app.use(reqUtils) // Must come before record-redirect and events
|
||||
app.use(recordRedirect)
|
||||
app.use(instrument('./detect-language')) // Must come before context, breadcrumbs, find-page, handle-errors, homepages
|
||||
app.use(asyncMiddleware(instrument('./context'))) // Must come before early-access-*, handle-redirects
|
||||
app.use(asyncMiddleware(instrument('./contextualizers/short-versions'))) // Support version shorthands
|
||||
|
||||
// *** Redirects, 3xx responses ***
|
||||
// I ordered these by use frequency
|
||||
app.use(require('connect-slashes')(false))
|
||||
app.use(connectSlashes(false))
|
||||
app.use(instrument('./redirects/external'))
|
||||
app.use(instrument('./redirects/help-to-docs'))
|
||||
app.use(instrument('./redirects/language-code-redirects')) // Must come before contextualizers
|
||||
@@ -132,7 +151,7 @@ module.exports = function (app) {
|
||||
app.use(asyncMiddleware(instrument('./is-next-request')))
|
||||
|
||||
// *** Headers for pages only ***
|
||||
app.use(require('./set-fastly-cache-headers'))
|
||||
app.use(setFastlyCacheHeaders)
|
||||
|
||||
// handle serving NextJS bundled code (/_next/*)
|
||||
if (process.env.FEATURE_NEXTJS) {
|
||||
@@ -146,5 +165,5 @@ module.exports = function (app) {
|
||||
app.get('/*', asyncMiddleware(instrument('./render-page')))
|
||||
|
||||
// *** Error handling, must go last ***
|
||||
app.use(require('./handle-errors'))
|
||||
app.use(handleErrors)
|
||||
}
|
||||
|
||||
@@ -1,38 +1,10 @@
|
||||
const pathToRegexp = require('path-to-regexp')
|
||||
|
||||
const { productIds } = require('../lib/all-products')
|
||||
const versionIds = Object.keys(require('../lib/all-versions'))
|
||||
|
||||
const { FEATURE_NEXTJS } = process.env;
|
||||
|
||||
const homePageExp = pathToRegexp('/:locale/:versionId?')
|
||||
const productPageExp = pathToRegexp('/:locale/:versionId?/:productId')
|
||||
const subSectionExp = pathToRegexp('/:locale/:versionId?/:productId/:subSection*')
|
||||
|
||||
module.exports = function isNextRequest(req, res, next) {
|
||||
req.renderWithNextjs = false;
|
||||
|
||||
if (FEATURE_NEXTJS && !req.path.startsWith('/_next/')) {
|
||||
if ('nextjs' in req.query) {
|
||||
req.renderWithNextjs = true;
|
||||
} else {
|
||||
// Custom path matching to determine if we should render with nextjs
|
||||
|
||||
// Remove any query string (?...) and/or fragment identifier (#...)
|
||||
const { pathname } = new URL(req.originalUrl, "https://docs.github.com");
|
||||
|
||||
// Should the current path be rendered by NextJS?
|
||||
const homePageMatch = homePageExp.exec(pathname)
|
||||
const productPageMatch = productPageExp.exec(pathname)
|
||||
const subSectionMatch = subSectionExp.exec(pathname)
|
||||
if (homePageMatch && (!homePageMatch[2] || versionIds.includes(homePageMatch[2]))) {
|
||||
req.renderWithNextjs = true
|
||||
} else if (productPageMatch && productIds.includes(productPageMatch[3])) {
|
||||
req.renderWithNextjs = true
|
||||
} else if (subSectionMatch) {
|
||||
req.renderWithNextjs = true
|
||||
}
|
||||
}
|
||||
if (FEATURE_NEXTJS) {
|
||||
req.renderWithNextjs = true;
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const express = require('express')
|
||||
const languages = new Set(Object.keys(require('../lib/languages')))
|
||||
const versions = new Set(Object.values(require('../lib/search/versions')))
|
||||
const libLanguages = require('../lib/languages')
|
||||
const searchVersions = require('../lib/search/versions')
|
||||
const languages = new Set(Object.keys(libLanguages))
|
||||
const versions = new Set(Object.values(searchVersions))
|
||||
const loadLunrResults = require('../lib/search/lunr-search')
|
||||
const loadAlgoliaResults = require('../lib/search/algolia-search')
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
const webpack = require('webpack')
|
||||
const middleware = require('webpack-dev-middleware')
|
||||
const config = require('../webpack.config')
|
||||
|
||||
const webpackCompiler = webpack({
|
||||
...config,
|
||||
plugins: [
|
||||
...config.plugins
|
||||
]
|
||||
})
|
||||
|
||||
module.exports = middleware(webpackCompiler, {
|
||||
publicPath: config.output.publicPath
|
||||
})
|
||||
22
package-lock.json
generated
22
package-lock.json
generated
@@ -51,12 +51,12 @@
|
||||
"lodash": "^4.17.21",
|
||||
"lunr": "^2.3.9",
|
||||
"lunr-languages": "^1.4.0",
|
||||
"mdast-util-from-markdown": "^0.8.5",
|
||||
"mdast-util-to-string": "^2.0.0",
|
||||
"morgan": "^1.10.0",
|
||||
"next": "^11.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"parse5": "^6.0.1",
|
||||
"path-to-regexp": "^0.1.7",
|
||||
"port-used": "^2.0.8",
|
||||
"rate-limit-redis": "^2.1.0",
|
||||
"react": "^17.0.2",
|
||||
@@ -143,7 +143,6 @@
|
||||
"jest-slow-test-reporter": "^1.0.0",
|
||||
"linkinator": "^2.13.6",
|
||||
"make-promises-safe": "^5.1.0",
|
||||
"mdast-util-from-markdown": "^0.8.5",
|
||||
"mini-css-extract-plugin": "^1.6.0",
|
||||
"mkdirp": "^1.0.4",
|
||||
"mock-express-response": "^0.3.0",
|
||||
@@ -169,7 +168,6 @@
|
||||
"url-template": "^2.0.8",
|
||||
"webpack": "^5.37.0",
|
||||
"webpack-cli": "^4.7.0",
|
||||
"webpack-dev-middleware": "^4.2.0",
|
||||
"website-scraper": "^4.2.3"
|
||||
},
|
||||
"engines": {
|
||||
@@ -4179,7 +4177,6 @@
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.3.tgz",
|
||||
"integrity": "sha512-SXPBMnFVQg1s00dlMCc/jCdvPqdE4mXaMMCeRlxLDmTAEoegHT53xKtkDnzDTOcmMHUfcjyf36/YYZ6SxRdnsw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/unist": "*"
|
||||
}
|
||||
@@ -16037,7 +16034,6 @@
|
||||
"version": "0.8.5",
|
||||
"resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-0.8.5.tgz",
|
||||
"integrity": "sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/mdast": "^3.0.0",
|
||||
"mdast-util-to-string": "^2.0.0",
|
||||
@@ -16050,7 +16046,6 @@
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz",
|
||||
"integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"character-entities": "^1.0.0",
|
||||
"character-entities-legacy": "^1.0.0",
|
||||
@@ -16261,7 +16256,6 @@
|
||||
"version": "2.11.3",
|
||||
"resolved": "https://registry.npmjs.org/micromark/-/micromark-2.11.3.tgz",
|
||||
"integrity": "sha512-oph5YYkVqR2U9OtWBcXYysZMtrdIvi8dfSeyEdr1wFr3Bk6YwI6THosX2AzKnhdps7mVUbXiqhmosu9DcA+xlQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"debug": "^4.0.0",
|
||||
"parse-entities": "^2.0.0"
|
||||
@@ -16271,7 +16265,6 @@
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
|
||||
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
@@ -16282,14 +16275,12 @@
|
||||
"node_modules/micromark/node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"dev": true
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node_modules/micromark/node_modules/parse-entities": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz",
|
||||
"integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"character-entities": "^1.0.0",
|
||||
"character-entities-legacy": "^1.0.0",
|
||||
@@ -28366,7 +28357,6 @@
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.3.tgz",
|
||||
"integrity": "sha512-SXPBMnFVQg1s00dlMCc/jCdvPqdE4mXaMMCeRlxLDmTAEoegHT53xKtkDnzDTOcmMHUfcjyf36/YYZ6SxRdnsw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/unist": "*"
|
||||
}
|
||||
@@ -38331,7 +38321,6 @@
|
||||
"version": "0.8.5",
|
||||
"resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-0.8.5.tgz",
|
||||
"integrity": "sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/mdast": "^3.0.0",
|
||||
"mdast-util-to-string": "^2.0.0",
|
||||
@@ -38344,7 +38333,6 @@
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz",
|
||||
"integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"character-entities": "^1.0.0",
|
||||
"character-entities-legacy": "^1.0.0",
|
||||
@@ -38535,7 +38523,6 @@
|
||||
"version": "2.11.3",
|
||||
"resolved": "https://registry.npmjs.org/micromark/-/micromark-2.11.3.tgz",
|
||||
"integrity": "sha512-oph5YYkVqR2U9OtWBcXYysZMtrdIvi8dfSeyEdr1wFr3Bk6YwI6THosX2AzKnhdps7mVUbXiqhmosu9DcA+xlQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"debug": "^4.0.0",
|
||||
"parse-entities": "^2.0.0"
|
||||
@@ -38545,7 +38532,6 @@
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
|
||||
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
@@ -38553,14 +38539,12 @@
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"dev": true
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"parse-entities": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz",
|
||||
"integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"character-entities": "^1.0.0",
|
||||
"character-entities-legacy": "^1.0.0",
|
||||
|
||||
@@ -57,13 +57,12 @@
|
||||
"lodash": "^4.17.21",
|
||||
"lunr": "^2.3.9",
|
||||
"lunr-languages": "^1.4.0",
|
||||
"mdast-util-to-string": "^2.0.0",
|
||||
"mdast-util-from-markdown": "^0.8.5",
|
||||
"mdast-util-to-string": "^2.0.0",
|
||||
"morgan": "^1.10.0",
|
||||
"next": "^11.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"parse5": "^6.0.1",
|
||||
"path-to-regexp": "^0.1.7",
|
||||
"port-used": "^2.0.8",
|
||||
"rate-limit-redis": "^2.1.0",
|
||||
"react": "^17.0.2",
|
||||
@@ -175,7 +174,6 @@
|
||||
"url-template": "^2.0.8",
|
||||
"webpack": "^5.37.0",
|
||||
"webpack-cli": "^4.7.0",
|
||||
"webpack-dev-middleware": "^4.2.0",
|
||||
"website-scraper": "^4.2.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
||||
@@ -63,7 +63,7 @@ async function main () {
|
||||
fs.writeFileSync(newDereferencedFile, newDereferenceContent)
|
||||
console.log(`Created ${newDereferencedFile}.`)
|
||||
|
||||
const dereferencedSchema = require(path.join(process.cwd(), newDereferencedFile))
|
||||
const dereferencedSchema = JSON.parse(fs.readFileSync(path.join(process.cwd(), newDereferencedFile)))
|
||||
|
||||
// Store all operations in an array of operation objects
|
||||
const operations = await getOperations(dereferencedSchema)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const dotenv = require('dotenv')
|
||||
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
require('dotenv').config()
|
||||
dotenv.config()
|
||||
}
|
||||
|
||||
// this module needs to work in development, production, and GitHub Actions
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const walk = require('walk-sync')
|
||||
const slugger = new (require('github-slugger'))()
|
||||
const entities = new (require('html-entities').XmlEntities)()
|
||||
const GithubSlugger = require('github-slugger')
|
||||
const htmlEntities = require('html-entities')
|
||||
const slugger = new GithubSlugger()
|
||||
const entities = new htmlEntities.XmlEntities()
|
||||
const frontmatter = require('../lib/read-frontmatter')
|
||||
const { execSync } = require('child_process')
|
||||
const addRedirectToFrontmatter = require('./helpers/add-redirect-to-frontmatter')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
const program = require('commander')
|
||||
const getOperations = require('./utils/get-operations')
|
||||
@@ -28,8 +29,7 @@ if (filesToCheck.length) {
|
||||
|
||||
async function check (files) {
|
||||
console.log('Verifying OpenAPI files are valid with decorator')
|
||||
|
||||
const documents = files.map(filename => [filename, require(filename)])
|
||||
const documents = files.map(filename => [filename, JSON.parse(fs.readFileSync(path.join(process.cwd(), filename)))])
|
||||
|
||||
for (const [filename, schema] of documents) {
|
||||
try {
|
||||
|
||||
@@ -75,7 +75,7 @@ async function getDereferencedFiles () {
|
||||
// name of the `github/github` checkout. A CI test
|
||||
// checks the version and fails if it's not a semantic version.
|
||||
schemas.forEach(filename => {
|
||||
const schema = require(path.join(dereferencedPath, filename))
|
||||
const schema = JSON.parse(fs.readFileSync(path.join(dereferencedPath, filename)))
|
||||
schema.info.version = `${githubBranch} !!DEVELOPMENT MODE - DO NOT MERGE!!`
|
||||
fs.writeFileSync(path.join(dereferencedPath, filename), JSON.stringify(schema, null, 2))
|
||||
})
|
||||
@@ -85,7 +85,7 @@ async function decorate () {
|
||||
console.log('\n🎄 Decorating the OpenAPI schema files in lib/rest/static/dereferenced.\n')
|
||||
|
||||
const dereferencedSchemas = schemas.reduce((acc, filename) => {
|
||||
const schema = require(path.join(dereferencedPath, filename))
|
||||
const schema = JSON.parse(fs.readFileSync(path.join(dereferencedPath, filename)))
|
||||
const key = filename.replace('.deref.json', '')
|
||||
return { ...acc, [key]: schema }
|
||||
}, {})
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
const { get, flatten, isPlainObject } = require('lodash')
|
||||
const { sentenceCase } = require('change-case')
|
||||
const slugger = new (require('github-slugger'))()
|
||||
const GitHubSlugger = require('github-slugger')
|
||||
const slugger = new GitHubSlugger()
|
||||
const httpStatusCodes = require('http-status-code')
|
||||
const renderContent = require('../../../lib/render-content')
|
||||
const createCodeSamples = require('./create-code-samples')
|
||||
const Ajv = require('ajv')
|
||||
const operationSchema = require('./operation-schema')
|
||||
|
||||
// titles that can't be derived by sentence-casing the ID
|
||||
const categoryTitles = { scim: 'SCIM' }
|
||||
@@ -39,7 +41,7 @@ module.exports = class Operation {
|
||||
}
|
||||
|
||||
get schema () {
|
||||
return require('./operation-schema')
|
||||
return operationSchema
|
||||
}
|
||||
|
||||
async process () {
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
// It can also be run manually. For more info see [contributing/search.md](contributing/search.md)
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
const searchSync = require('./search/sync')
|
||||
require('make-promises-safe')
|
||||
|
||||
main()
|
||||
|
||||
async function main () {
|
||||
const sync = require('./search/sync')
|
||||
const sync = searchSync
|
||||
const opts = {
|
||||
dryRun: 'DRY_RUN' in process.env,
|
||||
language: process.env.LANGUAGE,
|
||||
|
||||
@@ -4,6 +4,9 @@ const throng = require('throng')
|
||||
const os = require('os')
|
||||
const portUsed = require('port-used')
|
||||
const prefixStreamWrite = require('./lib/prefix-stream-write')
|
||||
const libApp = require('./lib/app')
|
||||
const libWarmServer = require('./lib/warm-server')
|
||||
const http = require('http')
|
||||
|
||||
// Intentionally require these for both cluster primary and workers
|
||||
require('./lib/check-node-version')
|
||||
@@ -46,8 +49,8 @@ async function checkPortAvailability () {
|
||||
}
|
||||
|
||||
async function startServer () {
|
||||
const app = require('./lib/app')
|
||||
const warmServer = require('./lib/warm-server')
|
||||
const app = libApp
|
||||
const warmServer = libWarmServer
|
||||
|
||||
// If in a deployed environment...
|
||||
if (NODE_ENV === 'production') {
|
||||
@@ -58,7 +61,7 @@ async function startServer () {
|
||||
}
|
||||
|
||||
// Workaround for https://github.com/expressjs/express/issues/1101
|
||||
const server = require('http').createServer(app)
|
||||
const server = http.createServer(app)
|
||||
server
|
||||
.listen(port, () => console.log(`app running on http://localhost:${port}`))
|
||||
.on('error', () => server.close())
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
/* global page, browser */
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const sleep = require('await-sleep')
|
||||
const { latest } = require('../../lib/enterprise-server-releases')
|
||||
const languages = require('../../lib/languages')
|
||||
const featureFlags = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/feature-flags.json')))
|
||||
|
||||
describe('homepage', () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
@@ -329,7 +332,7 @@ describe('nextjs query param', () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
|
||||
it('landing page renders through nextjs pipeline depending on FEATURE_NEXTJS value', async () => {
|
||||
const flagVal = require('../../feature-flags.json').FEATURE_NEXTJS
|
||||
const flagVal = featureFlags.FEATURE_NEXTJS
|
||||
await page.goto('http://localhost:4001/en/actions?nextjs=')
|
||||
const IS_NEXTJS_PAGE = await page.evaluate(() => window.IS_NEXTJS_PAGE)
|
||||
const nextWrapper = await page.$('#__next')
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const previewsJson = require('../../lib/graphql/static/previews')
|
||||
const upcomingChangesJson = require('../../lib/graphql/static/upcoming-changes')
|
||||
const prerenderedObjectsJson = require('../../lib/graphql/static/prerendered-objects')
|
||||
@@ -20,7 +22,7 @@ describe('graphql json files', () => {
|
||||
|
||||
test('schemas object validation', () => {
|
||||
graphqlVersions.forEach(version => {
|
||||
const schemaJsonPerVersion = require(`../../lib/graphql/static/schema-${version}`)
|
||||
const schemaJsonPerVersion = JSON.parse(fs.readFileSync(path.join(process.cwd(), `lib/graphql/static/schema-${version}.json`)))
|
||||
// all graphql types are arrays except for queries
|
||||
graphqlTypes
|
||||
.filter(type => type !== 'queries')
|
||||
|
||||
@@ -5,6 +5,7 @@ const flat = require('flat')
|
||||
const loadSiteData = require('../../lib/site-data')
|
||||
const patterns = require('../../lib/patterns')
|
||||
const { liquid } = require('../../lib/render-content')
|
||||
const walkSync = require('walk-sync')
|
||||
|
||||
describe('siteData module (English)', () => {
|
||||
let data
|
||||
@@ -82,7 +83,7 @@ describe('siteData module (English)', () => {
|
||||
})
|
||||
|
||||
test('warn if any YAML reusables are found', async () => {
|
||||
const reusables = require('walk-sync')(path.join(__dirname, '../../data/reusables'))
|
||||
const reusables = walkSync(path.join(__dirname, '../../data/reusables'))
|
||||
expect(reusables.length).toBeGreaterThan(100)
|
||||
const yamlReusables = reusables.filter(filename => filename.endsWith('.yml') || filename.endsWith('.yaml'))
|
||||
const message = `reusables are now written as individual Markdown files. Please migrate the following YAML files to Markdown:\n${yamlReusables.join('\n')}`
|
||||
|
||||
@@ -3,6 +3,7 @@ const path = require('path')
|
||||
const { difference, isPlainObject } = require('lodash')
|
||||
const { getJSON } = require('../helpers/supertest')
|
||||
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
||||
const rest = require('../../lib/rest')
|
||||
// list of REST markdown files that do not correspond to REST API resources
|
||||
// TODO could we get this list dynamically, say via page frontmatter?
|
||||
const excludeFromResourceNameCheck = [
|
||||
@@ -15,7 +16,7 @@ describe('REST references docs', () => {
|
||||
jest.setTimeout(3 * 60 * 1000)
|
||||
|
||||
test('markdown file exists for every operationId prefix in the api.github.com schema', async () => {
|
||||
const { categories } = require('../../lib/rest')
|
||||
const { categories } = rest
|
||||
const referenceDir = path.join(__dirname, '../../content/rest/reference')
|
||||
const filenames = (await fs.readdir(referenceDir))
|
||||
.filter(filename => !excludeFromResourceNameCheck.find(excludedFile => filename.endsWith(excludedFile)))
|
||||
@@ -47,7 +48,7 @@ describe('REST references docs', () => {
|
||||
})
|
||||
|
||||
test('no wrongly detected AppleScript syntax highlighting in schema data', async () => {
|
||||
const { operations } = require('../../lib/rest')
|
||||
const { operations } = rest
|
||||
expect(JSON.stringify(operations).includes('hljs language-applescript')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ const path = require('path')
|
||||
const { loadPages } = require('../../lib/page-data')
|
||||
const builtAssets = require('../../lib/built-asset-urls')
|
||||
const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
|
||||
const CspParse = require('csp-parse')
|
||||
|
||||
describe('server', () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
@@ -39,7 +40,7 @@ describe('server', () => {
|
||||
const res = await get('/en')
|
||||
expect('content-security-policy' in res.headers).toBe(true)
|
||||
|
||||
const csp = new (require('csp-parse'))(res.headers['content-security-policy'])
|
||||
const csp = new CspParse(res.headers['content-security-policy'])
|
||||
expect(csp.get('default-src')).toBe("'none'")
|
||||
|
||||
expect(csp.get('font-src').includes("'self'")).toBe(true)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { head } = require('../helpers/supertest')
|
||||
const topOldDeveloperSitePaths = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'tests/fixtures/top-old-developer-site-paths.json')))
|
||||
|
||||
describe('developer.github.com redirects', () => {
|
||||
jest.setTimeout(30 * 60 * 1000)
|
||||
@@ -16,7 +19,7 @@ describe('developer.github.com redirects', () => {
|
||||
|
||||
// test a subset of the top paths
|
||||
const pathsToCheck = 50
|
||||
const paths = require('../fixtures/top-old-developer-site-paths.json')
|
||||
const paths = topOldDeveloperSitePaths
|
||||
.filter(path => !ignoredPatterns.some(pattern => path.match(pattern)))
|
||||
.slice(0, pathsToCheck)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const { liquid } = require('../../lib/render-content')
|
||||
const { loadPageMap } = require('../../lib/page-data')
|
||||
const entities = new (require('html-entities').XmlEntities)()
|
||||
const htmlEntities = require('html-entities')
|
||||
const entities = new htmlEntities.XmlEntities()
|
||||
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
|
||||
|
||||
describe('liquid helper tags', () => {
|
||||
|
||||
Reference in New Issue
Block a user