2017-04-05 23:47:29 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const resolve = require('path').resolve;
|
|
|
|
|
const basename = require('path').basename;
|
|
|
|
|
const sync = require('glob').sync;
|
|
|
|
|
const bundleTypes = require('./bundles').bundleTypes;
|
|
|
|
|
const extractErrorCodes = require('../error-codes/extract-errors');
|
|
|
|
|
|
|
|
|
|
const exclude = [
|
|
|
|
|
'src/**/__benchmarks__/**/*.js',
|
|
|
|
|
'src/**/__tests__/**/*.js',
|
|
|
|
|
'src/**/__mocks__/**/*.js',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const UMD_DEV = bundleTypes.UMD_DEV;
|
|
|
|
|
const UMD_PROD = bundleTypes.UMD_PROD;
|
|
|
|
|
const NODE_DEV = bundleTypes.NODE_DEV;
|
|
|
|
|
const NODE_PROD = bundleTypes.NODE_PROD;
|
|
|
|
|
const FB_DEV = bundleTypes.FB_DEV;
|
|
|
|
|
const FB_PROD = bundleTypes.FB_PROD;
|
|
|
|
|
const RN_DEV = bundleTypes.RN_DEV;
|
|
|
|
|
const RN_PROD = bundleTypes.RN_PROD;
|
|
|
|
|
|
|
|
|
|
const errorCodeOpts = {
|
|
|
|
|
errorMapFilePath: 'scripts/error-codes/codes.json',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// these are the FBJS modules that are used throughout our bundles
|
|
|
|
|
const fbjsModules = [
|
|
|
|
|
'fbjs/lib/warning',
|
|
|
|
|
'fbjs/lib/invariant',
|
|
|
|
|
'fbjs/lib/emptyFunction',
|
|
|
|
|
'fbjs/lib/emptyObject',
|
|
|
|
|
'fbjs/lib/hyphenateStyleName',
|
|
|
|
|
'fbjs/lib/getUnboundedScrollPosition',
|
|
|
|
|
'fbjs/lib/camelizeStyleName',
|
|
|
|
|
'fbjs/lib/containsNode',
|
|
|
|
|
'fbjs/lib/shallowEqual',
|
|
|
|
|
'fbjs/lib/getActiveElement',
|
|
|
|
|
'fbjs/lib/focusNode',
|
|
|
|
|
'fbjs/lib/EventListener',
|
|
|
|
|
'fbjs/lib/memoizeStringOnly',
|
|
|
|
|
'fbjs/lib/ExecutionEnvironment',
|
|
|
|
|
'fbjs/lib/createNodesFromMarkup',
|
|
|
|
|
'fbjs/lib/performanceNow',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const devOnlyFilesToStubOut = [
|
2017-04-08 00:03:22 +08:00
|
|
|
"'ReactDebugCurrentFrame'",
|
2017-04-05 23:47:29 +08:00
|
|
|
"'ReactComponentTreeHook'",
|
2017-04-08 05:07:10 +08:00
|
|
|
"'ReactPerf'",
|
|
|
|
|
"'ReactTestUtils'",
|
2017-04-05 23:47:29 +08:00
|
|
|
];
|
|
|
|
|
|
2017-04-12 05:28:03 +08:00
|
|
|
const legacyModules = [
|
|
|
|
|
'create-react-class',
|
|
|
|
|
'create-react-class/factory',
|
|
|
|
|
'prop-types',
|
|
|
|
|
'prop-types/checkPropTypes',
|
|
|
|
|
];
|
|
|
|
|
|
2017-04-05 23:47:29 +08:00
|
|
|
// this function builds up a very niave Haste-like moduleMap
|
|
|
|
|
// that works to create up an alias map for modules to link
|
|
|
|
|
// up to their actual disk location so Rollup can properly
|
|
|
|
|
// bundle them
|
|
|
|
|
function createModuleMap(paths, extractErrors, bundleType) {
|
|
|
|
|
const moduleMap = {};
|
|
|
|
|
|
|
|
|
|
paths.forEach(path => {
|
2017-04-06 03:24:30 +08:00
|
|
|
const files = sync(path, {ignore: exclude});
|
2017-04-05 23:47:29 +08:00
|
|
|
|
|
|
|
|
files.forEach(file => {
|
|
|
|
|
if (extractErrors) {
|
|
|
|
|
extractErrors(file);
|
|
|
|
|
}
|
|
|
|
|
const moduleName = basename(file, '.js');
|
|
|
|
|
|
|
|
|
|
moduleMap[moduleName] = resolve(file);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-05-27 01:35:39 +08:00
|
|
|
// if this is FB, we want to remove ReactCurrentOwner and lowPriorityWarning,
|
|
|
|
|
// so we can handle it with a different case
|
2017-04-05 23:47:29 +08:00
|
|
|
if (bundleType === FB_DEV || bundleType === FB_PROD) {
|
|
|
|
|
delete moduleMap.ReactCurrentOwner;
|
2017-05-27 01:35:39 +08:00
|
|
|
delete moduleMap.lowPriorityWarning;
|
2017-04-05 23:47:29 +08:00
|
|
|
}
|
|
|
|
|
return moduleMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getNodeModules(bundleType) {
|
|
|
|
|
// rather than adding the rollup node resolve plugin,
|
|
|
|
|
// we can instead deal with the only node module that is used
|
|
|
|
|
// for UMD bundles - object-assign
|
|
|
|
|
switch (bundleType) {
|
|
|
|
|
case UMD_DEV:
|
|
|
|
|
case UMD_PROD:
|
|
|
|
|
return {
|
|
|
|
|
'object-assign': resolve('./node_modules/object-assign/index.js'),
|
|
|
|
|
// include the ART package modules directly by aliasing them from node_modules
|
|
|
|
|
'art/modes/current': resolve('./node_modules/art/modes/current.js'),
|
|
|
|
|
'art/modes/fast-noSideEffects': resolve(
|
|
|
|
|
'./node_modules/art/modes/fast-noSideEffects.js'
|
|
|
|
|
),
|
|
|
|
|
'art/core/transform': resolve('./node_modules/art/core/transform.js'),
|
|
|
|
|
};
|
|
|
|
|
case NODE_DEV:
|
|
|
|
|
case NODE_PROD:
|
|
|
|
|
case FB_DEV:
|
|
|
|
|
case FB_PROD:
|
|
|
|
|
case RN_DEV:
|
|
|
|
|
case RN_PROD:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ignoreFBModules() {
|
|
|
|
|
return [
|
|
|
|
|
// At FB, we don't know them statically:
|
|
|
|
|
'ReactFeatureFlags',
|
|
|
|
|
'ReactDOMFeatureFlags',
|
|
|
|
|
// In FB bundles, we preserve an inline require to ReactCurrentOwner.
|
|
|
|
|
// See the explanation in FB version of ReactCurrentOwner in www:
|
|
|
|
|
'ReactCurrentOwner',
|
2017-05-27 01:35:39 +08:00
|
|
|
'lowPriorityWarning',
|
2017-04-05 23:47:29 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ignoreReactNativeModules() {
|
|
|
|
|
return [
|
|
|
|
|
// This imports NativeMethodsMixin, causing
|
|
|
|
|
// a circular dependency.
|
|
|
|
|
'View',
|
2017-06-15 05:10:33 +08:00
|
|
|
// We have a shim for this file.
|
|
|
|
|
'ReactNativeFeatureFlags',
|
2017-04-05 23:47:29 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getExternalModules(externals, bundleType, isRenderer) {
|
|
|
|
|
// external modules tell Rollup that we should not attempt
|
|
|
|
|
// to bundle these modules and instead treat them as
|
|
|
|
|
// external depedencies to the bundle. so for CJS bundles
|
|
|
|
|
// this means having a require("name-of-external-module") at
|
|
|
|
|
// the top of the bundle. for UMD bundles this means having
|
|
|
|
|
// both a require and a global check for them
|
|
|
|
|
let externalModules = externals;
|
|
|
|
|
|
|
|
|
|
switch (bundleType) {
|
|
|
|
|
case UMD_DEV:
|
|
|
|
|
case UMD_PROD:
|
|
|
|
|
if (isRenderer) {
|
|
|
|
|
externalModules.push('react');
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NODE_DEV:
|
|
|
|
|
case NODE_PROD:
|
|
|
|
|
case RN_DEV:
|
|
|
|
|
case RN_PROD:
|
|
|
|
|
fbjsModules.forEach(module => externalModules.push(module));
|
|
|
|
|
externalModules.push('object-assign');
|
|
|
|
|
|
|
|
|
|
if (isRenderer) {
|
|
|
|
|
externalModules.push('react');
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FB_DEV:
|
|
|
|
|
case FB_PROD:
|
|
|
|
|
fbjsModules.forEach(module => externalModules.push(module));
|
2017-04-08 05:07:10 +08:00
|
|
|
externalModules.push('ReactCurrentOwner');
|
Downgrade deprecation warnings from errors to warnings (#9650)
* Initial regeneration of results.json
**what is the change?:**
We ran `yarn build` and updated the perf. stats record.
**why make this change?:**
Some commits have landed without updating this. By getting an initial update, I can run the build script again after my changes and see any size regressions.
* Downgrade deprecation warnings from errors to warnings
**what is the change?:**
Swapping out `warning` module for a fork that uses `console.warn`.
It looks like we were using the `warning` module for deprecation notices, *but* there is also a 'deprecated' module designed specifically for deprecation notices.
However, we could not find any place that it was currently used.
Since React's build process is not 100% clear to me, I assume it could still be used somewhere by something and just updated it along with other deprecation notices.
We might consider a follow-up diff that does some clean up here;
- remove 'deprecated' module if it's unused, OR
- use 'deprecated' module for all our current deprecation warnings
**why make this change?:**
- We have had complaints about noisy warnings, in particular after introducing new deprecations
- They potentially cause CI failures
- Deprecations are not really time-sensitive, can ship without breaking your app, etc.
For more context - https://github.com/facebook/react/issues/9395
**test plan:**
`npm run test`
and unit tests for the new modules
and manual testing (WIP)
**issue:**
https://github.com/facebook/react/issues/9395
* Add 'lowPriorityWarning' to ReactExternals
**what is the change?:**
We won't bundle 'lowPriorityWarning' with the rest of React when building for Facebook.
NOTE: A parallel commit will introduce an internal implementation of 'lowPriorityWarning' in Facebook's codebase, to compensate. Will post a comment with the diff number once that is up.
**why make this change?:**
So that the sync between github and Facebook can go more smoothly!
**test plan:**
We will see when I run the sync! But this is a reasonable first step imo.
**issue:**
https://github.com/facebook/react/issues/9398
* Make state mutations an error, not low-pri warning
**what is the change?:**
Even though this is a "deprecation" warning, we still want to use 'console.error' for it.
**why make this change?:**
- It's not likely to come up now, hopefully, because this warning has been present for some time
- This will cause real issues in production if ignored
**test plan:**
`yarn test` - we did fix one test which failed bc of this change
**issue:**
https://github.com/facebook/react/issues/9398
* Fix test of assigning to this.state that was only passing in fiber
**what is the change?:**
updated a unit test for assigning directly to state; it once again raises an error and not a warning.
**why make this change?:**
So that tests pass
**test plan:**
REACT_DOM_JEST_USE_FIBER=1 yarn run test
**issue:**
* Update results.json
2017-05-24 00:35:42 +08:00
|
|
|
externalModules.push('lowPriorityWarning');
|
2017-04-05 23:47:29 +08:00
|
|
|
if (isRenderer) {
|
|
|
|
|
externalModules.push('React');
|
2017-04-27 09:10:19 +08:00
|
|
|
if (externalModules.indexOf('react-dom') > -1) {
|
2017-04-27 09:07:53 +08:00
|
|
|
externalModules.push('ReactDOM');
|
|
|
|
|
}
|
2017-04-05 23:47:29 +08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return externalModules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInternalModules() {
|
|
|
|
|
// we tell Rollup where these files are located internally, otherwise
|
|
|
|
|
// it doesn't pick them up and assumes they're external
|
|
|
|
|
return {
|
|
|
|
|
reactProdInvariant: resolve('./src/shared/utils/reactProdInvariant.js'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFbjsModuleAliases(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
|
|
|
|
case UMD_DEV:
|
|
|
|
|
case UMD_PROD:
|
|
|
|
|
// we want to bundle these modules, so we re-alias them to the actual
|
|
|
|
|
// file so Rollup can bundle them up
|
|
|
|
|
const fbjsModulesAlias = {};
|
|
|
|
|
fbjsModules.forEach(fbjsModule => {
|
|
|
|
|
fbjsModulesAlias[fbjsModule] = resolve(`./node_modules/${fbjsModule}`);
|
|
|
|
|
});
|
|
|
|
|
return fbjsModulesAlias;
|
|
|
|
|
case NODE_DEV:
|
|
|
|
|
case NODE_PROD:
|
|
|
|
|
case FB_DEV:
|
|
|
|
|
case FB_PROD:
|
|
|
|
|
case RN_DEV:
|
|
|
|
|
case RN_PROD:
|
|
|
|
|
// for FB we don't want to bundle the above modules, instead keep them
|
|
|
|
|
// as external require() calls in the bundle
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceFbjsModuleAliases(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
|
|
|
|
case FB_DEV:
|
|
|
|
|
case FB_PROD:
|
2017-04-08 05:07:10 +08:00
|
|
|
// Haste at FB doesn't currently allow case sensitive names,
|
|
|
|
|
// and product code already uses "React". In the future,
|
|
|
|
|
// we will either allow both variants or migrate to lowercase.
|
2017-04-05 23:47:29 +08:00
|
|
|
return {
|
|
|
|
|
"'react'": "'React'",
|
2017-04-26 04:30:48 +08:00
|
|
|
"'react-dom'": "'ReactDOM'",
|
2017-04-05 23:47:29 +08:00
|
|
|
};
|
2017-04-08 05:07:10 +08:00
|
|
|
default:
|
|
|
|
|
return {};
|
2017-04-08 00:03:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 23:47:29 +08:00
|
|
|
const devOnlyModuleStub = `'${resolve('./scripts/rollup/shims/rollup/DevOnlyStubShim.js')}'`;
|
|
|
|
|
|
|
|
|
|
function replaceDevOnlyStubbedModules(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
|
|
|
|
case UMD_DEV:
|
|
|
|
|
case NODE_DEV:
|
|
|
|
|
case FB_DEV:
|
|
|
|
|
case RN_DEV:
|
|
|
|
|
case RN_PROD:
|
|
|
|
|
return {};
|
|
|
|
|
case FB_PROD:
|
|
|
|
|
case UMD_PROD:
|
|
|
|
|
case NODE_PROD:
|
|
|
|
|
const devOnlyModuleAliases = {};
|
|
|
|
|
devOnlyFilesToStubOut.forEach(devOnlyModule => {
|
|
|
|
|
devOnlyModuleAliases[devOnlyModule] = devOnlyModuleStub;
|
|
|
|
|
});
|
|
|
|
|
return devOnlyModuleAliases;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-12 05:28:03 +08:00
|
|
|
function replaceLegacyModuleAliases(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
|
|
|
|
case UMD_DEV:
|
|
|
|
|
case UMD_PROD:
|
|
|
|
|
const modulesAlias = {};
|
|
|
|
|
legacyModules.forEach(legacyModule => {
|
|
|
|
|
const modulePath = legacyModule.includes('/')
|
|
|
|
|
? legacyModule
|
|
|
|
|
: `${legacyModule}/index`;
|
|
|
|
|
const resolvedPath = resolve(`./node_modules/${modulePath}`);
|
|
|
|
|
modulesAlias[`'${legacyModule}'`] = `'${resolvedPath}'`;
|
|
|
|
|
});
|
|
|
|
|
return modulesAlias;
|
|
|
|
|
case NODE_DEV:
|
|
|
|
|
case NODE_PROD:
|
|
|
|
|
case FB_DEV:
|
|
|
|
|
case FB_PROD:
|
|
|
|
|
case RN_DEV:
|
|
|
|
|
case RN_PROD:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 01:14:46 +08:00
|
|
|
function replaceBundleStubModules(bundleModulesToStub) {
|
|
|
|
|
const stubbedModules = {};
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(bundleModulesToStub)) {
|
|
|
|
|
bundleModulesToStub.forEach(module => {
|
2017-07-19 23:28:55 +08:00
|
|
|
stubbedModules[`'${module}'`] = devOnlyModuleStub;
|
2017-05-26 01:14:46 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stubbedModules;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 23:47:29 +08:00
|
|
|
function getAliases(paths, bundleType, isRenderer, extractErrors) {
|
|
|
|
|
return Object.assign(
|
|
|
|
|
createModuleMap(
|
|
|
|
|
paths,
|
|
|
|
|
extractErrors && extractErrorCodes(errorCodeOpts),
|
|
|
|
|
bundleType
|
|
|
|
|
),
|
|
|
|
|
getInternalModules(),
|
|
|
|
|
getNodeModules(bundleType),
|
|
|
|
|
getFbjsModuleAliases(bundleType)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 01:14:46 +08:00
|
|
|
function getDefaultReplaceModules(bundleType, bundleModulesToStub) {
|
2017-04-05 23:47:29 +08:00
|
|
|
return Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
replaceFbjsModuleAliases(bundleType),
|
2017-04-12 05:28:03 +08:00
|
|
|
replaceDevOnlyStubbedModules(bundleType),
|
2017-05-26 01:14:46 +08:00
|
|
|
replaceLegacyModuleAliases(bundleType),
|
|
|
|
|
replaceBundleStubModules(bundleModulesToStub)
|
2017-04-05 23:47:29 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 02:51:19 +08:00
|
|
|
function getExcludedHasteGlobs() {
|
|
|
|
|
return exclude;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 23:47:29 +08:00
|
|
|
module.exports = {
|
2017-04-06 02:51:19 +08:00
|
|
|
getExcludedHasteGlobs,
|
2017-04-05 23:47:29 +08:00
|
|
|
getDefaultReplaceModules,
|
|
|
|
|
getAliases,
|
|
|
|
|
ignoreFBModules,
|
|
|
|
|
ignoreReactNativeModules,
|
|
|
|
|
getExternalModules,
|
|
|
|
|
};
|