diff --git a/packages/docusaurus/src/commands/build/build.ts b/packages/docusaurus/src/commands/build/build.ts index d05441b07480..d0334e34bf80 100644 --- a/packages/docusaurus/src/commands/build/build.ts +++ b/packages/docusaurus/src/commands/build/build.ts @@ -10,7 +10,7 @@ import logger, {PerfLogger} from '@docusaurus/logger'; import {mapAsyncSequential} from '@docusaurus/utils'; import {loadContext, type LoadContextParams} from '../../server/site'; import {loadI18n} from '../../server/i18n'; -import {buildLocale} from './buildLocale'; +import {buildLocale, type BuildLocaleParams} from './buildLocale'; export type BuildCLIOptions = Pick< LoadContextParams, @@ -90,29 +90,33 @@ async function getLocalesToBuild({ ]; } -async function tryToBuildLocale({ - siteDir, - locale, - cliOptions, -}: { - siteDir: string; - locale: string; - cliOptions: BuildCLIOptions; -}) { +async function tryToBuildLocale(params: BuildLocaleParams) { try { - await PerfLogger.async(`${logger.name(locale)}`, async () => { - await buildLocale({ - siteDir, - locale, - cliOptions, - }); + await PerfLogger.async(`${logger.name(params.locale)}`, async () => { + // Note: I tried to run buildLocale in worker_threads (still sequentially) + // It didn't work and I got SIGSEGV / SIGBUS errors + // See https://x.com/sebastienlorber/status/1848413716372480338 + await runBuildLocaleTask(params); }); } catch (err) { throw new Error( - logger.interpolate`Unable to build website for locale name=${locale}.`, + logger.interpolate`Unable to build website for locale name=${params.locale}.`, { cause: err, }, ); } } + +async function runBuildLocaleTask(params: BuildLocaleParams) { + // Note: I tried to run buildLocale task in worker_threads (sequentially) + // It didn't work and I got SIGSEGV / SIGBUS errors + // Goal was to isolate memory of each localized site build + // See also https://x.com/sebastienlorber/status/1848413716372480338 + // + // Running in child_process worked but is more complex and requires + // specifying the memory of the child process + weird logging issues to fix + // + // Note in the future we could try to enable concurrent localized site builds + await buildLocale(params); +} diff --git a/packages/docusaurus/src/commands/build/buildLocale.ts b/packages/docusaurus/src/commands/build/buildLocale.ts index 49b847c0db1b..1d8c30f219e9 100644 --- a/packages/docusaurus/src/commands/build/buildLocale.ts +++ b/packages/docusaurus/src/commands/build/buildLocale.ts @@ -27,15 +27,17 @@ import type { import type {SiteCollectedData} from '../../common'; import {BuildCLIOptions} from './build'; +export type BuildLocaleParams = { + siteDir: string; + locale: string; + cliOptions: Partial; +}; + export async function buildLocale({ siteDir, locale, cliOptions, -}: { - siteDir: string; - locale: string; - cliOptions: Partial; -}): Promise { +}: BuildLocaleParams): Promise { // Temporary workaround to unlock the ability to translate the site config // We'll remove it if a better official API can be designed // See https://github.com/facebook/docusaurus/issues/4542