@@ -25,7 +25,7 @@ const syncReactNative = require('./sync').syncReactNative;
2525const syncReactNativeRT = require ( './sync' ) . syncReactNativeRT ;
2626const syncReactNativeCS = require ( './sync' ) . syncReactNativeCS ;
2727const Packaging = require ( './packaging' ) ;
28- const Header = require ( './header ' ) ;
28+ const Wrappers = require ( './wrappers ' ) ;
2929
3030const UMD_DEV = Bundles . bundleTypes . UMD_DEV ;
3131const UMD_PROD = Bundles . bundleTypes . UMD_PROD ;
@@ -36,9 +36,6 @@ const FB_PROD = Bundles.bundleTypes.FB_PROD;
3636const RN_DEV = Bundles . bundleTypes . RN_DEV ;
3737const RN_PROD = Bundles . bundleTypes . RN_PROD ;
3838
39- const RECONCILER = Bundles . moduleTypes . RECONCILER ;
40-
41- const reactVersion = require ( '../../package.json' ) . version ;
4239const requestedBundleTypes = ( argv . type || '' )
4340 . split ( ',' )
4441 . map ( type => type . toUpperCase ( ) ) ;
@@ -63,109 +60,6 @@ const closureOptions = {
6360 processCommonJsModules : false ,
6461} ;
6562
66- function getBanner ( bundleType , globalName , filename , moduleType ) {
67- if ( moduleType === RECONCILER ) {
68- // Standalone reconciler is only used by third-party renderers.
69- // It is handled separately.
70- return getReconcilerBanner ( bundleType , filename ) ;
71- }
72-
73- switch ( bundleType ) {
74- // UMDs are not wrapped in conditions.
75- case UMD_DEV :
76- case UMD_PROD :
77- return Header . getHeader ( filename , reactVersion ) ;
78- // CommonJS DEV bundle is guarded to help weak dead code elimination.
79- case NODE_DEV :
80- let banner = Header . getHeader ( filename , reactVersion ) ;
81- // Wrap the contents of the if-DEV check with an IIFE.
82- // Block-level function definitions can cause problems for strict mode.
83- banner += `'use strict';\n\n\nif (process.env.NODE_ENV !== "production") {\n(function() {\n` ;
84- return banner ;
85- case NODE_PROD :
86- return Header . getHeader ( filename , reactVersion ) ;
87- // All FB and RN bundles need Haste headers.
88- // DEV bundle is guarded to help weak dead code elimination.
89- case FB_DEV :
90- case FB_PROD :
91- case RN_DEV :
92- case RN_PROD :
93- const isDev = bundleType === FB_DEV || bundleType === RN_DEV ;
94- const hasteFinalName = globalName + ( isDev ? '-dev' : '-prod' ) ;
95- // Wrap the contents of the if-DEV check with an IIFE.
96- // Block-level function definitions can cause problems for strict mode.
97- return (
98- Header . getProvidesHeader ( hasteFinalName ) +
99- ( isDev ? `\n\n'use strict';\n\n\nif (__DEV__) {\n(function() {\n` : '' )
100- ) ;
101- default :
102- throw new Error ( 'Unknown type.' ) ;
103- }
104- }
105-
106- function getFooter ( bundleType , filename , moduleType ) {
107- if ( moduleType === RECONCILER ) {
108- // Standalone reconciler is only used by third-party renderers.
109- // It is handled separately.
110- return getReconcilerFooter ( bundleType ) ;
111- }
112-
113- // Only need a footer if getBanner() has an opening brace.
114- switch ( bundleType ) {
115- // Non-UMD DEV bundles need conditions to help weak dead code elimination.
116- case NODE_DEV :
117- case FB_DEV :
118- case RN_DEV :
119- return '\n})();\n}\n' ;
120- default :
121- return '' ;
122- }
123- }
124-
125- // TODO: this is extremely gross.
126- // But it only affects the "experimental" standalone reconciler build.
127- // The goal is to avoid having any shared state between renderers sharing it on npm.
128- // Ideally we should just remove shared state in all Fiber modules and then lint against it.
129- // But for now, we store the exported function in a variable, and then put the rest of the code
130- // into a closure that makes all module-level state private to each call.
131- const RECONCILER_WRAPPER_INTRO = `var $$$reconciler;\nmodule.exports = function(config) {\n` ;
132- const RECONCILER_WRAPPER_OUTRO = `return ($$$reconciler || ($$$reconciler = module.exports))(config);\n};\n` ;
133-
134- function getReconcilerBanner ( bundleType , filename ) {
135- let banner = `${ Header . getHeader (
136- filename ,
137- reactVersion
138- ) } \n\n'use strict';\n\n\n`;
139- switch ( bundleType ) {
140- case NODE_DEV :
141- banner += `if (process.env.NODE_ENV !== "production") {\n${
142- RECONCILER_WRAPPER_INTRO
143- } `;
144- break ;
145- case NODE_PROD :
146- banner += RECONCILER_WRAPPER_INTRO ;
147- break ;
148- default :
149- throw new Error (
150- 'Standalone reconciler does not support ' + bundleType + ' builds.'
151- ) ;
152- }
153- return banner ;
154- }
155-
156- function getReconcilerFooter ( bundleType ) {
157- switch ( bundleType ) {
158- case NODE_DEV :
159- return `\n${ RECONCILER_WRAPPER_OUTRO } \n}` ;
160- case NODE_PROD :
161- return `\n${ RECONCILER_WRAPPER_OUTRO } ` ;
162- default :
163- throw new Error (
164- 'Standalone reconciler does not support ' + bundleType + ' builds.'
165- ) ;
166- }
167- }
168-
16963function getBabelConfig ( updateBabelOptions , bundleType , filename ) {
17064 let options = {
17165 exclude : 'node_modules/**' ,
@@ -393,9 +287,13 @@ function getPlugins(
393287 // License and haste headers, top-level `if` blocks.
394288 {
395289 transformBundle ( source ) {
396- const banner = getBanner ( bundleType , globalName , filename , moduleType ) ;
397- const footer = getFooter ( bundleType , filename , moduleType ) ;
398- return banner + '\n' + source + '\n' + footer ;
290+ return Wrappers . wrapBundle (
291+ source ,
292+ bundleType ,
293+ globalName ,
294+ filename ,
295+ moduleType
296+ ) ;
399297 } ,
400298 } ,
401299 // Record bundle size.
0 commit comments