Unverified Commit 80fa841c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add CI check to validate externals doc (#62968)

This avoids the need to manually check when these get out of sync by
having an automated check to keep them in sync when one or the other is
updated.

x-ref: https://github.com/vercel/next.js/pull/62966

Closes NEXT-2734
parent 6b111ec6
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
"lint-typescript": "turbo run typescript", "lint-typescript": "turbo run typescript",
"lint-eslint": "eslint . --ext js,jsx,ts,tsx --max-warnings=0 --config .eslintrc.json --no-eslintrc", "lint-eslint": "eslint . --ext js,jsx,ts,tsx --max-warnings=0 --config .eslintrc.json --no-eslintrc",
"lint-no-typescript": "run-p prettier-check lint-eslint lint-language", "lint-no-typescript": "run-p prettier-check lint-eslint lint-language",
"types-and-precompiled": "run-p lint-typescript check-precompiled", "types-and-precompiled": "run-p lint-typescript check-precompiled validate-externals-doc",
"validate-externals-doc": "node ./scripts/validate-externals-doc.js",
"lint": "run-p test-types lint-typescript prettier-check lint-eslint lint-language", "lint": "run-p test-types lint-typescript prettier-check lint-eslint lint-language",
"lint-fix": "pnpm prettier-fix && eslint . --ext js,jsx,ts,tsx --fix --max-warnings=0 --config .eslintrc.json --no-eslintrc", "lint-fix": "pnpm prettier-fix && eslint . --ext js,jsx,ts,tsx --fix --max-warnings=0 --config .eslintrc.json --no-eslintrc",
"lint-language": "alex .", "lint-language": "alex .",
......
const fs = require('fs')
const path = require('path')
const serverExternals = require('../packages/next/src/lib/server-external-packages.json')
const docPath = `docs/02-app/02-api-reference/05-next-config-js/serverComponentsExternalPackages.mdx`
const docContent = fs.readFileSync(path.join(__dirname, '..', docPath), 'utf8')
const docPkgs = []
const extraPkgs = []
const missingPkgs = []
for (let docPkg of docContent.split('opt-ed out:').pop().split('\n')) {
docPkg = docPkg.split('`')[1]
if (!docPkg) {
continue
}
docPkgs.push(docPkg)
if (!serverExternals.includes(docPkg)) {
extraPkgs.push(docPkg)
}
}
for (const pkg of serverExternals) {
if (!docPkgs.includes(pkg)) {
missingPkgs.push(pkg)
}
}
if (extraPkgs.length || missingPkgs.length) {
console.log(
'server externals doc out of sync!\n' +
`Extra packages included: ` +
JSON.stringify(extraPkgs, null, 2) +
'\n' +
`Missing packages: ` +
JSON.stringify(missingPkgs, null, 2) +
'\n' +
`doc path: ${docPath}`
)
process.exit(1)
}
console.log('server externals doc is in sync')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment