Skip to content

Commit 733d3aa

Browse files
authored
Fix FB_WWW eprh bundle dev guard (#36238)
We use FB_WWW bundle to inject internal feature flag values, but need to use NODE guard type because this is a node script -- __DEV__ is breaking internal builds Follow up to #35951
1 parent 404b38c commit 733d3aa

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

scripts/rollup/build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ function getPlugins(
453453
globalName,
454454
filename,
455455
moduleType,
456-
bundle.wrapWithModuleBoundaries
456+
bundle.wrapWithModuleBoundaries,
457+
bundle.wrapWithNodeDevGuard
457458
);
458459
},
459460
},

scripts/rollup/bundles.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,15 @@ const bundles = [
12351235
// currently required in order for the package to be copied over correctly.
12361236
// So, it would be worth improving that flow.
12371237
name: 'eslint-plugin-react-hooks',
1238-
bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, FB_WWW_PROD, CJS_DTS],
1238+
bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, CJS_DTS],
12391239
moduleType: ISOMORPHIC,
12401240
entry: 'eslint-plugin-react-hooks/src/index.ts',
12411241
global: 'ESLintPluginReactHooks',
12421242
minifyWithProdErrorCodes: false,
12431243
wrapWithModuleBoundaries: false,
1244+
// This is a Node.js build tool (ESLint plugin), not a www runtime bundle.
1245+
// Use process.env.NODE_ENV guard instead of __DEV__ for the dev wrapper.
1246+
wrapWithNodeDevGuard: true,
12441247
preferBuiltins: true,
12451248
externals: [
12461249
'@babel/core',

scripts/rollup/wrappers.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ function wrapWithTopLevelDefinitions(
510510
globalName,
511511
filename,
512512
moduleType,
513-
wrapWithModuleBoundaries
513+
wrapWithModuleBoundaries,
514+
wrapWithNodeDevGuard
514515
) {
515516
if (wrapWithModuleBoundaries) {
516517
switch (bundleType) {
@@ -553,8 +554,14 @@ function wrapWithTopLevelDefinitions(
553554
return wrapper(source, globalName, filename, moduleType);
554555
}
555556

557+
// Node.js build tools (e.g. ESLint plugins) use process.env.NODE_ENV instead
558+
// of __DEV__ even when building for FB_WWW, since they run in Node.js where
559+
// __DEV__ is not defined.
560+
const effectiveBundleType =
561+
wrapWithNodeDevGuard && bundleType === FB_WWW_DEV ? NODE_DEV : bundleType;
562+
556563
// All the other packages.
557-
const wrapper = topLevelDefinitionWrappers[bundleType];
564+
const wrapper = topLevelDefinitionWrappers[effectiveBundleType];
558565
if (typeof wrapper !== 'function') {
559566
throw new Error(`Unsupported build type: ${bundleType}.`);
560567
}

0 commit comments

Comments
 (0)