Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Docusaurus Faster - SSG worker threads #10826

Merged
merged 39 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
353436f
temporary remove helmet
slorber Jan 6, 2025
c29fd4a
temporary remove helmet
slorber Jan 6, 2025
489122f
SSG thread pool
slorber Jan 7, 2025
51a0d6d
try posix resolve for windows
slorber Jan 7, 2025
b42190d
fix(theme-translations): Add missing Polish (pl) theme translations (…
mariuszkrzaczkowski Jan 7, 2025
605107e
docs(website): Comparison with Rspress (#10822)
DevJoaoLopes Jan 7, 2025
678c6cd
feat(theme): code block showLineNumbers=start metastring (#10846)
slorber Jan 16, 2025
1fd3e21
fix(theme): Fix `<DocCardList>` usage on docs at root of a sidebar (#…
slorber Jan 16, 2025
788d617
Merge branch 'main' into slorber/poc-remove-helmet-nonserializable-data
slorber Jan 17, 2025
0e82861
useless log
slorber Jan 17, 2025
c0a68c0
useless comment
slorber Jan 17, 2025
a472e20
add v4 future flag: enableSSGWorkerThreads
slorber Jan 17, 2025
3fe6044
Infer SSG worker thread count
slorber Jan 17, 2025
f17ba7c
useless export
slorber Jan 17, 2025
461e1ed
snapshots
slorber Jan 17, 2025
10c5d11
stable SSG refactor
slorber Jan 23, 2025
4a370bb
add logs to debug windows issue
slorber Jan 23, 2025
1be0cf2
add logs to debug windows issue
slorber Jan 24, 2025
1b84830
install patch-package to monorepo
slorber Jan 24, 2025
6a3d338
test tinypool debug patch for windows issue
slorber Jan 24, 2025
5e16b7a
refactor: apply lint autofix
slorber Jan 24, 2025
1fa4503
test tinypool debug patch for windows issue
slorber Jan 24, 2025
6673459
Merge remote-tracking branch 'origin/slorber/poc-remove-helmet-nonser…
slorber Jan 24, 2025
d085a9f
cspell ignore patch-package patches files
slorber Jan 24, 2025
bbec34c
refactor: apply lint autofix
slorber Jan 24, 2025
a8b2c2f
empty
slorber Jan 24, 2025
051c28c
tinypool patch
slorber Jan 24, 2025
84864e0
test ESM worker
slorber Jan 24, 2025
d46c2cf
test ESM worker
slorber Jan 24, 2025
e65b8a8
test ESM worker
slorber Jan 24, 2025
76902f9
refactor: apply lint autofix
slorber Jan 24, 2025
d55360d
empty
slorber Jan 24, 2025
0a34905
fix tinypool windows bug?
slorber Jan 27, 2025
d01c920
remove tinypool debug patch
slorber Jan 27, 2025
63ccf09
move ssgWorkerThreads option to Docusaurus Faster
slorber Jan 27, 2025
25bace2
add basic doc for ssgWorkerThreads
slorber Jan 27, 2025
3e9fcd9
remove log
slorber Jan 27, 2025
6979595
polish
slorber Jan 27, 2025
49fd61b
polish
slorber Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add v4 future flag: enableSSGWorkerThreads
slorber committed Jan 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a472e20c52f04ee67d3dba7132d2fb7db3aeb96c
1 change: 1 addition & 0 deletions packages/docusaurus-types/src/config.d.ts
Original file line number Diff line number Diff line change
@@ -134,6 +134,7 @@ export type FasterConfig = {

export type FutureV4Config = {
removeLegacyPostBuildHeadAttribute: boolean;
enableSSGWorkerThreads: boolean;
};

export type FutureConfig = {
113 changes: 113 additions & 0 deletions packages/docusaurus/src/server/__tests__/configValidation.test.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ describe('normalizeConfig', () => {
future: {
v4: {
removeLegacyPostBuildHeadAttribute: true,
enableSSGWorkerThreads: true,
},
experimental_faster: {
swcJsLoader: true,
@@ -752,6 +753,7 @@ describe('future', () => {
const future: DocusaurusConfig['future'] = {
v4: {
removeLegacyPostBuildHeadAttribute: true,
enableSSGWorkerThreads: true,
},
experimental_faster: {
swcJsLoader: true,
@@ -1609,6 +1611,7 @@ describe('future', () => {
it('accepts v4 - full', () => {
const v4: FutureV4Config = {
removeLegacyPostBuildHeadAttribute: true,
enableSSGWorkerThreads: true,
};
expect(
normalizeConfig({
@@ -1724,5 +1727,115 @@ describe('future', () => {
`);
});
});

describe('enableSSGWorkerThreads', () => {
it('accepts - undefined', () => {
const v4: Partial<FutureV4Config> = {
enableSSGWorkerThreads: undefined,
};
expect(
normalizeConfig({
future: {
v4,
},
}),
).toEqual(v4Containing({enableSSGWorkerThreads: false}));
});

it('accepts - true', () => {
const v4: Partial<FutureV4Config> = {
removeLegacyPostBuildHeadAttribute: true, // required dependency
enableSSGWorkerThreads: true,
};
expect(
normalizeConfig({
future: {
v4,
},
}),
).toEqual(v4Containing({enableSSGWorkerThreads: true}));
});

it('accepts - false', () => {
const v4: Partial<FutureV4Config> = {
enableSSGWorkerThreads: false,
};
expect(
normalizeConfig({
future: {
v4,
},
}),
).toEqual(v4Containing({enableSSGWorkerThreads: false}));
});

it('rejects - true if removeLegacyPostBuildHeadAttribute is false', () => {
const v4: Partial<FutureV4Config> = {
removeLegacyPostBuildHeadAttribute: false,
enableSSGWorkerThreads: true,
};
expect(() =>
normalizeConfig({
future: {
v4,
},
}),
).toThrowErrorMatchingInlineSnapshot(`
"Docusaurus v4 future flag \`enableSSGWorkerThreads\` requires \`removeLegacyPostBuildHeadAttribute\` to be enabled first.
"
`);
});

it('rejects - true if removeLegacyPostBuildHeadAttribute is undefined', () => {
const v4: Partial<FutureV4Config> = {
removeLegacyPostBuildHeadAttribute: undefined,
enableSSGWorkerThreads: true,
};
expect(() =>
normalizeConfig({
future: {
v4,
},
}),
).toThrowErrorMatchingInlineSnapshot(`
"Docusaurus v4 future flag \`enableSSGWorkerThreads\` requires \`removeLegacyPostBuildHeadAttribute\` to be enabled first.
"
`);
});

it('rejects - null', () => {
const v4: Partial<FutureV4Config> = {
// @ts-expect-error: invalid
enableSSGWorkerThreads: 42,
};
expect(() =>
normalizeConfig({
future: {
v4,
},
}),
).toThrowErrorMatchingInlineSnapshot(`
""future.v4.enableSSGWorkerThreads" must be a boolean
"
`);
});

it('rejects - number', () => {
const v4: Partial<FutureV4Config> = {
// @ts-expect-error: invalid
enableSSGWorkerThreads: 42,
};
expect(() =>
normalizeConfig({
future: {
v4,
},
}),
).toThrowErrorMatchingInlineSnapshot(`
""future.v4.enableSSGWorkerThreads" must be a boolean
"
`);
});
});
});
});
24 changes: 24 additions & 0 deletions packages/docusaurus/src/server/configValidation.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import {
addLeadingSlash,
removeTrailingSlash,
} from '@docusaurus/utils-common';
import logger from '@docusaurus/logger';
import type {
FasterConfig,
FutureConfig,
@@ -63,11 +64,13 @@ export const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig = {

export const DEFAULT_FUTURE_V4_CONFIG: FutureV4Config = {
removeLegacyPostBuildHeadAttribute: false,
enableSSGWorkerThreads: false,
};

// When using the "v4: true" shortcut
export const DEFAULT_FUTURE_V4_CONFIG_TRUE: FutureV4Config = {
removeLegacyPostBuildHeadAttribute: true,
enableSSGWorkerThreads: true,
};

export const DEFAULT_FUTURE_CONFIG: FutureConfig = {
@@ -259,6 +262,27 @@ const FUTURE_V4_SCHEMA = Joi.alternatives()
removeLegacyPostBuildHeadAttribute: Joi.boolean().default(
DEFAULT_FUTURE_V4_CONFIG.removeLegacyPostBuildHeadAttribute,
),
enableSSGWorkerThreads: Joi.boolean()
.default(DEFAULT_FUTURE_V4_CONFIG.enableSSGWorkerThreads)
.custom((value, helpers) => {
const {removeLegacyPostBuildHeadAttribute} =
helpers.state.ancestors[0];
if (
value === true &&
(removeLegacyPostBuildHeadAttribute === false ||
removeLegacyPostBuildHeadAttribute === undefined)
) {
return helpers.error('any.custom', {key: 'B'});
}
return value; // Return the valid value
})
.messages({
'any.custom': `Docusaurus v4 future flag ${logger.code(
'enableSSGWorkerThreads',
)} requires ${logger.code(
'removeLegacyPostBuildHeadAttribute',
)} to be enabled first.`,
}),
}),
Joi.boolean()
.required()