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

feat: Throw exception on version mismatch #9380

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/docusaurus/src/server/siteMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function getPluginVersion(
*/
function checkDocusaurusPackagesVersion(siteMetadata: SiteMetadata) {
const {docusaurusVersion} = siteMetadata;
let mismatchDetected: boolean = false;
Object.entries(siteMetadata.pluginVersions).forEach(
([plugin, versionInfo]) => {
if (
Expand All @@ -82,13 +83,21 @@ function checkDocusaurusPackagesVersion(siteMetadata: SiteMetadata) {
versionInfo.version &&
versionInfo.version !== docusaurusVersion
) {
// change mismatched to true
mismatchDetected = true;
// Should we throw instead? It still could work with different versions
logger.error`Invalid name=${plugin} version number=${versionInfo.version}.
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
}
},
);
if (mismatchDetected) {
// Throw an exception or exit with a non-zero exit code.
throw new Error('Docusaurus plugin versions mismatch detected.');
// We can exit the process with a non-zero code:
// process.exit(1);
}
}

export async function loadSiteMetadata({
Expand Down