-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #62966 Closes NEXT-2734
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |