From 0b418202dc4be1ef1519679a71668b5c9c506371 Mon Sep 17 00:00:00 2001 From: Jack Pope Date: Wed, 8 Apr 2026 16:04:14 -0400 Subject: [PATCH] Fix FB_WWW eprh bundle dev guard 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 --- scripts/rollup/build.js | 3 ++- scripts/rollup/bundles.js | 5 ++++- scripts/rollup/wrappers.js | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 66b74b436349..087c2e6a43b9 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -453,7 +453,8 @@ function getPlugins( globalName, filename, moduleType, - bundle.wrapWithModuleBoundaries + bundle.wrapWithModuleBoundaries, + bundle.wrapWithNodeDevGuard ); }, }, diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index dbf6160a847e..7b9508b9e29c 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -1235,12 +1235,15 @@ const bundles = [ // currently required in order for the package to be copied over correctly. // So, it would be worth improving that flow. name: 'eslint-plugin-react-hooks', - bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, FB_WWW_PROD, CJS_DTS], + bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, CJS_DTS], moduleType: ISOMORPHIC, entry: 'eslint-plugin-react-hooks/src/index.ts', global: 'ESLintPluginReactHooks', minifyWithProdErrorCodes: false, wrapWithModuleBoundaries: false, + // This is a Node.js build tool (ESLint plugin), not a www runtime bundle. + // Use process.env.NODE_ENV guard instead of __DEV__ for the dev wrapper. + wrapWithNodeDevGuard: true, preferBuiltins: true, externals: [ '@babel/core', diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js index 1773253cc965..52ae3b21252d 100644 --- a/scripts/rollup/wrappers.js +++ b/scripts/rollup/wrappers.js @@ -510,7 +510,8 @@ function wrapWithTopLevelDefinitions( globalName, filename, moduleType, - wrapWithModuleBoundaries + wrapWithModuleBoundaries, + wrapWithNodeDevGuard ) { if (wrapWithModuleBoundaries) { switch (bundleType) { @@ -553,8 +554,14 @@ function wrapWithTopLevelDefinitions( return wrapper(source, globalName, filename, moduleType); } + // Node.js build tools (e.g. ESLint plugins) use process.env.NODE_ENV instead + // of __DEV__ even when building for FB_WWW, since they run in Node.js where + // __DEV__ is not defined. + const effectiveBundleType = + wrapWithNodeDevGuard && bundleType === FB_WWW_DEV ? NODE_DEV : bundleType; + // All the other packages. - const wrapper = topLevelDefinitionWrappers[bundleType]; + const wrapper = topLevelDefinitionWrappers[effectiveBundleType]; if (typeof wrapper !== 'function') { throw new Error(`Unsupported build type: ${bundleType}.`); }