mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 11:07:07 +02:00
refactor: remove deprecated Webpack utils & validation escape hatch (#6740)
This commit is contained in:
parent
051380aa4b
commit
9562a5d203
8 changed files with 7 additions and 90 deletions
12
packages/docusaurus-types/src/index.d.ts
vendored
12
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -392,18 +392,6 @@ export interface ConfigureWebpackUtils {
|
||||||
isServer: boolean;
|
isServer: boolean;
|
||||||
babelOptions?: Record<string, unknown>;
|
babelOptions?: Record<string, unknown>;
|
||||||
}) => RuleSetRule;
|
}) => RuleSetRule;
|
||||||
|
|
||||||
// TODO deprecated: remove before end of 2021?
|
|
||||||
getCacheLoader: (
|
|
||||||
isServer: boolean,
|
|
||||||
cacheOptions?: Record<string, unknown>,
|
|
||||||
) => RuleSetRule | null;
|
|
||||||
|
|
||||||
// TODO deprecated: remove before end of 2021?
|
|
||||||
getBabelLoader: (
|
|
||||||
isServer: boolean,
|
|
||||||
options?: Record<string, unknown>,
|
|
||||||
) => RuleSetRule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HtmlTagObject {
|
interface HtmlTagObject {
|
||||||
|
|
|
@ -10,8 +10,6 @@ export {default as Joi} from './Joi';
|
||||||
export {JoiFrontMatter} from './JoiFrontMatter';
|
export {JoiFrontMatter} from './JoiFrontMatter';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
isValidationDisabledEscapeHatch,
|
|
||||||
logValidationBugReportHint,
|
|
||||||
printWarning,
|
printWarning,
|
||||||
normalizePluginOptions,
|
normalizePluginOptions,
|
||||||
normalizeThemeConfig,
|
normalizeThemeConfig,
|
||||||
|
|
|
@ -9,26 +9,6 @@ import type Joi from './Joi';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import {PluginIdSchema} from './validationSchemas';
|
import {PluginIdSchema} from './validationSchemas';
|
||||||
|
|
||||||
// TODO temporary escape hatch for alpha-60: to be removed soon
|
|
||||||
// Our validation schemas might be buggy at first
|
|
||||||
// will permit users to bypass validation until we fix all validation errors
|
|
||||||
// see for example: https://github.com/facebook/docusaurus/pull/3120
|
|
||||||
// Undocumented on purpose, as we don't want users to keep using it over time
|
|
||||||
// Maybe we'll make this escape hatch official some day, with a better api?
|
|
||||||
export const isValidationDisabledEscapeHatch =
|
|
||||||
process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
|
|
||||||
|
|
||||||
if (isValidationDisabledEscapeHatch) {
|
|
||||||
logger.error`You should avoid using code=${'DISABLE_DOCUSAURUS_VALIDATION'} escape hatch, this will be removed.`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const logValidationBugReportHint = (): void => {
|
|
||||||
logger.error('A validation error occurred.');
|
|
||||||
logger.info(`The validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.
|
|
||||||
We may have made some mistakes.
|
|
||||||
If you think your configuration is valid and should keep working, please open a bug report.`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export function printWarning(warning?: Joi.ValidationError): void {
|
export function printWarning(warning?: Joi.ValidationError): void {
|
||||||
if (warning) {
|
if (warning) {
|
||||||
const warningMessages = warning.details
|
const warningMessages = warning.details
|
||||||
|
@ -54,11 +34,6 @@ export function normalizePluginOptions<T extends {id?: string}>(
|
||||||
printWarning(warning);
|
printWarning(warning);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
logValidationBugReportHint();
|
|
||||||
if (isValidationDisabledEscapeHatch) {
|
|
||||||
logger.error(error);
|
|
||||||
return options as T;
|
|
||||||
}
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +56,6 @@ export function normalizeThemeConfig<T>(
|
||||||
printWarning(warning);
|
printWarning(warning);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
logValidationBugReportHint();
|
|
||||||
if (isValidationDisabledEscapeHatch) {
|
|
||||||
logger.error(error);
|
|
||||||
return themeConfig as T;
|
|
||||||
}
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
return value!; // TODO remove this ! in TS 4.6
|
return value!; // TODO remove this ! in TS 4.6
|
||||||
|
@ -108,8 +78,6 @@ export function validateFrontMatter<T>(
|
||||||
const errorDetails = error.details;
|
const errorDetails = error.details;
|
||||||
const invalidFields = errorDetails.map(({path}) => path).join(', ');
|
const invalidFields = errorDetails.map(({path}) => path).join(', ');
|
||||||
|
|
||||||
logValidationBugReportHint();
|
|
||||||
|
|
||||||
logger.error`The following front matter:
|
logger.error`The following front matter:
|
||||||
${logger.yellow(frontMatterString)}
|
${logger.yellow(frontMatterString)}
|
||||||
contains invalid values for field(s): ${logger.yellow(invalidFields)}.
|
contains invalid values for field(s): ${logger.yellow(invalidFields)}.
|
||||||
|
|
|
@ -5,16 +5,9 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import logger from '@docusaurus/logger';
|
|
||||||
import type {DocusaurusConfig, I18nConfig} from '@docusaurus/types';
|
import type {DocusaurusConfig, I18nConfig} from '@docusaurus/types';
|
||||||
import {DEFAULT_CONFIG_FILE_NAME, STATIC_DIR_NAME} from '@docusaurus/utils';
|
import {DEFAULT_CONFIG_FILE_NAME, STATIC_DIR_NAME} from '@docusaurus/utils';
|
||||||
import {
|
import {Joi, URISchema, printWarning} from '@docusaurus/utils-validation';
|
||||||
Joi,
|
|
||||||
logValidationBugReportHint,
|
|
||||||
isValidationDisabledEscapeHatch,
|
|
||||||
URISchema,
|
|
||||||
printWarning,
|
|
||||||
} from '@docusaurus/utils-validation';
|
|
||||||
|
|
||||||
const DEFAULT_I18N_LOCALE = 'en';
|
const DEFAULT_I18N_LOCALE = 'en';
|
||||||
|
|
||||||
|
@ -218,12 +211,6 @@ export function validateConfig(
|
||||||
printWarning(warning);
|
printWarning(warning);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
logValidationBugReportHint();
|
|
||||||
if (isValidationDisabledEscapeHatch) {
|
|
||||||
logger.error(error.message);
|
|
||||||
return config as DocusaurusConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unknownFields = error.details.reduce((formattedError, err) => {
|
const unknownFields = error.details.reduce((formattedError, err) => {
|
||||||
if (err.type === 'object.unknown') {
|
if (err.type === 'object.unknown') {
|
||||||
return `${formattedError}"${err.path}",`;
|
return `${formattedError}"${err.path}",`;
|
||||||
|
|
|
@ -31,7 +31,6 @@ import type {
|
||||||
ConfigureWebpackUtils,
|
ConfigureWebpackUtils,
|
||||||
} from '@docusaurus/types';
|
} from '@docusaurus/types';
|
||||||
import {BABEL_CONFIG_FILE_NAME} from '@docusaurus/utils';
|
import {BABEL_CONFIG_FILE_NAME} from '@docusaurus/utils';
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
// Utility method to get style loaders
|
// Utility method to get style loaders
|
||||||
export function getStyleLoaders(
|
export function getStyleLoaders(
|
||||||
|
@ -163,27 +162,6 @@ export const getCustomizableJSLoader =
|
||||||
? getDefaultBabelLoader({isServer, babelOptions})
|
? getDefaultBabelLoader({isServer, babelOptions})
|
||||||
: jsLoader(isServer);
|
: jsLoader(isServer);
|
||||||
|
|
||||||
// TODO remove this before end of 2021?
|
|
||||||
const warnBabelLoaderOnce = _.memoize(() => {
|
|
||||||
logger.warn`Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): code=${'getBabelLoader(isServer)'} is now deprecated in favor of code=${'getJSLoader(isServer)'}.`;
|
|
||||||
});
|
|
||||||
const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(
|
|
||||||
isServer: boolean,
|
|
||||||
babelOptions?: TransformOptions | string,
|
|
||||||
) {
|
|
||||||
warnBabelLoaderOnce();
|
|
||||||
return getDefaultBabelLoader({isServer, babelOptions});
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO remove this before end of 2021 ?
|
|
||||||
const warnCacheLoaderOnce = _.memoize(() => {
|
|
||||||
logger.warn`Docusaurus uses Webpack 5 and code=${'getCacheLoader()'} usage is now deprecated.`;
|
|
||||||
});
|
|
||||||
function getCacheLoaderDeprecated() {
|
|
||||||
warnCacheLoaderOnce();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to modify webpack config
|
* Helper function to modify webpack config
|
||||||
* @param configureWebpack a webpack config or a function to modify config
|
* @param configureWebpack a webpack config or a function to modify config
|
||||||
|
@ -204,8 +182,6 @@ export function applyConfigureWebpack(
|
||||||
const utils: ConfigureWebpackUtils = {
|
const utils: ConfigureWebpackUtils = {
|
||||||
getStyleLoaders,
|
getStyleLoaders,
|
||||||
getJSLoader: getCustomizableJSLoader(jsLoader),
|
getJSLoader: getCustomizableJSLoader(jsLoader),
|
||||||
getBabelLoader: getBabelLoaderDeprecated,
|
|
||||||
getCacheLoader: getCacheLoaderDeprecated,
|
|
||||||
};
|
};
|
||||||
if (typeof configureWebpack === 'function') {
|
if (typeof configureWebpack === 'function') {
|
||||||
const {mergeStrategy, ...res} = configureWebpack(
|
const {mergeStrategy, ...res} = configureWebpack(
|
||||||
|
|
|
@ -188,13 +188,13 @@ module.exports = function (context, options) {
|
||||||
name: 'custom-docusaurus-plugin',
|
name: 'custom-docusaurus-plugin',
|
||||||
// highlight-start
|
// highlight-start
|
||||||
configureWebpack(config, isServer, utils) {
|
configureWebpack(config, isServer, utils) {
|
||||||
const {getCacheLoader} = utils;
|
const {getJSLoader} = utils;
|
||||||
return {
|
return {
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.foo$/,
|
test: /\.foo$/,
|
||||||
use: [getCacheLoader(isServer), 'my-custom-webpack-loader'],
|
use: [getJSLoader(isServer), 'my-custom-webpack-loader'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -182,13 +182,13 @@ module.exports = function (context, options) {
|
||||||
name: 'custom-docusaurus-plugin',
|
name: 'custom-docusaurus-plugin',
|
||||||
// highlight-start
|
// highlight-start
|
||||||
configureWebpack(config, isServer, utils) {
|
configureWebpack(config, isServer, utils) {
|
||||||
const {getCacheLoader} = utils;
|
const {getJSLoader} = utils;
|
||||||
return {
|
return {
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.foo$/,
|
test: /\.foo$/,
|
||||||
use: [getCacheLoader(isServer), 'my-custom-webpack-loader'],
|
use: [getJSLoader(isServer), 'my-custom-webpack-loader'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -188,13 +188,13 @@ module.exports = function (context, options) {
|
||||||
name: 'custom-docusaurus-plugin',
|
name: 'custom-docusaurus-plugin',
|
||||||
// highlight-start
|
// highlight-start
|
||||||
configureWebpack(config, isServer, utils) {
|
configureWebpack(config, isServer, utils) {
|
||||||
const {getCacheLoader} = utils;
|
const {getJSLoader} = utils;
|
||||||
return {
|
return {
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.foo$/,
|
test: /\.foo$/,
|
||||||
use: [getCacheLoader(isServer), 'my-custom-webpack-loader'],
|
use: [getJSLoader(isServer), 'my-custom-webpack-loader'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue