mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 11:22:30 +02:00
feat(core): throw error when official docusaurus dependencies use different versions (#9381)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
dceaae41d7
commit
1319996083
3 changed files with 8 additions and 30 deletions
|
@ -1,15 +0,0 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`loadSiteMetadata warns about plugin version mismatch 1`] = `
|
|
||||||
{
|
|
||||||
"docusaurusVersion": "<CURRENT_VERSION>",
|
|
||||||
"pluginVersions": {
|
|
||||||
"docusaurus-plugin-content-docs": {
|
|
||||||
"name": "@docusaurus/plugin-content-docs",
|
|
||||||
"type": "package",
|
|
||||||
"version": "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"siteVersion": "random-version",
|
|
||||||
}
|
|
||||||
`;
|
|
|
@ -5,8 +5,8 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {jest} from '@jest/globals';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
||||||
import {getPluginVersion, loadSiteMetadata} from '../siteMetadata';
|
import {getPluginVersion, loadSiteMetadata} from '../siteMetadata';
|
||||||
import type {LoadedPlugin} from '@docusaurus/types';
|
import type {LoadedPlugin} from '@docusaurus/types';
|
||||||
|
|
||||||
|
@ -37,10 +37,7 @@ describe('getPluginVersion', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('loadSiteMetadata', () => {
|
describe('loadSiteMetadata', () => {
|
||||||
it('warns about plugin version mismatch', async () => {
|
it('throws if plugin versions mismatch', async () => {
|
||||||
const consoleMock = jest
|
|
||||||
.spyOn(console, 'error')
|
|
||||||
.mockImplementation(() => {});
|
|
||||||
await expect(
|
await expect(
|
||||||
loadSiteMetadata({
|
loadSiteMetadata({
|
||||||
plugins: [
|
plugins: [
|
||||||
|
@ -55,11 +52,9 @@ describe('loadSiteMetadata', () => {
|
||||||
] as LoadedPlugin[],
|
] as LoadedPlugin[],
|
||||||
siteDir: path.join(__dirname, '__fixtures__/siteMetadata'),
|
siteDir: path.join(__dirname, '__fixtures__/siteMetadata'),
|
||||||
}),
|
}),
|
||||||
).resolves.toMatchSnapshot();
|
).rejects
|
||||||
expect(consoleMock.mock.calls[0]![0]).toMatchInlineSnapshot(`
|
.toThrow(`Invalid name=docusaurus-plugin-content-docs version number=1.0.0.
|
||||||
"[ERROR] Invalid docusaurus-plugin-content-docs version 1.0.0.
|
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${DOCUSAURUS_VERSION}).
|
||||||
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?`);
|
||||||
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?"
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import logger from '@docusaurus/logger';
|
|
||||||
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
||||||
import type {
|
import type {
|
||||||
LoadedPlugin,
|
LoadedPlugin,
|
||||||
|
@ -82,10 +81,9 @@ function checkDocusaurusPackagesVersion(siteMetadata: SiteMetadata) {
|
||||||
versionInfo.version &&
|
versionInfo.version &&
|
||||||
versionInfo.version !== docusaurusVersion
|
versionInfo.version !== docusaurusVersion
|
||||||
) {
|
) {
|
||||||
// Should we throw instead? It still could work with different versions
|
throw new Error(`Invalid name=${plugin} version number=${versionInfo.version}.
|
||||||
logger.error`Invalid name=${plugin} version number=${versionInfo.version}.
|
|
||||||
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
|
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?`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue