Skip to content

Commit e641568

Browse files
authored
feat(core): Docusaurus Faster - Rspack Persistent Cache (#10931)
1 parent 5b848cb commit e641568

File tree

13 files changed

+285
-95
lines changed

13 files changed

+285
-95
lines changed

.github/workflows/tests-e2e.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
env:
6969
# Our website should build even with limited memory
7070
# See https://github.com/facebook/docusaurus/pull/10590
71-
NODE_OPTIONS: '--max-old-space-size=250'
71+
NODE_OPTIONS: '--max-old-space-size=300'
7272
DOCUSAURUS_PERF_LOGGER: 'true'
7373
working-directory: ../test-website
7474

@@ -181,7 +181,7 @@ jobs:
181181
env:
182182
# Our website should build even with limited memory
183183
# See https://github.com/facebook/docusaurus/pull/10590
184-
NODE_OPTIONS: '--max-old-space-size=250'
184+
NODE_OPTIONS: '--max-old-space-size=300'
185185
DOCUSAURUS_PERF_LOGGER: 'true'
186186
working-directory: ../test-website
187187

@@ -223,6 +223,6 @@ jobs:
223223
env:
224224
# Our website should build even with limited memory
225225
# See https://github.com/facebook/docusaurus/pull/10590
226-
NODE_OPTIONS: '--max-old-space-size=250'
226+
NODE_OPTIONS: '--max-old-space-size=300'
227227
DOCUSAURUS_PERF_LOGGER: 'true'
228228
working-directory: ../test-website

packages/docusaurus-faster/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"license": "MIT",
2020
"dependencies": {
2121
"@docusaurus/types": "3.7.0",
22-
"@rspack/core": "^1.2.2",
22+
"@rspack/core": "^1.2.5",
2323
"@swc/core": "^1.7.39",
2424
"@swc/html": "^1.7.39",
2525
"browserslist": "^4.24.2",

packages/docusaurus-plugin-content-docs/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ async function createMdxLoaderDependencyFile({
7676
dataDir: string;
7777
options: PluginOptions;
7878
versionsMetadata: VersionMetadata[];
79-
}) {
79+
}): Promise<string | undefined> {
80+
// TODO this has been temporarily made opt-in until Rspack cache bug is fixed
81+
// See https://github.com/facebook/docusaurus/pull/10931
82+
// See https://github.com/facebook/docusaurus/pull/10934#issuecomment-2672253145
83+
if (!process.env.DOCUSAURUS_ENABLE_MDX_DEPENDENCY_FILE) {
84+
return undefined;
85+
}
86+
8087
const filePath = path.join(dataDir, '__mdx-loader-dependency.json');
8188
// the cache is invalidated whenever this file content changes
8289
const fileContent = {
@@ -138,7 +145,7 @@ export default async function pluginContentDocs(
138145
options,
139146
versionsMetadata,
140147
}),
141-
],
148+
].filter((d): d is string => typeof d === 'string'),
142149

143150
useCrossCompilerCache:
144151
siteConfig.future.experimental_faster.mdxCrossCompilerCache,

packages/docusaurus-types/src/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export type FasterConfig = {
130130
lightningCssMinimizer: boolean;
131131
mdxCrossCompilerCache: boolean;
132132
rspackBundler: boolean;
133+
rspackPersistentCache: boolean;
133134
ssgWorkerThreads: boolean;
134135
};
135136

packages/docusaurus/src/commands/clear.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ async function removePath(entry: {path: string; description: string}) {
1919
}
2020
try {
2121
await fs.remove(entry.path);
22-
logger.success`Removed the ${entry.description} at path=${entry.path}.`;
22+
logger.success`Removed the ${entry.description} at path=${path.relative(
23+
process.cwd(),
24+
entry.path,
25+
)}.`;
2326
} catch (err) {
2427
logger.error`Could not remove the ${entry.description} at path=${entry.path}.`;
2528
logger.error(err);
@@ -40,7 +43,7 @@ export async function clear(siteDirParam: string = '.'): Promise<void> {
4043
// In Yarn PnP, cache is stored in `.yarn/.cache` because n_m doesn't exist
4144
const cacheFolders = ['node_modules', '.yarn'].map((p) => ({
4245
path: path.join(siteDir, p, '.cache'),
43-
description: 'Webpack persistent cache folder',
46+
description: 'bundler persistent cache folder',
4447
}));
4548
await Promise.all(
4649
[generatedFolder, buildFolder, ...cacheFolders].map(removePath),

packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = `
1212
"lightningCssMinimizer": false,
1313
"mdxCrossCompilerCache": false,
1414
"rspackBundler": false,
15+
"rspackPersistentCache": false,
1516
"ssgWorkerThreads": false,
1617
"swcHtmlMinimizer": false,
1718
"swcJsLoader": false,
@@ -85,6 +86,7 @@ exports[`loadSiteConfig website with ts + js config 1`] = `
8586
"lightningCssMinimizer": false,
8687
"mdxCrossCompilerCache": false,
8788
"rspackBundler": false,
89+
"rspackPersistentCache": false,
8890
"ssgWorkerThreads": false,
8991
"swcHtmlMinimizer": false,
9092
"swcJsLoader": false,
@@ -158,6 +160,7 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = `
158160
"lightningCssMinimizer": false,
159161
"mdxCrossCompilerCache": false,
160162
"rspackBundler": false,
163+
"rspackPersistentCache": false,
161164
"ssgWorkerThreads": false,
162165
"swcHtmlMinimizer": false,
163166
"swcJsLoader": false,
@@ -231,6 +234,7 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = `
231234
"lightningCssMinimizer": false,
232235
"mdxCrossCompilerCache": false,
233236
"rspackBundler": false,
237+
"rspackPersistentCache": false,
234238
"ssgWorkerThreads": false,
235239
"swcHtmlMinimizer": false,
236240
"swcJsLoader": false,
@@ -304,6 +308,7 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = `
304308
"lightningCssMinimizer": false,
305309
"mdxCrossCompilerCache": false,
306310
"rspackBundler": false,
311+
"rspackPersistentCache": false,
307312
"ssgWorkerThreads": false,
308313
"swcHtmlMinimizer": false,
309314
"swcJsLoader": false,
@@ -377,6 +382,7 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = `
377382
"lightningCssMinimizer": false,
378383
"mdxCrossCompilerCache": false,
379384
"rspackBundler": false,
385+
"rspackPersistentCache": false,
380386
"ssgWorkerThreads": false,
381387
"swcHtmlMinimizer": false,
382388
"swcJsLoader": false,
@@ -450,6 +456,7 @@ exports[`loadSiteConfig website with valid async config 1`] = `
450456
"lightningCssMinimizer": false,
451457
"mdxCrossCompilerCache": false,
452458
"rspackBundler": false,
459+
"rspackPersistentCache": false,
453460
"ssgWorkerThreads": false,
454461
"swcHtmlMinimizer": false,
455462
"swcJsLoader": false,
@@ -525,6 +532,7 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = `
525532
"lightningCssMinimizer": false,
526533
"mdxCrossCompilerCache": false,
527534
"rspackBundler": false,
535+
"rspackPersistentCache": false,
528536
"ssgWorkerThreads": false,
529537
"swcHtmlMinimizer": false,
530538
"swcJsLoader": false,
@@ -600,6 +608,7 @@ exports[`loadSiteConfig website with valid config creator function 1`] = `
600608
"lightningCssMinimizer": false,
601609
"mdxCrossCompilerCache": false,
602610
"rspackBundler": false,
611+
"rspackPersistentCache": false,
603612
"ssgWorkerThreads": false,
604613
"swcHtmlMinimizer": false,
605614
"swcJsLoader": false,
@@ -678,6 +687,7 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = `
678687
"lightningCssMinimizer": false,
679688
"mdxCrossCompilerCache": false,
680689
"rspackBundler": false,
690+
"rspackPersistentCache": false,
681691
"ssgWorkerThreads": false,
682692
"swcHtmlMinimizer": false,
683693
"swcJsLoader": false,

packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ exports[`load loads props for site with custom i18n path 1`] = `
8686
"lightningCssMinimizer": false,
8787
"mdxCrossCompilerCache": false,
8888
"rspackBundler": false,
89+
"rspackPersistentCache": false,
8990
"ssgWorkerThreads": false,
9091
"swcHtmlMinimizer": false,
9192
"swcJsLoader": false,

packages/docusaurus/src/server/__tests__/configValidation.test.ts

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('normalizeConfig', () => {
5858
lightningCssMinimizer: true,
5959
mdxCrossCompilerCache: true,
6060
rspackBundler: true,
61+
rspackPersistentCache: true,
6162
ssgWorkerThreads: true,
6263
},
6364
experimental_storage: {
@@ -761,6 +762,7 @@ describe('future', () => {
761762
lightningCssMinimizer: true,
762763
mdxCrossCompilerCache: true,
763764
rspackBundler: true,
765+
rspackPersistentCache: true,
764766
ssgWorkerThreads: true,
765767
},
766768
experimental_storage: {
@@ -1115,6 +1117,7 @@ describe('future', () => {
11151117
lightningCssMinimizer: true,
11161118
mdxCrossCompilerCache: true,
11171119
rspackBundler: true,
1120+
rspackPersistentCache: true,
11181121
ssgWorkerThreads: true,
11191122
};
11201123
expect(
@@ -1156,7 +1159,8 @@ describe('future', () => {
11561159
}),
11571160
).toThrowErrorMatchingInlineSnapshot(`
11581161
"Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on.
1159-
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`"
1162+
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`
1163+
All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future"
11601164
`);
11611165
});
11621166

@@ -1170,7 +1174,8 @@ describe('future', () => {
11701174
}),
11711175
).toThrowErrorMatchingInlineSnapshot(`
11721176
"Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on.
1173-
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`"
1177+
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`
1178+
All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future"
11741179
`);
11751180
});
11761181

@@ -1615,6 +1620,110 @@ describe('future', () => {
16151620
});
16161621
});
16171622

1623+
describe('rspackPersistentCache', () => {
1624+
it('accepts - undefined', () => {
1625+
const faster: Partial<FasterConfig> = {
1626+
rspackPersistentCache: undefined,
1627+
};
1628+
expect(
1629+
normalizeConfig({
1630+
future: {
1631+
experimental_faster: faster,
1632+
},
1633+
}),
1634+
).toEqual(fasterContaining({rspackPersistentCache: false}));
1635+
});
1636+
1637+
it('accepts - true (rspackBundler: true)', () => {
1638+
const faster: Partial<FasterConfig> = {
1639+
rspackBundler: true,
1640+
rspackPersistentCache: true,
1641+
};
1642+
expect(
1643+
normalizeConfig({
1644+
future: {
1645+
experimental_faster: faster,
1646+
},
1647+
}),
1648+
).toEqual(fasterContaining({rspackPersistentCache: true}));
1649+
});
1650+
1651+
it('rejects - true (rspackBundler: false)', () => {
1652+
const faster: Partial<FasterConfig> = {
1653+
rspackBundler: false,
1654+
rspackPersistentCache: true,
1655+
};
1656+
expect(() =>
1657+
normalizeConfig({
1658+
future: {
1659+
experimental_faster: faster,
1660+
},
1661+
}),
1662+
).toThrowErrorMatchingInlineSnapshot(
1663+
`"Docusaurus config flag \`future.experimental_faster.rspackPersistentCache\` requires the flag \`future.experimental_faster.rspackBundler\` to be turned on."`,
1664+
);
1665+
});
1666+
1667+
it('rejects - true (rspackBundler: undefined)', () => {
1668+
const faster: Partial<FasterConfig> = {
1669+
rspackBundler: false,
1670+
rspackPersistentCache: true,
1671+
};
1672+
expect(() =>
1673+
normalizeConfig({
1674+
future: {
1675+
experimental_faster: faster,
1676+
},
1677+
}),
1678+
).toThrowErrorMatchingInlineSnapshot(
1679+
`"Docusaurus config flag \`future.experimental_faster.rspackPersistentCache\` requires the flag \`future.experimental_faster.rspackBundler\` to be turned on."`,
1680+
);
1681+
});
1682+
1683+
it('accepts - false', () => {
1684+
const faster: Partial<FasterConfig> = {
1685+
rspackPersistentCache: false,
1686+
};
1687+
expect(
1688+
normalizeConfig({
1689+
future: {
1690+
experimental_faster: faster,
1691+
},
1692+
}),
1693+
).toEqual(fasterContaining({rspackPersistentCache: false}));
1694+
});
1695+
1696+
it('rejects - null', () => {
1697+
// @ts-expect-error: invalid
1698+
const faster: Partial<FasterConfig> = {rspackPersistentCache: 42};
1699+
expect(() =>
1700+
normalizeConfig({
1701+
future: {
1702+
experimental_faster: faster,
1703+
},
1704+
}),
1705+
).toThrowErrorMatchingInlineSnapshot(`
1706+
""future.experimental_faster.rspackPersistentCache" must be a boolean
1707+
"
1708+
`);
1709+
});
1710+
1711+
it('rejects - number', () => {
1712+
// @ts-expect-error: invalid
1713+
const faster: Partial<FasterConfig> = {rspackPersistentCache: 42};
1714+
expect(() =>
1715+
normalizeConfig({
1716+
future: {
1717+
experimental_faster: faster,
1718+
},
1719+
}),
1720+
).toThrowErrorMatchingInlineSnapshot(`
1721+
""future.experimental_faster.rspackPersistentCache" must be a boolean
1722+
"
1723+
`);
1724+
});
1725+
});
1726+
16181727
describe('ssgWorkerThreads', () => {
16191728
it('accepts - undefined', () => {
16201729
const faster: Partial<FasterConfig> = {
@@ -1656,7 +1765,8 @@ describe('future', () => {
16561765
}),
16571766
).toThrowErrorMatchingInlineSnapshot(`
16581767
"Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on.
1659-
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`"
1768+
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`
1769+
All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future"
16601770
`);
16611771
});
16621772

@@ -1673,7 +1783,8 @@ describe('future', () => {
16731783
}),
16741784
).toThrowErrorMatchingInlineSnapshot(`
16751785
"Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on.
1676-
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`"
1786+
If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\`
1787+
All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future"
16771788
`);
16781789
});
16791790

0 commit comments

Comments
 (0)