Skip to content

Commit

Permalink
Add CI check to validate externals doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Mar 7, 2024
1 parent 6b111ec commit 9efad0e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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')

0 comments on commit 9efad0e

Please sign in to comment.