mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-31 23:40:39 +02:00
refactor: remove "error" reporting level, move reportMessage to logger (#7642)
This commit is contained in:
parent
1b9bec1042
commit
bfba6a8b02
16 changed files with 117 additions and 116 deletions
|
@ -161,3 +161,8 @@ exports[`normalizeConfig throws error for unknown field 1`] = `
|
|||
If you still want these fields to be in your configuration, put them in the "customFields" field.
|
||||
See https://docusaurus.io/docs/api/docusaurus-config/#customfields"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws for "error" reporting severity 1`] = `
|
||||
""onBrokenLinks" must be one of [ignore, log, warn, throw]
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -308,6 +308,20 @@ describe('normalizeConfig', () => {
|
|||
),
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
it('throws for "error" reporting severity', () => {
|
||||
expect(() =>
|
||||
validateConfig(
|
||||
{
|
||||
title: 'Site',
|
||||
url: 'https://example.com',
|
||||
baseUrl: '/',
|
||||
onBrokenLinks: 'error',
|
||||
},
|
||||
'docusaurus.config.js',
|
||||
),
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('config warnings', () => {
|
||||
|
|
|
@ -11,12 +11,7 @@ import _ from 'lodash';
|
|||
import logger from '@docusaurus/logger';
|
||||
import combinePromises from 'combine-promises';
|
||||
import {matchRoutes} from 'react-router-config';
|
||||
import {
|
||||
removePrefix,
|
||||
removeSuffix,
|
||||
reportMessage,
|
||||
resolvePathname,
|
||||
} from '@docusaurus/utils';
|
||||
import {removePrefix, removeSuffix, resolvePathname} from '@docusaurus/utils';
|
||||
import {getAllFinalRoutes} from './utils';
|
||||
import type {RouteConfig, ReportingSeverity} from '@docusaurus/types';
|
||||
|
||||
|
@ -247,6 +242,6 @@ export async function handleBrokenLinks({
|
|||
|
||||
const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
|
||||
if (errorMessage) {
|
||||
reportMessage(errorMessage, onBrokenLinks);
|
||||
logger.report(onBrokenLinks)(errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,13 +174,13 @@ export const ConfigSchema = Joi.object<DocusaurusConfig>({
|
|||
trailingSlash: Joi.boolean(), // No default value! undefined = retrocompatible legacy behavior!
|
||||
i18n: I18N_CONFIG_SCHEMA,
|
||||
onBrokenLinks: Joi.string()
|
||||
.equal('ignore', 'log', 'warn', 'error', 'throw')
|
||||
.equal('ignore', 'log', 'warn', 'throw')
|
||||
.default(DEFAULT_CONFIG.onBrokenLinks),
|
||||
onBrokenMarkdownLinks: Joi.string()
|
||||
.equal('ignore', 'log', 'warn', 'error', 'throw')
|
||||
.equal('ignore', 'log', 'warn', 'throw')
|
||||
.default(DEFAULT_CONFIG.onBrokenMarkdownLinks),
|
||||
onDuplicateRoutes: Joi.string()
|
||||
.equal('ignore', 'log', 'warn', 'error', 'throw')
|
||||
.equal('ignore', 'log', 'warn', 'throw')
|
||||
.default(DEFAULT_CONFIG.onDuplicateRoutes),
|
||||
organizationName: Joi.string().allow(''),
|
||||
staticDirectories: Joi.array()
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
import query from 'querystring';
|
||||
import _ from 'lodash';
|
||||
import logger from '@docusaurus/logger';
|
||||
import {
|
||||
docuHash,
|
||||
normalizeUrl,
|
||||
simpleHash,
|
||||
escapePath,
|
||||
reportMessage,
|
||||
} from '@docusaurus/utils';
|
||||
import {getAllFinalRoutes} from './utils';
|
||||
import type {
|
||||
|
@ -228,15 +228,13 @@ export function handleDuplicateRoutes(
|
|||
return false;
|
||||
});
|
||||
if (duplicatePaths.length > 0) {
|
||||
const finalMessage = `Duplicate routes found!
|
||||
${duplicatePaths
|
||||
.map(
|
||||
(duplicateRoute) =>
|
||||
`- Attempting to create page at ${duplicateRoute}, but a page already exists at this route.`,
|
||||
)
|
||||
.join('\n')}
|
||||
logger.report(
|
||||
onDuplicateRoutes,
|
||||
)`Duplicate routes found!${duplicatePaths.map(
|
||||
(duplicateRoute) =>
|
||||
logger.interpolate`Attempting to create page at url=${duplicateRoute}, but a page already exists at this route.`,
|
||||
)}
|
||||
This could lead to non-deterministic routing behavior.`;
|
||||
reportMessage(finalMessage, onDuplicateRoutes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue