Skip to content

Commit ea1fef4

Browse files
jjuliamolinfacebook-github-bot
authored andcommitted
Fix OSS build after Docusaurus 3 upgrade
Summary: The Docusaurus 2→3 upgrade (D98898843) broke the GitHub CI website build. The bundled remark-mdx-filter-imports plugin visits import AST nodes (MDX v1/v2), but Docusaurus 3 uses MDX v3 where imports are mdxjsEsm nodes instead — so the filter never ran, and webpack failed trying to resolve internal fb/*.md files. Added a custom remark plugin (stripFbImports) that handles mdxjsEsm nodes correctly. It parses individual import statements within each node and only removes the ones matching fb paths, preserving other imports (like SrcFileLink, OssOnly) that MDX v3 may bundle into the same node. JSX elements referencing the removed imports are also stripped. Only active in OSS builds. Differential Revision: D101358870
1 parent edf92cf commit ea1fef4

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

glean/website/docusaurus.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010

1111
const {fbContent} = require('internaldocs-fb-helpers');
12+
const {isInternal} = require('docusaurus-plugin-internaldocs-fb/internal');
13+
const stripFbImports = require('./src/remark/stripFbImports');
1214

1315
module.exports = {
1416
title: 'Glean',
@@ -109,6 +111,9 @@ module.exports = {
109111
docs: {
110112
path: './docs',
111113
sidebarPath: require.resolve('./sidebars.js'),
114+
beforeDefaultRemarkPlugins: [
115+
...(!isInternal() ? [stripFbImports] : []),
116+
],
112117
editUrl: fbContent({
113118
internal:
114119
'https://www.internalfb.com/intern/diffusion/FBS/browse/master/fbcode/glean/website/',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
* @format
9+
*/
10+
11+
const fbPath = /\/(.*\/)?fb\//;
12+
13+
function stripFbImports() {
14+
return (tree) => {
15+
const stripped = new Set();
16+
const newChildren = [];
17+
18+
for (const node of tree.children) {
19+
if (node.type !== 'mdxjsEsm' || !node.data?.estree?.body) {
20+
newChildren.push(node);
21+
continue;
22+
}
23+
24+
const keptStatements = [];
25+
const removedSpecifiers = [];
26+
27+
for (const stmt of node.data.estree.body) {
28+
if (
29+
stmt.type === 'ImportDeclaration' &&
30+
fbPath.test(stmt.source.value)
31+
) {
32+
for (const sp of stmt.specifiers ?? [])
33+
removedSpecifiers.push(sp.local.name);
34+
} else {
35+
keptStatements.push(stmt);
36+
}
37+
}
38+
39+
for (const name of removedSpecifiers) stripped.add(name);
40+
41+
if (keptStatements.length === 0) continue;
42+
43+
if (keptStatements.length === node.data.estree.body.length) {
44+
newChildren.push(node);
45+
} else {
46+
const keptLines = node.value
47+
.split('\n')
48+
.filter((line) => !fbPath.test(line));
49+
newChildren.push({
50+
...node,
51+
value: keptLines.join('\n'),
52+
data: {
53+
...node.data,
54+
estree: { ...node.data.estree, body: keptStatements },
55+
},
56+
});
57+
}
58+
}
59+
60+
tree.children = newChildren;
61+
if (stripped.size > 0) stripJsx(tree, stripped);
62+
};
63+
}
64+
65+
function stripJsx(node, names) {
66+
if (!node.children) return;
67+
node.children = node.children.filter((c) => {
68+
if (c.type.startsWith('mdxJsx') && names.has(c.name)) return false;
69+
stripJsx(c, names);
70+
return true;
71+
});
72+
}
73+
74+
module.exports = stripFbImports;

0 commit comments

Comments
 (0)