From c2abc3bb64b98101392bdbc08a6dab79b60cb538 Mon Sep 17 00:00:00 2001 From: Shubhankarsingh124 <31387840+shubhankar-mern@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:02:27 +0000 Subject: [PATCH 1/2] feat: Throw exception on version mismatch --- packages/docusaurus/src/server/siteMetadata.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/docusaurus/src/server/siteMetadata.ts b/packages/docusaurus/src/server/siteMetadata.ts index affcbf7183ec..96787c5f43bd 100644 --- a/packages/docusaurus/src/server/siteMetadata.ts +++ b/packages/docusaurus/src/server/siteMetadata.ts @@ -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 ( @@ -82,6 +83,8 @@ 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}). @@ -89,6 +92,12 @@ 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({ From 3ff466206d1b2b92c205eb48dd87b25775ed0509 Mon Sep 17 00:00:00 2001 From: Shubhankarsingh124 <31387840+shubhankar-mern@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:18:01 +0000 Subject: [PATCH 2/2] eaft added the test cases for version mismatch --- packages/docusaurus/src/server/__tests__/siteMetadata.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts b/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts index 3985173a03b8..4b1271c76757 100644 --- a/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts +++ b/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts @@ -55,7 +55,7 @@ describe('loadSiteMetadata', () => { ] as LoadedPlugin[], siteDir: path.join(__dirname, '__fixtures__/siteMetadata'), }), - ).resolves.toMatchSnapshot(); + ).rejects.toThrow('Docusaurus plugin versions mismatch detected.'); expect(consoleMock.mock.calls[0]![0]).toMatchInlineSnapshot(` "[ERROR] Invalid docusaurus-plugin-content-docs version 1.0.0. All official @docusaurus/* packages should have the exact same version as @docusaurus/core ().