Fix FB isomorphic build (#10704)
* Freeze bundle configs before the build This ensures we don't accidentally mutate it. * Fix config mutation during the build uncovered by freeze * Fix FB isomorphic build by marking object-assign as an external * Bye bye redundant check
Dan Abramov committed
Sep 14, 2017 at 01:24 UTC
af36a05d5a8aecb31f3db66bbb8ebe95163ac14a
2 files changed
+20
-2
scripts/rollup/bundles.js
+18
@@ -369,6 +369,24 @@ const bundles = [
369
},
370
];
371
372
+// Based on deep-freeze by substack (public domain)
373
+function deepFreeze(o) {
374
+ Object.freeze(o);
375
+ Object.getOwnPropertyNames(o).forEach(function(prop) {
376
+ if (
377
+ o[prop] !== null &&
378
+ (typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
379
+ !Object.isFrozen(o[prop])
380
+ ) {
381
+ deepFreeze(o[prop]);
382
+ }
383
+ });
384
+ return o;
385
+}
386
+
387
+// Don't accidentally mutate config as part of the build
388
+deepFreeze(bundles);
389
+
390
module.exports = {
391
bundleTypes,
392
bundles,
scripts/rollup/modules.js
+2
-2
@@ -143,7 +143,7 @@ function getExternalModules(externals, bundleType, isRenderer) {
143
// this means having a require("name-of-external-module") at
144
// the top of the bundle. for UMD bundles this means having
145
// both a require and a global check for them
146
- let externalModules = externals;
146
+ let externalModules = externals.slice();
147
148
switch (bundleType) {
149
case UMD_DEV:
@@ -158,7 +158,6 @@ function getExternalModules(externals, bundleType, isRenderer) {
158
case RN_PROD:
159
fbjsModules.forEach(module => externalModules.push(module));
160
externalModules.push('object-assign');
161
-
161
if (isRenderer) {
162
externalModules.push('react');
163
}
@@ -166,6 +165,7 @@ function getExternalModules(externals, bundleType, isRenderer) {
165
case FB_DEV:
166
case FB_PROD:
167
fbjsModules.forEach(module => externalModules.push(module));
168
+ externalModules.push('object-assign');
169
externalModules.push('ReactCurrentOwner');
170
externalModules.push('lowPriorityWarning');
171
if (isRenderer) {