fix(preset-classic): throw if preset finds GA options in theme config (#6284)

* fix(preset-classic): throw if preset finds GA options in theme config

* revert

* stricter
This commit is contained in:
Joshua Chen 2022-01-07 12:50:45 +08:00 committed by GitHub
parent e231359f84
commit 37a84f86a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View file

@ -82,7 +82,7 @@ export function validateOptions({
export function validateThemeConfig({ export function validateThemeConfig({
themeConfig, themeConfig,
}: ThemeConfigValidationContext<ThemeConfig>): ValidationResult<ThemeConfig> { }: ThemeConfigValidationContext<ThemeConfig>): ValidationResult<ThemeConfig> {
if (themeConfig.googleAnalytics) { if ('googleAnalytics' in themeConfig) {
throw new Error( throw new Error(
'The "googleAnalytics" field in themeConfig should now be specified as option for plugin-google-analytics. More information at https://github.com/facebook/docusaurus/pull/5832.', 'The "googleAnalytics" field in themeConfig should now be specified as option for plugin-google-analytics. More information at https://github.com/facebook/docusaurus/pull/5832.',
); );

View file

@ -95,7 +95,7 @@ export function validateOptions({
export function validateThemeConfig({ export function validateThemeConfig({
themeConfig, themeConfig,
}: ThemeConfigValidationContext<ThemeConfig>): ValidationResult<ThemeConfig> { }: ThemeConfigValidationContext<ThemeConfig>): ValidationResult<ThemeConfig> {
if (themeConfig.gtag) { if ('gtag' in themeConfig) {
throw new Error( throw new Error(
'The "gtag" field in themeConfig should now be specified as option for plugin-google-gtag. More information at https://github.com/facebook/docusaurus/pull/5832.', 'The "gtag" field in themeConfig should now be specified as option for plugin-google-gtag. More information at https://github.com/facebook/docusaurus/pull/5832.',
); );

View file

@ -48,6 +48,16 @@ export default function preset(
if (algolia) { if (algolia) {
themes.push(require.resolve('@docusaurus/theme-search-algolia')); themes.push(require.resolve('@docusaurus/theme-search-algolia'));
} }
if ('gtag' in themeConfig) {
throw new Error(
'The "gtag" field in themeConfig should now be specified as option for plugin-google-gtag. For preset-classic, simply move themeConfig.gtag to preset options. More information at https://github.com/facebook/docusaurus/pull/5832.',
);
}
if ('googleAnalytics' in themeConfig) {
throw new Error(
'The "googleAnalytics" field in themeConfig should now be specified as option for plugin-google-analytics. For preset-classic, simply move themeConfig.googleAnalytics to preset options. More information at https://github.com/facebook/docusaurus/pull/5832.',
);
}
const plugins: PluginConfig[] = []; const plugins: PluginConfig[] = [];
if (docs !== false) { if (docs !== false) {
@ -59,7 +69,7 @@ export default function preset(
if (pages !== false) { if (pages !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-content-pages', pages)); plugins.push(makePluginConfig('@docusaurus/plugin-content-pages', pages));
} }
if (isProd && googleAnalytics) { if (googleAnalytics) {
plugins.push( plugins.push(
makePluginConfig('@docusaurus/plugin-google-analytics', googleAnalytics), makePluginConfig('@docusaurus/plugin-google-analytics', googleAnalytics),
); );
@ -67,7 +77,7 @@ export default function preset(
if (debug || (debug === undefined && !isProd)) { if (debug || (debug === undefined && !isProd)) {
plugins.push(require.resolve('@docusaurus/plugin-debug')); plugins.push(require.resolve('@docusaurus/plugin-debug'));
} }
if (isProd && gtag) { if (gtag) {
plugins.push(makePluginConfig('@docusaurus/plugin-google-gtag', gtag)); plugins.push(makePluginConfig('@docusaurus/plugin-google-gtag', gtag));
} }
if (isProd && sitemap !== false) { if (isProd && sitemap !== false) {