|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const {resolve} = require('path'); |
4 | | -const {readFileSync} = require('fs'); |
5 | 3 | const {signFile, getSigningToken} = require('signedsource'); |
6 | 4 | const {bundleTypes, moduleTypes} = require('./bundles'); |
7 | 5 |
|
@@ -30,19 +28,25 @@ const {RECONCILER} = moduleTypes; |
30 | 28 |
|
31 | 29 | const USE_STRICT_HEADER_REGEX = /'use strict';\n+/; |
32 | 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()); |
37 | 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 | +`; |
46 | 50 | } |
47 | 51 |
|
48 | 52 | const license = ` * Copyright (c) Meta Platforms, Inc. and affiliates. |
@@ -496,11 +500,7 @@ function wrapWithTopLevelDefinitions( |
496 | 500 |
|
497 | 501 | // Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools. |
498 | 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 | 504 | break; |
505 | 505 | } |
506 | 506 | } |
|
0 commit comments