From 0a0a3af75a740d0920ebf7f4affaf8d1ce8c107f Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Fri, 3 May 2024 14:08:10 -0400 Subject: [PATCH] Bundle config: inline internal hook wrapper (#28978) Bundle config: inline internal hook wrapper Instead of reading this wrapper from 2 files for "start" and "end" and then string modifying the templates, just inline them like the other wrappers in this file. --- scripts/rollup/wrappers.js | 38 +++++++++---------- .../wrappers/registerInternalModuleBegin.js | 10 ----- .../wrappers/registerInternalModuleEnd.js | 10 ----- 3 files changed, 19 insertions(+), 39 deletions(-) delete mode 100644 scripts/rollup/wrappers/registerInternalModuleBegin.js delete mode 100644 scripts/rollup/wrappers/registerInternalModuleEnd.js diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js index fb3ea66783bbb..e76931bb85b42 100644 --- a/scripts/rollup/wrappers.js +++ b/scripts/rollup/wrappers.js @@ -1,7 +1,5 @@ 'use strict'; -const {resolve} = require('path'); -const {readFileSync} = require('fs'); const {signFile, getSigningToken} = require('signedsource'); const {bundleTypes, moduleTypes} = require('./bundles'); @@ -30,19 +28,25 @@ const {RECONCILER} = moduleTypes; const USE_STRICT_HEADER_REGEX = /'use strict';\n+/; -function registerInternalModuleStart(globalName) { - const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js'); - const file = readFileSync(path); - return String(file).trim(); +function wrapWithRegisterInternalModule(source) { + return `\ +'use strict'; +if ( + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === + 'function' +) { + __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); } - -function registerInternalModuleStop(globalName) { - const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js'); - const file = readFileSync(path); - - // Remove the 'use strict' directive from the footer. - // This directive is only meaningful when it is the first statement in a file or function. - return String(file).replace(USE_STRICT_HEADER_REGEX, '').trim(); +${source} +if ( + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === + 'function' +) { + __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); +} +`; } const license = ` * Copyright (c) Meta Platforms, Inc. and affiliates. @@ -496,11 +500,7 @@ function wrapWithTopLevelDefinitions( // Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools. // This allows the Timeline to de-emphasize (dim) internal stack frames. - source = ` - ${registerInternalModuleStart(globalName)} - ${source} - ${registerInternalModuleStop(globalName)} - `; + source = wrapWithRegisterInternalModule(source); break; } } diff --git a/scripts/rollup/wrappers/registerInternalModuleBegin.js b/scripts/rollup/wrappers/registerInternalModuleBegin.js deleted file mode 100644 index a9170ca3e45da..0000000000000 --- a/scripts/rollup/wrappers/registerInternalModuleBegin.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ -if ( - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === - 'function' -) { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); -} diff --git a/scripts/rollup/wrappers/registerInternalModuleEnd.js b/scripts/rollup/wrappers/registerInternalModuleEnd.js deleted file mode 100644 index 119fb115a1ceb..0000000000000 --- a/scripts/rollup/wrappers/registerInternalModuleEnd.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ -if ( - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === - 'function' -) { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); -}