Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI check to validate externals doc #62968

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"lint-typescript": "turbo run typescript",
"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",
"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-fix": "pnpm prettier-fix && eslint . --ext js,jsx,ts,tsx --fix --max-warnings=0 --config .eslintrc.json --no-eslintrc",
"lint-language": "alex .",
Expand Down
45 changes: 45 additions & 0 deletions scripts/validate-externals-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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')