Skip to content

Commit 63faec5

Browse files
committed
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.
1 parent 73bcdfb commit 63faec5

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

scripts/rollup/wrappers.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const {resolve} = require('path');
4-
const {readFileSync} = require('fs');
53
const {signFile, getSigningToken} = require('signedsource');
64
const {bundleTypes, moduleTypes} = require('./bundles');
75

@@ -30,19 +28,25 @@ const {RECONCILER} = moduleTypes;
3028

3129
const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;
3230

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());
3740
}
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+
`;
4650
}
4751

4852
const license = ` * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -496,11 +500,7 @@ function wrapWithTopLevelDefinitions(
496500

497501
// Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
498502
// 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);
504504
break;
505505
}
506506
}

scripts/rollup/wrappers/registerInternalModuleBegin.js

-10
This file was deleted.

scripts/rollup/wrappers/registerInternalModuleEnd.js

-10
This file was deleted.

0 commit comments

Comments
 (0)