Skip to content

Commit d995587

Browse files
committed
Build renderers into their individual npm packages
This copies modules into three separate packages instead of putting it all in React. The overlap in shared and between renderers gets duplicated. This allows the isomorphic package to stay minimal. It can also be used as a direct dependency without much risk. This also allow us to ship versions to each renderer independently and we can ship renderers without updating the main react package dependency.
1 parent c06a68a commit d995587

File tree

17 files changed

+237
-42
lines changed

17 files changed

+237
-42
lines changed

grunt/config/browserify.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'});
1616

1717
var SECRET_INTERNALS_NAME = 'React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED';
1818

19-
var shimSharedModules = globalShim.configure({
19+
var shimSharedModulesFiles = {
2020
'./ReactCurrentOwner': SECRET_INTERNALS_NAME + '.ReactCurrentOwner',
2121
'./ReactComponentTreeHook': SECRET_INTERNALS_NAME + '.ReactComponentTreeHook',
2222
// The methods we used here are exposed on the main React export.
@@ -26,7 +26,14 @@ var shimSharedModules = globalShim.configure({
2626
'./ReactElement': 'React',
2727
'./ReactPropTypes': 'React.PropTypes',
2828
'./ReactChildren': 'React.Children',
29-
});
29+
};
30+
31+
// We can access these as absolute or relative. We need to shim both.
32+
for (var key in shimSharedModulesFiles) {
33+
shimSharedModulesFiles[key.replace(/^\.\//, 'react/lib/')] = shimSharedModulesFiles[key];
34+
}
35+
36+
var shimSharedModules = globalShim.configure(shimSharedModulesFiles);
3037

3138
var shimDOMModules = aliasify.configure({
3239
'aliases': {
@@ -72,7 +79,7 @@ function simpleBannerify(src) {
7279
// Our basic config which we'll add to to make our other builds
7380
var basic = {
7481
entries: [
75-
'./build/modules/ReactUMDEntry.js',
82+
'./build/node_modules/react/lib/ReactUMDEntry.js',
7683
],
7784
outfile: './build/react.js',
7885
debug: false,
@@ -85,7 +92,7 @@ var basic = {
8592

8693
var min = {
8794
entries: [
88-
'./build/modules/ReactUMDEntry.js',
95+
'./build/node_modules/react/lib/ReactUMDEntry.js',
8996
],
9097
outfile: './build/react.min.js',
9198
debug: false,
@@ -103,7 +110,7 @@ var min = {
103110

104111
var addons = {
105112
entries: [
106-
'./build/modules/ReactWithAddonsUMDEntry.js',
113+
'./build/node_modules/react/lib/ReactWithAddonsUMDEntry.js',
107114
],
108115
outfile: './build/react-with-addons.js',
109116
debug: false,
@@ -117,7 +124,7 @@ var addons = {
117124

118125
var addonsMin = {
119126
entries: [
120-
'./build/modules/ReactWithAddonsUMDEntry.js',
127+
'./build/node_modules/react/lib/ReactWithAddonsUMDEntry.js',
121128
],
122129
outfile: './build/react-with-addons.min.js',
123130
debug: false,
@@ -135,7 +142,7 @@ var addonsMin = {
135142
// The DOM Builds
136143
var dom = {
137144
entries: [
138-
'./build/modules/ReactDOMUMDEntry.js',
145+
'./build/node_modules/react-dom/lib/ReactDOMUMDEntry.js',
139146
],
140147
outfile: './build/react-dom.js',
141148
debug: false,
@@ -149,7 +156,7 @@ var dom = {
149156

150157
var domMin = {
151158
entries: [
152-
'./build/modules/ReactDOMUMDEntry.js',
159+
'./build/node_modules/react-dom/lib/ReactDOMUMDEntry.js',
153160
],
154161
outfile: './build/react-dom.min.js',
155162
debug: false,
@@ -167,7 +174,7 @@ var domMin = {
167174

168175
var domServer = {
169176
entries: [
170-
'./build/modules/ReactDOMServerUMDEntry.js',
177+
'./build/node_modules/react-dom/lib/ReactDOMServerUMDEntry.js',
171178
],
172179
outfile: './build/react-dom-server.js',
173180
debug: false,
@@ -181,7 +188,7 @@ var domServer = {
181188

182189
var domServerMin = {
183190
entries: [
184-
'./build/modules/ReactDOMServerUMDEntry.js',
191+
'./build/node_modules/react-dom/lib/ReactDOMServerUMDEntry.js',
185192
],
186193
outfile: './build/react-dom-server.min.js',
187194
debug: false,

grunt/tasks/npm-react-addons.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,55 @@ var path = require('path');
66

77
var addons = {
88
CSSTransitionGroup: {
9+
peerDependency: 'react',
910
module: 'ReactCSSTransitionGroup',
1011
name: 'css-transition-group',
1112
docs: 'animation',
1213
},
1314
LinkedStateMixin: {
15+
peerDependency: 'react',
1416
module: 'LinkedStateMixin',
1517
name: 'linked-state-mixin',
1618
docs: 'two-way-binding-helpers',
1719
},
1820
Perf: {
21+
peerDependency: 'react-dom',
1922
module: 'ReactPerf',
2023
name: 'perf',
2124
docs: 'perf',
2225
},
2326
PureRenderMixin: {
27+
peerDependency: 'react',
2428
module: 'ReactComponentWithPureRenderMixin',
2529
name: 'pure-render-mixin',
2630
docs: 'pure-render-mixin',
2731
},
2832
TestUtils: {
33+
peerDependency: 'react-dom',
2934
module: 'ReactTestUtils',
3035
name: 'test-utils',
3136
docs: 'test-utils',
3237
},
3338
TransitionGroup: {
39+
peerDependency: 'react',
3440
module: 'ReactTransitionGroup',
3541
name: 'transition-group',
3642
docs: 'animation',
3743
},
3844
createFragment: {
45+
peerDependency: 'react',
3946
module: 'ReactFragment',
4047
method: 'create',
4148
name: 'create-fragment',
4249
docs: 'create-fragment',
4350
},
4451
shallowCompare: {
52+
peerDependency: 'react',
4553
module: 'shallowCompare',
4654
name: 'shallow-compare',
4755
},
4856
updates: {
57+
peerDependency: 'react',
4958
module: 'update',
5059
name: 'update',
5160
docs: 'update',
@@ -54,9 +63,11 @@ var addons = {
5463

5564
function generateSource(info) {
5665
var pieces = [
57-
"module.exports = require('react/lib/",
66+
'module.exports = require(\'',
67+
info.peerDependency,
68+
'/lib/',
5869
info.module,
59-
"')",
70+
'\')',
6071
];
6172
if (info.method) {
6273
pieces.push('.', info.method);
@@ -78,6 +89,12 @@ function buildReleases() {
7889
var pkgData = Object.assign({}, pkgTemplate);
7990
pkgData.name = pkgName;
8091

92+
var version = pkgTemplate.peerDependencies.react;
93+
if (info.peerDependency !== 'react') {
94+
pkgData.peerDependencies = {};
95+
pkgData.peerDependencies[info.peerDependency] = version;
96+
}
97+
8198
grunt.file.mkdir(destDir);
8299
var link = info.docs ? info.docs : 'addons';
83100
link = `https://facebook.github.io/react/docs/${link}.html`;

grunt/tasks/npm-react-dom.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var grunt = require('grunt');
55

66
var src = 'packages/react-dom/';
77
var dest = 'build/packages/react-dom/';
8+
var modSrc = 'build/node_modules/react-dom/lib';
9+
var lib = dest + 'lib/';
810
var dist = dest + 'dist/';
911
var distFiles = [
1012
'react-dom.js',
@@ -21,6 +23,7 @@ function buildRelease() {
2123
// Copy to build/packages/react-dom
2224
var mappings = [].concat(
2325
grunt.file.expandMapping('**/*', dest, {cwd: src}),
26+
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
2427
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
2528
);
2629
mappings.forEach(function(mapping) {

grunt/tasks/npm-react-native.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var grunt = require('grunt');
55

66
var src = 'packages/react-native-renderer/';
77
var dest = 'build/packages/react-native-renderer/';
8+
var modSrc = 'build/node_modules/react-native/lib';
9+
var lib = dest + 'lib/';
810

911
function buildRelease() {
1012
if (grunt.file.exists(dest)) {
@@ -14,6 +16,7 @@ function buildRelease() {
1416
// Copy to build/packages/react-native-renderer
1517
var mappings = [].concat(
1618
grunt.file.expandMapping('**/*', dest, {cwd: src}),
19+
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
1720
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
1821
);
1922
mappings.forEach(function(mapping) {

grunt/tasks/npm-react-test.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var grunt = require('grunt');
55

66
var src = 'packages/react-test-renderer/';
77
var dest = 'build/packages/react-test-renderer/';
8+
var modSrc = 'build/node_modules/react-test-renderer/lib';
9+
var lib = dest + 'lib/';
810

911
function buildRelease() {
1012
if (grunt.file.exists(dest)) {
@@ -14,6 +16,7 @@ function buildRelease() {
1416
// Copy to build/packages/react-native-renderer
1517
var mappings = [].concat(
1618
grunt.file.expandMapping('**/*', dest, {cwd: src}),
19+
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
1720
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
1821
);
1922
mappings.forEach(function(mapping) {

grunt/tasks/npm-react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var grunt = require('grunt');
55

66
var src = 'packages/react/';
77
var dest = 'build/packages/react/';
8-
var modSrc = 'build/modules/';
8+
var modSrc = 'build/node_modules/react/lib';
99
var lib = dest + 'lib/';
1010
var dist = dest + 'dist/';
1111
var distFiles = [

0 commit comments

Comments
 (0)