Files
next.js/scripts/validate-externals-doc.js
T
Delba de OliveiraandGitHub 0b35ddd825 Docs: Move next.config.js API pages under a config folder, fix headings in TS and ESLint config pages (#72465)
This PR:

- Moves `next.config.js` options under a "config" folder which includes
references for other configuration such as the ESLint plugin. I figure
it would be tidier than having "Next.config.js Options" and "Config" in
the API reference.
- Fixes the issue with the "config" folder not showing up in canary:
https://linear.app/vercel/issue/DOC-3749/bug-figure-out-why-new-config-folder-isnt-showing-up-in-the-canary
- Fixes the indentation issues and missing example header (caused by an
invisible character).

Redirects: https://github.com/vercel/front/pull/38704
2024-11-08 14:48:55 +00:00

70 lines
1.5 KiB
JavaScript

const fs = require('fs')
const path = require('path')
const serverExternals = require('../packages/next/src/lib/server-external-packages.json')
function validate(docPath) {
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('| Version')
.shift()
.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}`
)
return false
}
return true
}
const appRouterValid = validate(
`docs/01-app/03-api-reference/05-config/01-next-config-js/serverExternalPackages.mdx`
)
const pagesRouterValid = validate(
`docs/02-pages/03-api-reference/04-config/01-next-config-js/serverExternalPackages.mdx`
)
if (appRouterValid && pagesRouterValid) {
console.log('server externals doc is in sync')
process.exit(0)
} else {
process.exit(1)
}