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(core): throw error when official docusaurus dependencies use different versions #9381

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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

This file was deleted.

17 changes: 6 additions & 11 deletions packages/docusaurus/src/server/__tests__/siteMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
import {getPluginVersion, loadSiteMetadata} from '../siteMetadata';
import type {LoadedPlugin} from '@docusaurus/types';

Expand Down Expand Up @@ -37,10 +37,7 @@ describe('getPluginVersion', () => {
});

describe('loadSiteMetadata', () => {
it('warns about plugin version mismatch', async () => {
const consoleMock = jest
.spyOn(console, 'error')
.mockImplementation(() => {});
it('throws if plugin versions mismatch', async () => {
await expect(
loadSiteMetadata({
plugins: [
Expand All @@ -55,11 +52,9 @@ describe('loadSiteMetadata', () => {
] as LoadedPlugin[],
siteDir: path.join(__dirname, '__fixtures__/siteMetadata'),
}),
).resolves.toMatchSnapshot();
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 (<CURRENT_VERSION>).
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?"
`);
).rejects
.toThrow(`Invalid name=docusaurus-plugin-content-docs version number=1.0.0.
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${DOCUSAURUS_VERSION}).
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
});
});
6 changes: 2 additions & 4 deletions packages/docusaurus/src/server/siteMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import fs from 'fs-extra';
import path from 'path';
import logger from '@docusaurus/logger';
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
import type {
LoadedPlugin,
Expand Down Expand Up @@ -82,10 +81,9 @@ function checkDocusaurusPackagesVersion(siteMetadata: SiteMetadata) {
versionInfo.version &&
versionInfo.version !== docusaurusVersion
) {
// Should we throw instead? It still could work with different versions
logger.error`Invalid name=${plugin} version number=${versionInfo.version}.
throw new 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?`;
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
}
},
);
Expand Down
Loading