@samitouri / QOS-React-2 / commits / 8ca3f567bc

Fix module-boundary wrappers (#22688)

Brian Vaughn committed Nov 4, 2021 at 10:40 UTC 8ca3f567bc3ed56c2101e5c51f968a5339f63093
3 files changed +20 -32
scripts/rollup/wrappers.js
+18 -14
@@ -27,24 +27,23 @@ const {
27
28 const {RECONCILER} = moduleTypes;
29
30 +const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;
31 +
32 function registerInternalModuleStart(globalName) {
31 - const path = resolve(
32 - __dirname,
33 - '..',
34 - '..',
35 - 'packages/shared/registerInternalModuleStart.js'
36 - );
37 - return String(readFileSync(path)).trim();
33 + const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
34 + const file = readFileSync(path);
35 + return String(file).trim();
36 }
37
38 function registerInternalModuleStop(globalName) {
41 - const path = resolve(
42 - __dirname,
43 - '..',
44 - '..',
45 - 'packages/shared/registerInternalModuleStop.js'
46 - );
47 - return String(readFileSync(path)).trim();
39 + const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js');
40 + const file = readFileSync(path);
41 +
42 + // Remove the 'use strict' directive from the footer.
43 + // This directive is only meaningful when it is the first statement in a file or function.
44 + return String(file)
45 + .replace(USE_STRICT_HEADER_REGEX, '')
46 + .trim();
47 }
48
49 const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
@@ -359,6 +358,11 @@ function wrapBundle(
358 case RN_OSS_PROFILING:
359 case RN_FB_DEV:
360 case RN_FB_PROFILING:
361 + // Remove the 'use strict' directive from source.
362 + // The module start wrapper will add its own.
363 + // This directive is only meaningful when it is the first statement in a file or function.
364 + source = source.replace(USE_STRICT_HEADER_REGEX, '');
365 +
366 // Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
367 // This allows the Timeline to de-emphasize (dim) internal stack frames.
368 source = `
scripts/rollup/wrappers/registerInternalModuleBegin.js renamed
+1 -9
@@ -1,14 +1,6 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
1 +'use strict';
2
3 /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
9 -
10 -// Don't require this file directly; it's embedded by Rollup during build.
11 -
4 if (
5 typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
6 typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
scripts/rollup/wrappers/registerInternalModuleEnd.js renamed
+1 -9
@@ -1,14 +1,6 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
1 +'use strict';
2
3 /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
9 -
10 -// Don't require this file directly; it's embedded by Rollup during build.
11 -
4 if (
5 typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
6 typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===