Files
react/scripts/rollup/bundles.js
Dan Abramov 1eed302d34 Drop Haste (#11303)
* Use relative paths in packages/react

* Use relative paths in packages/react-art

* Use relative paths in packages/react-cs

* Use relative paths in other packages

* Fix as many issues as I can

This uncovered an interesting problem where ./b from package/src/a would resolve to a different instantiation of package/src/b in Jest.

Either this is a showstopper or we can solve it by completely fobbidding remaining /src/.

* Fix all tests

It seems we can't use relative requires in tests anymore. Otherwise Jest becomes confused between real file and symlink.
https://github.com/facebook/jest/issues/3830

This seems bad... Except that we already *don't* want people to create tests that import individual source files.
All existing cases of us doing so are actually TODOs waiting to be fixed.

So perhaps this requirement isn't too bad because it makes bad code looks bad.

Of course, if we go with this, we'll have to lint against relative requires in tests.
It also makes moving things more painful.

* Prettier

* Remove @providesModule

* Fix remaining Haste imports I missed earlier

* Fix up paths to reflect new flat structure

* Fix Flow

* Fix CJS and UMD builds

* Fix FB bundles

* Fix RN bundles

* Prettier

* Fix lint

* Fix warning printing and error codes

* Fix buggy return

* Fix lint and Flow

* Use Yarn on CI

* Unbreak Jest

* Fix lint

* Fix aliased originals getting included in DEV

Shouldn't affect correctness (they were ignored) but fixes DEV size regression.

* Record sizes

* Fix weird version in package.json

* Tweak bundle labels

* Get rid of output option by introducing react-dom/server.node

* Reconciler should depend on prop-types

* Update sizes last time
2017-10-25 02:55:00 +03:00

224 lines
5.4 KiB
JavaScript

'use strict';
const bundleTypes = {
UMD_DEV: 'UMD_DEV',
UMD_PROD: 'UMD_PROD',
NODE_DEV: 'NODE_DEV',
NODE_PROD: 'NODE_PROD',
FB_DEV: 'FB_DEV',
FB_PROD: 'FB_PROD',
RN_DEV: 'RN_DEV',
RN_PROD: 'RN_PROD',
};
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 moduleTypes = {
ISOMORPHIC: 'ISOMORPHIC',
RENDERER: 'RENDERER',
RENDERER_UTILS: 'RENDERER_UTILS',
RECONCILER: 'RECONCILER',
};
// React
const ISOMORPHIC = moduleTypes.ISOMORPHIC;
// Individual renderers. They bundle the reconciler. (e.g. ReactDOM)
const RENDERER = moduleTypes.RENDERER;
// Helper packages that access specific renderer's internals. (e.g. TestUtils)
const RENDERER_UTILS = moduleTypes.RENDERER_UTILS;
// Standalone reconciler for third-party renderers.
const RECONCILER = moduleTypes.RECONCILER;
const bundles = [
/******* Isomorphic *******/
{
label: 'core',
bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD],
moduleType: ISOMORPHIC,
entry: 'react',
global: 'React',
externals: [],
},
/******* React DOM *******/
{
label: 'dom-client',
bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD],
moduleType: RENDERER,
entry: 'react-dom',
global: 'ReactDOM',
externals: ['react'],
},
//******* Test Utils *******/
{
label: 'dom-test-utils',
moduleType: RENDERER_UTILS,
bundleTypes: [FB_DEV, NODE_DEV, NODE_PROD],
entry: 'react-dom/test-utils',
global: 'ReactTestUtils',
externals: ['react', 'react-dom'],
},
/* React DOM internals required for react-native-web (e.g., to shim native events from react-dom) */
{
label: 'dom-unstable-native-dependencies',
bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD],
moduleType: RENDERER_UTILS,
entry: 'react-dom/unstable-native-dependencies',
global: 'ReactDOMUnstableNativeDependencies',
externals: ['react', 'react-dom'],
},
/******* React DOM Server *******/
{
label: 'dom-server-browser',
bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD],
moduleType: RENDERER,
entry: 'react-dom/server.browser',
global: 'ReactDOMServer',
externals: ['react'],
},
{
label: 'dom-server-node',
bundleTypes: [NODE_DEV, NODE_PROD],
moduleType: RENDERER,
entry: 'react-dom/server.node',
externals: ['react', 'stream'],
},
/******* React ART *******/
{
label: 'art',
bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD],
moduleType: RENDERER,
entry: 'react-art',
global: 'ReactART',
externals: ['react'],
babel: opts =>
Object.assign({}, opts, {
// Include JSX
presets: opts.presets.concat([require.resolve('babel-preset-react')]),
}),
},
/******* React Native *******/
{
label: 'native',
bundleTypes: [RN_DEV, RN_PROD],
moduleType: RENDERER,
entry: 'react-native-renderer',
global: 'ReactNativeRenderer',
externals: [
'ExceptionsManager',
'InitializeCore',
'Platform',
'RCTEventEmitter',
'TextInputState',
'UIManager',
'View',
'deepDiffer',
'deepFreezeAndThrowOnMutationInDev',
'flattenStyle',
],
},
/******* React Native RT *******/
{
label: 'native-rt',
bundleTypes: [RN_DEV, RN_PROD],
moduleType: RENDERER,
entry: 'react-rt-renderer',
global: 'ReactRTRenderer',
externals: [
'ExceptionsManager',
'InitializeCore',
'Platform',
'BatchedBridge',
'RTManager',
],
},
/******* React Native CS *******/
{
label: 'native-cs',
bundleTypes: [RN_DEV, RN_PROD],
moduleType: RENDERER,
entry: 'react-cs-renderer',
global: 'ReactCSRenderer',
externals: [],
featureFlags: 'react-cs-renderer/src/ReactNativeCSFeatureFlags',
},
/******* React Test Renderer *******/
{
label: 'test',
bundleTypes: [FB_DEV, NODE_DEV, NODE_PROD],
moduleType: RENDERER,
entry: 'react-test-renderer',
global: 'ReactTestRenderer',
externals: ['react'],
},
{
label: 'test-shallow',
bundleTypes: [FB_DEV, NODE_DEV, NODE_PROD],
moduleType: RENDERER,
entry: 'react-test-renderer/shallow',
global: 'ReactShallowRenderer',
externals: ['react'],
},
/******* React Noop Renderer (used only for fixtures/fiber-debugger) *******/
{
label: 'noop',
bundleTypes: [NODE_DEV],
moduleType: RENDERER,
entry: 'react-noop-renderer',
global: 'ReactNoopRenderer',
externals: ['react', 'jest-matchers'],
},
/******* React Reconciler *******/
{
label: 'react-reconciler',
bundleTypes: [NODE_DEV, NODE_PROD],
moduleType: RECONCILER,
entry: 'react-reconciler',
global: 'ReactReconciler',
externals: ['react'],
},
];
// Based on deep-freeze by substack (public domain)
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function(prop) {
if (
o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])
) {
deepFreeze(o[prop]);
}
});
return o;
}
// Don't accidentally mutate config as part of the build
deepFreeze(bundles);
module.exports = {
bundleTypes,
moduleTypes,
bundles,
};