Skip to content

Commit

Permalink
refactor + comment
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 22, 2024
1 parent d81c2ab commit a272cd6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
38 changes: 21 additions & 17 deletions packages/docusaurus/src/commands/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
12 changes: 7 additions & 5 deletions packages/docusaurus/src/commands/build/buildLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import type {
import type {SiteCollectedData} from '../../common';
import {BuildCLIOptions} from './build';

export type BuildLocaleParams = {
siteDir: string;
locale: string;
cliOptions: Partial<BuildCLIOptions>;
};

export async function buildLocale({
siteDir,
locale,
cliOptions,
}: {
siteDir: string;
locale: string;
cliOptions: Partial<BuildCLIOptions>;
}): Promise<void> {
}: BuildLocaleParams): Promise<void> {
// 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
Expand Down

0 comments on commit a272cd6

Please sign in to comment.