2017-11-09 06:37:11 +08:00
|
|
|
'use strict';
|
|
|
|
|
2020-02-04 07:31:31 +08:00
|
|
|
const {bundleTypes, moduleTypes} = require('./bundles');
|
2017-11-09 06:37:11 +08:00
|
|
|
const reactVersion = require('../../package.json').version;
|
|
|
|
|
2020-02-04 07:31:31 +08:00
|
|
|
const {
|
|
|
|
UMD_DEV,
|
|
|
|
UMD_PROD,
|
|
|
|
UMD_PROFILING,
|
|
|
|
NODE_DEV,
|
|
|
|
NODE_PROD,
|
|
|
|
NODE_PROFILING,
|
|
|
|
FB_WWW_DEV,
|
|
|
|
FB_WWW_PROD,
|
|
|
|
FB_WWW_PROFILING,
|
|
|
|
RN_OSS_DEV,
|
|
|
|
RN_OSS_PROD,
|
|
|
|
RN_OSS_PROFILING,
|
|
|
|
RN_FB_DEV,
|
|
|
|
RN_FB_PROD,
|
|
|
|
RN_FB_PROFILING,
|
|
|
|
} = bundleTypes;
|
2017-11-09 06:37:11 +08:00
|
|
|
|
2020-02-04 07:31:31 +08:00
|
|
|
const {RECONCILER} = moduleTypes;
|
2017-11-09 06:37:11 +08:00
|
|
|
|
2018-09-08 06:11:23 +08:00
|
|
|
const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
|
2017-11-09 06:37:11 +08:00
|
|
|
*
|
|
|
|
* 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}`;
|
|
|
|
},
|
|
|
|
|
2018-09-14 08:44:08 +08:00
|
|
|
/***************** UMD_PROFILING *****************/
|
|
|
|
[UMD_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
/***************** NODE_DEV *****************/
|
|
|
|
[NODE_DEV](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-11-24 01:44:58 +08:00
|
|
|
${
|
2020-01-09 21:54:11 +08:00
|
|
|
globalName === 'ReactNoopRenderer' ||
|
|
|
|
globalName === 'ReactNoopRendererPersistent'
|
|
|
|
? // React Noop needs regenerator runtime because it uses
|
|
|
|
// generators but GCC doesn't handle them in the output.
|
|
|
|
// So we use Babel for them.
|
|
|
|
`const regeneratorRuntime = require("regenerator-runtime");`
|
|
|
|
: ``
|
|
|
|
}
|
2017-11-24 01:44:58 +08:00
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** NODE_PROD *****************/
|
|
|
|
[NODE_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
2017-11-24 01:44:58 +08:00
|
|
|
${
|
2020-01-09 21:54:11 +08:00
|
|
|
globalName === 'ReactNoopRenderer' ||
|
|
|
|
globalName === 'ReactNoopRendererPersistent'
|
|
|
|
? // React Noop needs regenerator runtime because it uses
|
|
|
|
// generators but GCC doesn't handle them in the output.
|
|
|
|
// So we use Babel for them.
|
|
|
|
`const regeneratorRuntime = require("regenerator-runtime");`
|
|
|
|
: ``
|
|
|
|
}
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2018-06-12 04:16:27 +08:00
|
|
|
/***************** NODE_PROFILING *****************/
|
|
|
|
[NODE_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
${
|
2020-01-09 21:54:11 +08:00
|
|
|
globalName === 'ReactNoopRenderer' ||
|
|
|
|
globalName === 'ReactNoopRendererPersistent'
|
|
|
|
? // React Noop needs regenerator runtime because it uses
|
|
|
|
// generators but GCC doesn't handle them in the output.
|
|
|
|
// So we use Babel for them.
|
|
|
|
`const regeneratorRuntime = require("regenerator-runtime");`
|
|
|
|
: ``
|
|
|
|
}
|
2018-06-12 04:16:27 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** FB_WWW_DEV ******************/
|
|
|
|
[FB_WWW_DEV](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @preventMunge
|
2018-04-10 01:57:52 +08:00
|
|
|
* @preserve-invariant-messages
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** FB_WWW_PROD ******************/
|
|
|
|
[FB_WWW_PROD](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @preventMunge
|
2018-04-10 01:57:52 +08:00
|
|
|
* @preserve-invariant-messages
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-27 04:28:41 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** FB_WWW_PROFILING ******************/
|
|
|
|
[FB_WWW_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-06-27 04:28:41 +08:00
|
|
|
* @preventMunge
|
|
|
|
* @preserve-invariant-messages
|
|
|
|
*/
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** RN_OSS_DEV ******************/
|
|
|
|
[RN_OSS_DEV](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @providesModule ${globalName}-dev
|
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** RN_OSS_PROD ******************/
|
|
|
|
[RN_OSS_PROD](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @providesModule ${globalName}-prod
|
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-12 04:16:27 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_OSS_PROFILING ******************/
|
|
|
|
[RN_OSS_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-06-12 04:16:27 +08:00
|
|
|
* @providesModule ${globalName}-profiling
|
|
|
|
* @preventMunge
|
|
|
|
* ${'@gen' + 'erated'}
|
|
|
|
*/
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_FB_DEV ******************/
|
|
|
|
[RN_FB_DEV](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-04-19 04:16:50 +08:00
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2018-04-19 04:16:50 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_FB_PROD ******************/
|
|
|
|
[RN_FB_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-04-19 04:16:50 +08:00
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2018-04-19 04:16:50 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-27 04:28:41 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_FB_PROFILING ******************/
|
|
|
|
[RN_FB_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-06-27 04:28:41 +08:00
|
|
|
* @preventMunge
|
|
|
|
* ${'@gen' + 'erated'}
|
|
|
|
*/
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
${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") {
|
2018-05-19 18:29:11 +08:00
|
|
|
module.exports = function $$$reconciler($$$hostConfig) {
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}
|
2018-05-19 18:29:11 +08:00
|
|
|
var $$$renderer = module.exports;
|
|
|
|
module.exports = $$$reconciler;
|
|
|
|
return $$$renderer;
|
2017-11-09 06:37:11 +08:00
|
|
|
};
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** NODE_PROD (reconciler only) *****************/
|
|
|
|
[NODE_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
2018-05-19 18:29:11 +08:00
|
|
|
module.exports = function $$$reconciler($$$hostConfig) {
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}
|
2018-05-19 18:29:11 +08:00
|
|
|
var $$$renderer = module.exports;
|
|
|
|
module.exports = $$$reconciler;
|
|
|
|
return $$$renderer;
|
2017-11-09 06:37:11 +08:00
|
|
|
};`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|