@samitouri / QOS-React / commits / 0a0a3af75a

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.

Jan Kassens committed May 3, 2024 at 14:08 UTC 0a0a3af75a740d0920ebf7f4affaf8d1ce8c107f
3 files changed +19 -39
scripts/rollup/wrappers.js
+19 -19
@@ -1,7 +1,5 @@
1 'use strict';
2
3 -const {resolve} = require('path');
4 -const {readFileSync} = require('fs');
3 const {signFile, getSigningToken} = require('signedsource');
4 const {bundleTypes, moduleTypes} = require('./bundles');
5
@@ -30,19 +28,25 @@ const {RECONCILER} = moduleTypes;
28
29 const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;
30
33 -function registerInternalModuleStart(globalName) {
34 - const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
35 - const file = readFileSync(path);
36 - return String(file).trim();
31 +function wrapWithRegisterInternalModule(source) {
32 + return `\
33 +'use strict';
34 +if (
35 + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
36 + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
37 + 'function'
38 +) {
39 + __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
40 }
38 -
39 -function registerInternalModuleStop(globalName) {
40 - const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js');
41 - const file = readFileSync(path);
42 -
43 - // Remove the 'use strict' directive from the footer.
44 - // This directive is only meaningful when it is the first statement in a file or function.
45 - return String(file).replace(USE_STRICT_HEADER_REGEX, '').trim();
41 +${source}
42 +if (
43 + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
44 + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
45 + 'function'
46 +) {
47 + __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
48 +}
49 +`;
50 }
51
52 const license = ` * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -496,11 +500,7 @@ function wrapWithTopLevelDefinitions(
500
501 // Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
502 // This allows the Timeline to de-emphasize (dim) internal stack frames.
499 - source = `
500 - ${registerInternalModuleStart(globalName)}
501 - ${source}
502 - ${registerInternalModuleStop(globalName)}
503 - `;
503 + source = wrapWithRegisterInternalModule(source);
504 break;
505 }
506 }
scripts/rollup/wrappers/registerInternalModuleBegin.js deleted
-10
@@ -1,10 +0,0 @@
1 -'use strict';
2 -
3 -/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
4 -if (
5 - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
6 - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
7 - 'function'
8 -) {
9 - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
10 -}
scripts/rollup/wrappers/registerInternalModuleEnd.js deleted
-10
@@ -1,10 +0,0 @@
1 -'use strict';
2 -
3 -/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
4 -if (
5 - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
6 - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
7 - 'function'
8 -) {
9 - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
10 -}