From 7f91d9d5f5902512a7a1cfd0cec0731d93de9e6d Mon Sep 17 00:00:00 2001
From: Brian Vaughn <bvaughn@fb.com>
Date: Wed, 3 Nov 2021 14:09:29 -0400
Subject: [PATCH] Remove duplicate header comment that resulted from build time
 module-boundary wrapper code

---
 scripts/rollup/wrappers.js                    | 32 +++++++++++--------
 .../wrappers/registerInternalModuleBegin.js   | 10 +-----
 .../wrappers/registerInternalModuleEnd.js     | 10 +-----
 3 files changed, 20 insertions(+), 32 deletions(-)
 rename packages/shared/registerInternalModuleStart.js => scripts/rollup/wrappers/registerInternalModuleBegin.js (51%)
 rename packages/shared/registerInternalModuleStop.js => scripts/rollup/wrappers/registerInternalModuleEnd.js (50%)

diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js
index c83ecc0fbdb96..83ed19d00c2d6 100644
--- a/scripts/rollup/wrappers.js
+++ b/scripts/rollup/wrappers.js
@@ -27,24 +27,23 @@ const {
 
 const {RECONCILER} = moduleTypes;
 
+const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;
+
 function registerInternalModuleStart(globalName) {
-  const path = resolve(
-    __dirname,
-    '..',
-    '..',
-    'packages/shared/registerInternalModuleStart.js'
-  );
-  return String(readFileSync(path)).trim();
+  const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
+  const file = readFileSync(path);
+  return String(file).trim();
 }
 
 function registerInternalModuleStop(globalName) {
-  const path = resolve(
-    __dirname,
-    '..',
-    '..',
-    'packages/shared/registerInternalModuleStop.js'
-  );
-  return String(readFileSync(path)).trim();
+  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();
 }
 
 const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
@@ -359,6 +358,11 @@ function wrapBundle(
       case RN_OSS_PROFILING:
       case RN_FB_DEV:
       case RN_FB_PROFILING:
+        // Remove the 'use strict' directive from source.
+        // The module start wrapper will add its own.
+        // This directive is only meaningful when it is the first statement in a file or function.
+        source = source.replace(USE_STRICT_HEADER_REGEX, '');
+
         // Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
         // This allows the Scheduling Profiler to de-emphasize (dim) internal stack frames.
         source = `
diff --git a/packages/shared/registerInternalModuleStart.js b/scripts/rollup/wrappers/registerInternalModuleBegin.js
similarity index 51%
rename from packages/shared/registerInternalModuleStart.js
rename to scripts/rollup/wrappers/registerInternalModuleBegin.js
index 1bab503c2a6da..a9170ca3e45da 100644
--- a/packages/shared/registerInternalModuleStart.js
+++ b/scripts/rollup/wrappers/registerInternalModuleBegin.js
@@ -1,14 +1,6 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
+'use strict';
 
 /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
-
-// Don't require this file directly; it's embedded by Rollup during build.
-
 if (
   typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
   typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
diff --git a/packages/shared/registerInternalModuleStop.js b/scripts/rollup/wrappers/registerInternalModuleEnd.js
similarity index 50%
rename from packages/shared/registerInternalModuleStop.js
rename to scripts/rollup/wrappers/registerInternalModuleEnd.js
index 44a69bed9ac37..119fb115a1ceb 100644
--- a/packages/shared/registerInternalModuleStop.js
+++ b/scripts/rollup/wrappers/registerInternalModuleEnd.js
@@ -1,14 +1,6 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
+'use strict';
 
 /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
-
-// Don't require this file directly; it's embedded by Rollup during build.
-
 if (
   typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
   typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===