diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts index e1ad88e567..bb1cf4ef43 100644 --- a/packages/docusaurus/src/commands/build.ts +++ b/packages/docusaurus/src/commands/build.ts @@ -206,11 +206,7 @@ async function buildLocale({ await compile([clientConfig, serverConfig]); // Remove server.bundle.js because it is not needed. - if ( - serverConfig.output && - serverConfig.output.filename && - typeof serverConfig.output.filename === 'string' - ) { + if (typeof serverConfig.output?.filename === 'string') { const serverBundle = path.join(outDir, serverConfig.output.filename); if (await fs.pathExists(serverBundle)) { await fs.unlink(serverBundle); diff --git a/packages/docusaurus/src/server/__tests__/i18n.test.ts b/packages/docusaurus/src/server/__tests__/i18n.test.ts index 5d65a521f8..a78e5fbf3f 100644 --- a/packages/docusaurus/src/server/__tests__/i18n.test.ts +++ b/packages/docusaurus/src/server/__tests__/i18n.test.ts @@ -5,12 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import { - loadI18n, - localizePath, - getDefaultLocaleConfig, - shouldWarnAboutNodeVersion, -} from '../i18n'; +import {loadI18n, localizePath, getDefaultLocaleConfig} from '../i18n'; import {DEFAULT_I18N_CONFIG} from '../configValidation'; import path from 'path'; import type {I18nConfig} from '@docusaurus/types'; @@ -83,20 +78,6 @@ describe('defaultLocaleConfig', () => { }); }); -describe('shouldWarnAboutNodeVersion', () => { - test('warns for old NodeJS version and [en,fr]', () => { - expect(shouldWarnAboutNodeVersion(12, ['en', 'fr'])).toEqual(true); - }); - - test('not warn for old NodeJS version and [en]', () => { - expect(shouldWarnAboutNodeVersion(12, ['en'])).toEqual(false); - }); - - test('not warn for recent NodeJS version and [en,fr]', () => { - expect(shouldWarnAboutNodeVersion(14, ['en', 'fr'])).toEqual(false); - }); -}); - describe('loadI18n', () => { const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(); beforeEach(() => { @@ -215,7 +196,7 @@ describe('localizePath', () => { }, options: {localizePath: true}, }), - ).toEqual(`${path.sep}baseFsPath${path.sep}fr${path.sep}`); + ).toEqual(`${path.sep}baseFsPath${path.sep}fr`); }); test('should localize path for default locale, if requested', () => { diff --git a/packages/docusaurus/src/server/i18n.ts b/packages/docusaurus/src/server/i18n.ts index 1885b3f47f..26739b4158 100644 --- a/packages/docusaurus/src/server/i18n.ts +++ b/packages/docusaurus/src/server/i18n.ts @@ -28,15 +28,6 @@ export function getDefaultLocaleConfig(locale: string): I18nLocaleConfig { }; } -export function shouldWarnAboutNodeVersion( - version: number, - locales: string[], -): boolean { - const isOnlyEnglish = locales.length === 1 && locales.includes('en'); - const isOlderNodeVersion = version < 14; - return isOlderNodeVersion && !isOnlyEnglish; -} - export async function loadI18n( config: DocusaurusConfig, options: {locale?: string} = {}, @@ -86,21 +77,19 @@ export function localizePath({ options?: {localizePath?: boolean}; }): string { const shouldLocalizePath: boolean = - typeof options.localizePath === 'undefined' - ? // By default, we don't localize the path of defaultLocale - i18n.currentLocale !== i18n.defaultLocale - : options.localizePath; + // By default, we don't localize the path of defaultLocale + options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale; if (!shouldLocalizePath) { return originalPath; } // FS paths need special care, for Windows support if (pathType === 'fs') { - return path.join(originalPath, path.sep, i18n.currentLocale, path.sep); + return path.join(originalPath, i18n.currentLocale); } - // Url paths + // Url paths; add a trailing slash so it's a valid base URL if (pathType === 'url') { - return normalizeUrl([originalPath, '/', i18n.currentLocale, '/']); + return normalizeUrl([originalPath, i18n.currentLocale, '/']); } // should never happen throw new Error(`Unhandled path type "${pathType}".`);