Consolidate build process with GCC (#11483)

* Consolidate build process with GCC

* Record sizes

* Refactor header and footer wrapping

It is easier to understand if we just explicitly type them out.
This commit is contained in:
Dan Abramov
2017-11-08 22:37:11 +00:00
committed by GitHub
parent e88f292041
commit c83596df65
7 changed files with 452 additions and 456 deletions
+2 -2
View File
@@ -83,13 +83,13 @@
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-inject": "^2.0.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-prettier": "^0.3.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.1",
"rollup-plugin-strip-banner": "^0.2.0",
"run-sequence": "^1.1.4",
"through2": "^2.0.0",
"tmp": "~0.0.28",
"typescript": "~1.8.10",
"uglify-js": "^2.5.0",
"yargs": "^6.3.0"
},
"devEngines": {
+1 -1
View File
@@ -5,7 +5,7 @@ set -e
# Make sure we don't introduce accidental @providesModule annotations.
EXPECTED='packages/react-cs-renderer/src/ReactNativeCSTypes.js
packages/react-native-renderer/src/ReactNativeTypes.js
scripts/rollup/header.js'
scripts/rollup/wrappers.js'
ACTUAL=$(git grep -l @providesModule -- './*.js' ':!scripts/rollup/shims/*.js')
if [ "$EXPECTED" != "$ACTUAL" ]; then
+93 -295
View File
@@ -2,10 +2,12 @@
const rollup = require('rollup').rollup;
const babel = require('rollup-plugin-babel');
const closure = require('rollup-plugin-closure-compiler-js');
const commonjs = require('rollup-plugin-commonjs');
const alias = require('rollup-plugin-alias');
const uglify = require('rollup-plugin-uglify');
const prettier = require('rollup-plugin-prettier');
const replace = require('rollup-plugin-replace');
const stripBanner = require('rollup-plugin-strip-banner');
const chalk = require('chalk');
const join = require('path').join;
const resolve = require('path').resolve;
@@ -23,8 +25,7 @@ const syncReactNative = require('./sync').syncReactNative;
const syncReactNativeRT = require('./sync').syncReactNativeRT;
const syncReactNativeCS = require('./sync').syncReactNativeCS;
const Packaging = require('./packaging');
const Header = require('./header');
const closure = require('rollup-plugin-closure-compiler-js');
const Wrappers = require('./wrappers');
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
@@ -35,9 +36,6 @@ const FB_PROD = Bundles.bundleTypes.FB_PROD;
const RN_DEV = Bundles.bundleTypes.RN_DEV;
const RN_PROD = Bundles.bundleTypes.RN_PROD;
const RECONCILER = Bundles.moduleTypes.RECONCILER;
const reactVersion = require('../../package.json').version;
const requestedBundleTypes = (argv.type || '')
.split(',')
.map(type => type.toUpperCase());
@@ -51,134 +49,16 @@ const errorCodeOpts = {
errorMapFilePath: 'scripts/error-codes/codes.json',
};
function getHeaderSanityCheck(bundleType, globalName) {
switch (bundleType) {
case FB_DEV:
case FB_PROD:
case RN_DEV:
case RN_PROD:
let hasteFinalName = globalName;
switch (bundleType) {
case FB_DEV:
case RN_DEV:
hasteFinalName += '-dev';
break;
case FB_PROD:
case RN_PROD:
hasteFinalName += '-prod';
break;
}
return hasteFinalName;
case UMD_DEV:
case UMD_PROD:
return reactVersion;
default:
return null;
}
}
function getBanner(bundleType, globalName, filename, moduleType) {
if (moduleType === RECONCILER) {
// Standalone reconciler is only used by third-party renderers.
// It is handled separately.
return getReconcilerBanner(bundleType, filename);
}
switch (bundleType) {
// UMDs are not wrapped in conditions.
case UMD_DEV:
case UMD_PROD:
return Header.getHeader(filename, reactVersion);
// CommonJS DEV bundle is guarded to help weak dead code elimination.
case NODE_DEV:
let banner = Header.getHeader(filename, reactVersion);
// Wrap the contents of the if-DEV check with an IIFE.
// Block-level function definitions can cause problems for strict mode.
banner += `'use strict';\n\n\nif (process.env.NODE_ENV !== "production") {\n(function() {\n`;
return banner;
case NODE_PROD:
return Header.getHeader(filename, reactVersion);
// All FB and RN bundles need Haste headers.
// DEV bundle is guarded to help weak dead code elimination.
case FB_DEV:
case FB_PROD:
case RN_DEV:
case RN_PROD:
const isDev = bundleType === FB_DEV || bundleType === RN_DEV;
const hasteFinalName = globalName + (isDev ? '-dev' : '-prod');
// Wrap the contents of the if-DEV check with an IIFE.
// Block-level function definitions can cause problems for strict mode.
return (
Header.getProvidesHeader(hasteFinalName) +
(isDev ? `\n\n'use strict';\n\n\nif (__DEV__) {\n(function() {\n` : '')
);
default:
throw new Error('Unknown type.');
}
}
function getFooter(bundleType, filename, moduleType) {
if (moduleType === RECONCILER) {
// Standalone reconciler is only used by third-party renderers.
// It is handled separately.
return getReconcilerFooter(bundleType);
}
// Only need a footer if getBanner() has an opening brace.
switch (bundleType) {
// Non-UMD DEV bundles need conditions to help weak dead code elimination.
case NODE_DEV:
case FB_DEV:
case RN_DEV:
return '\n})();\n}\n';
default:
return '';
}
}
// TODO: this is extremely gross.
// But it only affects the "experimental" standalone reconciler build.
// The goal is to avoid having any shared state between renderers sharing it on npm.
// Ideally we should just remove shared state in all Fiber modules and then lint against it.
// But for now, we store the exported function in a variable, and then put the rest of the code
// into a closure that makes all module-level state private to each call.
const RECONCILER_WRAPPER_INTRO = `var $$$reconciler;\nmodule.exports = function(config) {\n`;
const RECONCILER_WRAPPER_OUTRO = `return ($$$reconciler || ($$$reconciler = module.exports))(config);\n};\n`;
function getReconcilerBanner(bundleType, filename) {
let banner = `${Header.getHeader(
filename,
reactVersion
)}\n\n'use strict';\n\n\n`;
switch (bundleType) {
case NODE_DEV:
banner += `if (process.env.NODE_ENV !== "production") {\n${
RECONCILER_WRAPPER_INTRO
}`;
break;
case NODE_PROD:
banner += RECONCILER_WRAPPER_INTRO;
break;
default:
throw new Error(
'Standalone reconciler does not support ' + bundleType + ' builds.'
);
}
return banner;
}
function getReconcilerFooter(bundleType) {
switch (bundleType) {
case NODE_DEV:
return `\n${RECONCILER_WRAPPER_OUTRO}\n}`;
case NODE_PROD:
return `\n${RECONCILER_WRAPPER_OUTRO}`;
default:
throw new Error(
'Standalone reconciler does not support ' + bundleType + ' builds.'
);
}
}
const closureOptions = {
compilationLevel: 'SIMPLE',
languageIn: 'ECMASCRIPT5_STRICT',
languageOut: 'ECMASCRIPT5_STRICT',
env: 'CUSTOM',
warningLevel: 'QUIET',
applyInputSourceMaps: false,
useTypesForOptimization: false,
processCommonJsModules: false,
};
function getBabelConfig(updateBabelOptions, bundleType, filename) {
let options = {
@@ -261,7 +141,6 @@ function getRollupOutputOptions(
return Object.assign(
{},
{
banner: getBanner(bundleType, globalName, filename, moduleType),
destDir: 'build/',
file:
'build/' +
@@ -270,7 +149,6 @@ function getRollupOutputOptions(
filename,
globalName
),
footer: getFooter(bundleType, filename, moduleType),
format,
globals,
interop: false,
@@ -280,13 +158,6 @@ function getRollupOutputOptions(
);
}
function stripEnvVariables(production) {
return {
__DEV__: production ? 'false' : 'true',
'process.env.NODE_ENV': production ? "'production'" : "'development'",
};
}
function getFormat(bundleType) {
switch (bundleType) {
case UMD_DEV:
@@ -323,86 +194,21 @@ function getFilename(name, globalName, bundleType) {
}
}
function getUglifyConfig(configs) {
var mangle = configs.mangle;
var preserveVersionHeader = configs.preserveVersionHeader;
var removeComments = configs.removeComments;
var headerSanityCheck = configs.headerSanityCheck;
return {
warnings: false,
compress: {
screw_ie8: true,
dead_code: true,
unused: true,
drop_debugger: true,
// we have a string literal <script> that we don't want to evaluate
// for FB prod bundles (where we disable mangling)
evaluate: mangle,
booleans: true,
// Our www inline transform combined with Jest resetModules is confused
// in some rare cases unless we keep all requires at the top:
hoist_funs: mangle,
},
output: {
beautify: !mangle,
comments(node, comment) {
if (preserveVersionHeader && comment.pos === 0 && comment.col === 0) {
// Keep the very first comment (the bundle header) in prod bundles.
if (
headerSanityCheck &&
comment.value.indexOf(headerSanityCheck) === -1
) {
// Sanity check: this doesn't look like the bundle header!
throw new Error(
'Expected the first comment to be the file header but got: ' +
comment.value
);
}
return true;
}
return !removeComments;
},
},
mangle: mangle
? {
toplevel: true,
screw_ie8: true,
}
: false,
};
}
// FB uses require('React') instead of require('react').
// We can't set up a forwarding module due to case sensitivity issues.
function rewriteFBReactImport() {
return {
transformBundle(source) {
return source.replace(/require\(['"]react['"]\)/g, "require('React')");
},
};
}
// Strip 'use strict' directives in individual modules
// because we always emit them in the file headers.
// The whole bundle is strict.
function stripUseStrict() {
return {
transform(source) {
return source.replace(/['"]use strict['"']/g, '');
},
};
}
// Plugin that writes to the error code file so that by the time it is picked
// up by Babel, the errors are already extracted.
function writeErrorCodes() {
const flush = extractErrorCodes(errorCodeOpts);
return {
transform(source) {
flush(source);
return source;
},
};
function isProductionBundleType(bundleType) {
switch (bundleType) {
case UMD_DEV:
case NODE_DEV:
case FB_DEV:
case RN_DEV:
return false;
case UMD_PROD:
case NODE_PROD:
case FB_PROD:
case RN_PROD:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
}
}
function getPlugins(
@@ -416,88 +222,81 @@ function getPlugins(
modulesToStub,
featureFlags
) {
const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts);
const shims = Modules.getShims(bundleType, entry, featureFlags);
const plugins = [
const isProduction = isProductionBundleType(bundleType);
const isInGlobalScope = bundleType === UMD_DEV || bundleType === UMD_PROD;
const isFBBundle = bundleType === FB_DEV || bundleType === FB_PROD;
const isRNBundle = bundleType === RN_DEV || bundleType === RN_PROD;
const shouldStayReadable = isFBBundle || isRNBundle;
return [
// Extract error codes from invariant() messages into a file.
shouldExtractErrors && writeErrorCodes(),
shouldExtractErrors && {
transform(source) {
findAndRecordErrorCodes(source);
return source;
},
},
// Shim some modules for www custom behavior and optimizations.
alias(shims),
// Use Node resolution mechanism.
resolvePlugin({
skip: externals,
}),
// Remove license headers from individual modules
stripBanner({
exclude: 'node_modules/**/*',
}),
// Compile to ES5.
babel(getBabelConfig(updateBabelOptions, bundleType)),
stripUseStrict(),
].filter(Boolean);
const headerSanityCheck = getHeaderSanityCheck(bundleType, globalName);
switch (bundleType) {
case UMD_DEV:
case NODE_DEV:
plugins.push(replace(stripEnvVariables(false)), commonjs());
break;
case UMD_PROD:
case NODE_PROD:
plugins.push(
replace(stripEnvVariables(true)),
commonjs(),
closure({
compilationLevel: 'SIMPLE',
languageIn: 'ECMASCRIPT5_STRICT',
languageOut: 'ECMASCRIPT5_STRICT',
env: 'CUSTOM',
warningLevel: 'QUIET',
// Remove 'use strict' from individual source files.
{
transform(source) {
return source.replace(/['"]use strict['"']/g, '');
},
},
// Turn __DEV__ and process.env checks into constants.
replace({
__DEV__: isProduction ? 'false' : 'true',
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
}),
// We still need CommonJS for external deps like object-assign.
commonjs(),
// www still needs require('React') rather than require('react')
isFBBundle && {
transformBundle(source) {
return source.replace(/require\(['"]react['"]\)/g, "require('React')");
},
},
// Apply dead code elimination and/or minification.
isProduction &&
closure(
Object.assign({}, closureOptions, {
// Don't let it create global variables in the browser.
// https://github.com/facebook/react/issues/10909
assumeFunctionWrapper: bundleType !== UMD_PROD,
applyInputSourceMaps: false,
useTypesForOptimization: false,
processCommonJsModules: false,
assumeFunctionWrapper: !isInGlobalScope,
// Works because `google-closure-compiler-js` is forked in Yarn lockfile.
// We can remove this if GCC merges my PR:
// https://github.com/google/closure-compiler/pull/2707
// and then the compiled version is released via `google-closure-compiler-js`.
renaming: !shouldStayReadable,
})
);
break;
case FB_DEV:
plugins.push(
replace(stripEnvVariables(false)),
commonjs(),
rewriteFBReactImport()
);
break;
case FB_PROD:
plugins.push(
replace(stripEnvVariables(true)),
commonjs(),
uglify(
getUglifyConfig({
mangle: bundleType !== FB_PROD,
preserveVersionHeader: bundleType === UMD_PROD,
// leave comments in for source map debugging purposes
// they will be stripped as part of FB's build process
removeComments: bundleType !== FB_PROD,
headerSanityCheck,
})
),
rewriteFBReactImport()
);
break;
case RN_DEV:
case RN_PROD:
plugins.push(
replace(stripEnvVariables(bundleType === RN_PROD)),
commonjs(),
uglify(
getUglifyConfig({
mangle: false,
preserveVersionHeader: true,
removeComments: true,
headerSanityCheck,
})
)
);
break;
}
plugins.push(
),
// Add the whitespace back if necessary.
shouldStayReadable && prettier(),
// License and haste headers, top-level `if` blocks.
{
transformBundle(source) {
return Wrappers.wrapBundle(
source,
bundleType,
globalName,
filename,
moduleType
);
},
},
// Record bundle size.
sizes({
getSize: (size, gzip) => {
const key = `${filename} (${bundleType})`;
@@ -506,9 +305,8 @@ function getPlugins(
gzip,
};
},
})
);
return plugins;
}),
].filter(Boolean);
}
function createBundle(bundle, bundleType) {
-32
View File
@@ -1,32 +0,0 @@
'use strict';
function getProvidesHeader(hasteFinalName) {
return `/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noflow
* @providesModule ${hasteFinalName}
* @preventMunge
*/
`;
}
function getHeader(filename, reactVersion) {
return `/** @license React v${reactVersion}
* ${filename}
*
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
`;
}
module.exports = {
getProvidesHeader,
getHeader,
};
+104 -104
View File
@@ -1,212 +1,212 @@
{
"bundleSizes": {
"react.development.js (UMD_DEV)": {
"size": 57647,
"gzip": 14957
"size": 54812,
"gzip": 14834
},
"react.production.min.js (UMD_PROD)": {
"size": 6676,
"gzip": 2774
"size": 6577,
"gzip": 2731
},
"react.development.js (NODE_DEV)": {
"size": 48028,
"gzip": 12662
"size": 45180,
"gzip": 12540
},
"react.production.min.js (NODE_PROD)": {
"size": 5475,
"gzip": 2351
"size": 5377,
"gzip": 2310
},
"React-dev.js (FB_DEV)": {
"size": 46073,
"gzip": 12047
"size": 45067,
"gzip": 12284
},
"React-prod.js (FB_PROD)": {
"size": 25976,
"gzip": 6831
"size": 12469,
"gzip": 3322
},
"react-dom.development.js (UMD_DEV)": {
"size": 587808,
"gzip": 133625
"size": 566445,
"gzip": 132067
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 94541,
"gzip": 30614
"size": 94571,
"gzip": 30628
},
"react-dom.development.js (NODE_DEV)": {
"size": 568590,
"gzip": 128929
"size": 547414,
"gzip": 127145
},
"react-dom.production.min.js (NODE_PROD)": {
"size": 92717,
"gzip": 29846
"size": 92747,
"gzip": 29857
},
"ReactDOM-dev.js (FB_DEV)": {
"size": 572114,
"gzip": 130091
"size": 572910,
"gzip": 131679
},
"ReactDOM-prod.js (FB_PROD)": {
"size": 418963,
"gzip": 92847
"size": 270891,
"gzip": 51323
},
"react-dom-test-utils.development.js (NODE_DEV)": {
"size": 37878,
"gzip": 10319
"size": 35991,
"gzip": 10251
},
"react-dom-test-utils.production.min.js (NODE_PROD)": {
"size": 10173,
"gzip": 3834
"size": 10195,
"gzip": 3840
},
"ReactTestUtils-dev.js (FB_DEV)": {
"size": 37278,
"gzip": 10187
"size": 36706,
"gzip": 10335
},
"react-dom-unstable-native-dependencies.development.js (UMD_DEV)": {
"size": 66834,
"gzip": 16686
"size": 63456,
"gzip": 16551
},
"react-dom-unstable-native-dependencies.production.min.js (UMD_PROD)": {
"size": 11351,
"gzip": 3902
"size": 11373,
"gzip": 3908
},
"react-dom-unstable-native-dependencies.development.js (NODE_DEV)": {
"size": 62186,
"gzip": 15358
"size": 58986,
"gzip": 15262
},
"react-dom-unstable-native-dependencies.production.min.js (NODE_PROD)": {
"size": 10894,
"gzip": 3773
"size": 10916,
"gzip": 3778
},
"ReactDOMUnstableNativeDependencies-dev.js (FB_DEV)": {
"size": 61619,
"gzip": 15202
"size": 60056,
"gzip": 15406
},
"ReactDOMUnstableNativeDependencies-prod.js (FB_PROD)": {
"size": 52151,
"gzip": 12591
"size": 26610,
"gzip": 5327
},
"react-dom-server.browser.development.js (UMD_DEV)": {
"size": 101089,
"gzip": 26192
"size": 94251,
"gzip": 25351
},
"react-dom-server.browser.production.min.js (UMD_PROD)": {
"size": 14718,
"gzip": 5827
"size": 14740,
"gzip": 5834
},
"react-dom-server.browser.development.js (NODE_DEV)": {
"size": 89855,
"gzip": 23451
"size": 83195,
"gzip": 22545
},
"react-dom-server.browser.production.min.js (NODE_PROD)": {
"size": 14193,
"gzip": 5709
"size": 14215,
"gzip": 5714
},
"ReactDOMServer-dev.js (FB_DEV)": {
"size": 89282,
"gzip": 23287
"size": 86914,
"gzip": 22797
},
"ReactDOMServer-prod.js (FB_PROD)": {
"size": 45189,
"gzip": 11995
"size": 31382,
"gzip": 8114
},
"react-dom-server.node.development.js (NODE_DEV)": {
"size": 92021,
"gzip": 23959
"size": 85177,
"gzip": 23046
},
"react-dom-server.node.production.min.js (NODE_PROD)": {
"size": 15018,
"gzip": 6017
"size": 15040,
"gzip": 6022
},
"react-art.development.js (UMD_DEV)": {
"size": 361649,
"gzip": 79069
"size": 356132,
"gzip": 78808
},
"react-art.production.min.js (UMD_PROD)": {
"size": 83540,
"gzip": 25716
"size": 83550,
"gzip": 25720
},
"react-art.development.js (NODE_DEV)": {
"size": 285841,
"gzip": 60122
"size": 280511,
"gzip": 59802
},
"react-art.production.min.js (NODE_PROD)": {
"size": 47425,
"gzip": 14826
"size": 47447,
"gzip": 14833
},
"ReactART-dev.js (FB_DEV)": {
"size": 285290,
"gzip": 60273
"size": 291930,
"gzip": 61727
},
"ReactART-prod.js (FB_PROD)": {
"size": 223089,
"gzip": 45921
"size": 146916,
"gzip": 25076
},
"ReactNativeRenderer-dev.js (RN_DEV)": {
"size": 264179,
"gzip": 45201
"size": 410167,
"gzip": 89963
},
"ReactNativeRenderer-prod.js (RN_PROD)": {
"size": 212604,
"gzip": 36247
"size": 200640,
"gzip": 34582
},
"ReactRTRenderer-dev.js (RN_DEV)": {
"size": 195908,
"gzip": 32822
"size": 286373,
"gzip": 60712
},
"ReactRTRenderer-prod.js (RN_PROD)": {
"size": 153400,
"gzip": 25311
"size": 137994,
"gzip": 23151
},
"ReactCSRenderer-dev.js (RN_DEV)": {
"size": 189445,
"gzip": 31430
"size": 277226,
"gzip": 57864
},
"ReactCSRenderer-prod.js (RN_PROD)": {
"size": 149120,
"gzip": 24267
"size": 130881,
"gzip": 21853
},
"react-test-renderer.development.js (NODE_DEV)": {
"size": 284278,
"gzip": 59193
"size": 278468,
"gzip": 58909
},
"react-test-renderer.production.min.js (NODE_PROD)": {
"size": 46027,
"gzip": 14218
"size": 46049,
"gzip": 14225
},
"ReactTestRenderer-dev.js (FB_DEV)": {
"size": 283739,
"gzip": 59348
"size": 289988,
"gzip": 60842
},
"react-test-renderer-shallow.development.js (NODE_DEV)": {
"size": 10659,
"gzip": 2682
"size": 9693,
"gzip": 2634
},
"react-test-renderer-shallow.production.min.js (NODE_PROD)": {
"size": 4850,
"gzip": 1791
"size": 4872,
"gzip": 1800
},
"ReactShallowRenderer-dev.js (FB_DEV)": {
"size": 10154,
"gzip": 2521
"size": 9917,
"gzip": 2596
},
"react-noop-renderer.development.js (NODE_DEV)": {
"size": 280242,
"gzip": 58186
"size": 274984,
"gzip": 57892
},
"react-reconciler.development.js (NODE_DEV)": {
"size": 265017,
"gzip": 54727
"size": 260419,
"gzip": 54546
},
"react-reconciler.production.min.js (NODE_PROD)": {
"size": 39270,
"gzip": 12270
"size": 39408,
"gzip": 12244
},
"react-call-return.development.js (NODE_DEV)": {
"size": 3050,
"gzip": 980
"size": 2521,
"gzip": 929
},
"react-call-return.production.min.js (NODE_PROD)": {
"size": 875,
"gzip": 505
"size": 897,
"gzip": 512
}
}
}
+199
View File
@@ -0,0 +1,199 @@
'use strict';
const Bundles = require('./bundles');
const reactVersion = require('../../package.json').version;
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
const FB_DEV = Bundles.bundleTypes.FB_DEV;
const FB_PROD = Bundles.bundleTypes.FB_PROD;
const RN_DEV = Bundles.bundleTypes.RN_DEV;
const RN_PROD = Bundles.bundleTypes.RN_PROD;
const RECONCILER = Bundles.moduleTypes.RECONCILER;
const license = ` * Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.`;
const wrappers = {
/***************** UMD_DEV *****************/
[UMD_DEV](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
'use strict';
${source}`;
},
/***************** UMD_PROD *****************/
[UMD_PROD](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
${source}`;
},
/***************** NODE_DEV *****************/
[NODE_DEV](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
'use strict';
if (process.env.NODE_ENV !== "production") {
(function() {
${source}
})();
}`;
},
/***************** NODE_PROD *****************/
[NODE_PROD](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
${source}`;
},
/****************** FB_DEV ******************/
[FB_DEV](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @providesModule ${globalName}-dev
* @preventMunge
*/
'use strict';
if (__DEV__) {
(function() {
${source}
})();
}`;
},
/****************** FB_PROD ******************/
[FB_PROD](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @providesModule ${globalName}-prod
* @preventMunge
*/
${source}`;
},
/****************** RN_DEV ******************/
[RN_DEV](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @providesModule ${globalName}-dev
* @preventMunge
*/
'use strict';
if (__DEV__) {
(function() {
${source}
})();
}`;
},
/****************** RN_DEV ******************/
[RN_PROD](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @providesModule ${globalName}-prod
* @preventMunge
*/
${source}`;
},
};
const reconcilerWrappers = {
/***************** NODE_DEV (reconciler only) *****************/
[NODE_DEV](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
'use strict';
if (process.env.NODE_ENV !== "production") {
// This is a hacky way to ensure third party renderers don't share
// top-level module state inside the reconciler. Ideally we should
// remove this hack by putting all top-level state into the closures
// and then forbidding adding more of it in the reconciler.
var $$$reconciler;
module.exports = function(config) {
${source}
return ($$$reconciler || ($$$reconciler = module.exports))(config);
};
}`;
},
/***************** NODE_PROD (reconciler only) *****************/
[NODE_PROD](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
var $$$reconciler;
module.exports = function(config) {
${source}
return ($$$reconciler || ($$$reconciler = module.exports))(config);
};`;
},
};
function wrapBundle(source, bundleType, globalName, filename, moduleType) {
if (moduleType === RECONCILER) {
// Standalone reconciler is only used by third-party renderers.
// It is handled separately.
const wrapper = reconcilerWrappers[bundleType];
if (typeof wrapper !== 'function') {
throw new Error(
`Unsupported build type for the reconciler package: ${bundleType}.`
);
}
return wrapper(source, globalName, filename, moduleType);
}
// All the other packages.
const wrapper = wrappers[bundleType];
if (typeof wrapper !== 'function') {
throw new Error(`Unsupported build type: ${bundleType}.`);
}
return wrapper(source, globalName, filename, moduleType);
}
module.exports = {
wrapBundle,
};
+53 -22
View File
@@ -1437,7 +1437,7 @@ detective@^4.3.1:
acorn "^4.0.3"
defined "^1.0.0"
diff@^3.2.0:
diff@3.3.0, diff@^3.2.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.0.tgz#056695150d7aa93237ca7e378ac3b1682b7963b9"
@@ -1798,6 +1798,13 @@ extglob@^0.3.1:
dependencies:
is-extglob "^1.0.0"
extract-banner@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/extract-banner/-/extract-banner-0.1.2.tgz#61d1ed5cce3acdadb35f4323910b420364241a7f"
dependencies:
strip-bom-string "^0.1.2"
strip-use-strict "^0.1.0"
extsprintf@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550"
@@ -2150,8 +2157,8 @@ glogg@^1.0.0:
sparkles "^1.0.0"
google-closure-compiler-js@>20170000:
version "20170626.0.0"
resolved "https://registry.yarnpkg.com/google-closure-compiler-js/-/google-closure-compiler-js-20170626.0.0.tgz#5df265b277d1ec6fdea12eed131d1491cd8a8d71"
version "20170910.0.1"
resolved "https://registry.yarnpkg.com/@gaearon/google-closure-compiler-js/-/google-closure-compiler-js-20170910.0.1.tgz#b0cf7ef408219a19c390375a76bf0a82ccf65eea"
dependencies:
minimist "^1.2.0"
vinyl "^2.0.1"
@@ -3208,6 +3215,18 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"
magic-string@0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.19.1.tgz#14d768013caf2ec8fdea16a49af82fc377e75201"
dependencies:
vlq "^0.2.1"
magic-string@0.22.4, magic-string@^0.22.4:
version "0.22.4"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.4.tgz#31039b4e40366395618c1d6cf8193c53917475ff"
dependencies:
vlq "^0.2.1"
magic-string@^0.15.2:
version "0.15.2"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.15.2.tgz#0681d7388741bbc3addaa65060992624c6c09e9c"
@@ -3220,12 +3239,6 @@ magic-string@^0.16.0:
dependencies:
vlq "^0.2.1"
magic-string@^0.22.4:
version "0.22.4"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.4.tgz#31039b4e40366395618c1d6cf8193c53917475ff"
dependencies:
vlq "^0.2.1"
makeerror@1.0.x:
version "1.0.11"
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c"
@@ -3671,7 +3684,7 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@1.8.1:
prettier@1.8.1, prettier@^1.0.0:
version "1.8.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.8.1.tgz#91064d778c08c85ac1cbe6b23195c34310d039f9"
@@ -4104,6 +4117,14 @@ rollup-plugin-node-resolve@^2.0.0:
builtin-modules "^1.1.0"
resolve "^1.1.6"
rollup-plugin-prettier@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-prettier/-/rollup-plugin-prettier-0.3.0.tgz#1000df8a2914d367b79507c1caa582fdbed8b0f3"
dependencies:
diff "3.3.0"
magic-string "0.22.4"
prettier "^1.0.0"
rollup-plugin-replace@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-replace/-/rollup-plugin-replace-1.1.1.tgz#396315ded050a6ce43b9518a886a3f60efb1ea33"
@@ -4112,11 +4133,20 @@ rollup-plugin-replace@^1.1.1:
minimatch "^3.0.2"
rollup-pluginutils "^1.5.0"
rollup-plugin-uglify@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-1.0.2.tgz#d4aa6f5df13522eae1ba17780c7c4c7096038359"
rollup-plugin-strip-banner@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-strip-banner/-/rollup-plugin-strip-banner-0.2.0.tgz#d5c86979c7871427f9d7f797e09a493750769fd4"
dependencies:
uglify-js "^2.6.1"
extract-banner "0.1.2"
magic-string "0.19.1"
rollup-pluginutils "2.0.1"
rollup-pluginutils@2.0.1, rollup-pluginutils@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.0.1.tgz#7ec95b3573f6543a46a6461bd9a7c544525d0fc0"
dependencies:
estree-walker "^0.3.0"
micromatch "^2.3.11"
rollup-pluginutils@^1.2.0, rollup-pluginutils@^1.5.0:
version "1.5.2"
@@ -4125,13 +4155,6 @@ rollup-pluginutils@^1.2.0, rollup-pluginutils@^1.5.0:
estree-walker "^0.2.1"
minimatch "^3.0.2"
rollup-pluginutils@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.0.1.tgz#7ec95b3573f6543a46a6461bd9a7c544525d0fc0"
dependencies:
estree-walker "^0.3.0"
micromatch "^2.3.11"
rollup@^0.49.3:
version "0.49.3"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.49.3.tgz#4cce32643dd8cf2154c69ff0e43470067db0adbf"
@@ -4399,6 +4422,10 @@ strip-ansi@^4.0.0:
dependencies:
ansi-regex "^3.0.0"
strip-bom-string@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/strip-bom-string/-/strip-bom-string-0.1.2.tgz#9c6e720a313ba9836589518405ccfb88a5f41b9c"
strip-bom@3.0.0, strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
@@ -4417,6 +4444,10 @@ strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
strip-use-strict@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/strip-use-strict/-/strip-use-strict-0.1.0.tgz#e30e8fd2206834e41e5eb3f3dc1ea7a4e4258f5f"
supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
@@ -4600,7 +4631,7 @@ ua-parser-js@^0.7.9:
version "0.7.17"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"
uglify-js@^2.5.0, uglify-js@^2.6, uglify-js@^2.6.1:
uglify-js@^2.6:
version "2.8.22"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.22.tgz#d54934778a8da14903fa29a326fb24c0ab51a1a0"
dependencies: