Skip to content

Commit

Permalink
Use aliasify everywhere instead of browserify-global-shim (#7476)
Browse files Browse the repository at this point in the history
I already had to aliasify to have better control over the requires
so we might as well do it everywhere for consistency.

This probably makes it easier to rebase the rollup work too
because aliases seems to be how you solve this in that world.
(cherry picked from commit c8f7215)
  • Loading branch information
sebmarkbage authored and zpao committed Oct 3, 2016
1 parent cc2e5cc commit ecdc185
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
39 changes: 9 additions & 30 deletions grunt/config/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,18 @@ var UglifyJS = require('uglify-js');
var uglifyify = require('uglifyify');
var derequire = require('derequire');
var aliasify = require('aliasify');
var globalShim = require('browserify-global-shim');
var collapser = require('bundle-collapser/plugin');

var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'});
var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'});

var SECRET_INTERNALS_NAME = 'React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED';

var shimSharedModulesFiles = {
'./ReactCurrentOwner': SECRET_INTERNALS_NAME + '.ReactCurrentOwner',
'./ReactComponentTreeHook': SECRET_INTERNALS_NAME + '.ReactComponentTreeHook',
// Use the global, anywhere we require React
'./React': 'React',
};

// We can access these as absolute or relative. We need to shim both.
for (var key in shimSharedModulesFiles) {
shimSharedModulesFiles[key.replace(/^\.\//, 'react/lib/')] = shimSharedModulesFiles[key];
}

var shimSharedModules = globalShim.configure(shimSharedModulesFiles);

// Fiber needs the symbol from ReactElement right now. So we can't shim
// ReactElement. Otherwise this would just be the same as above.
// TODO: Refactor this so that Fiber can access the symbol without bringing in
// the rest of ReactElement.
var shimSharedModulesFiberFiles = {};
for (var key in shimSharedModulesFiles) {
if (!/ReactElement/.test(key)) {
shimSharedModulesFiberFiles[key] = shimSharedModulesFiles[key];
}
}
var shimSharedModulesFiber = globalShim.configure(shimSharedModulesFiberFiles);
var shimSharedModules = aliasify.configure({
'aliases': {
'react/lib/React': 'react/lib/ReactUMDShim',
'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwnerUMDShim',
'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHookUMDShim',
},
});

var shimDOMModules = aliasify.configure({
'aliases': {
Expand Down Expand Up @@ -219,7 +198,7 @@ var domFiber = {
debug: false,
standalone: 'ReactDOMFiber',
// Apply as global transform so that we also envify fbjs and any other deps
transforms: [shimSharedModulesFiber],
transforms: [shimSharedModules],
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, simpleBannerify],
Expand All @@ -234,7 +213,7 @@ var domFiberMin = {
standalone: 'ReactDOMFiber',
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [shimSharedModulesFiber, envifyProd, uglifyify],
transforms: [shimSharedModules, envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var paths = {
src: [
'src/umd/ReactUMDEntry.js',
'src/umd/ReactWithAddonsUMDEntry.js',
'src/umd/shims/ReactAddonsDOMDependenciesUMDShim.js',
'src/umd/shims/**/*.js',

'src/isomorphic/**/*.js',
'src/addons/**/*.js',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"babel-traverse": "^6.9.0",
"babylon": "6.8.0",
"browserify": "^13.0.0",
"browserify-global-shim": "^1.0.3",
"bundle-collapser": "^1.1.1",
"coffee-script": "^1.8.0",
"core-js": "^2.2.1",
Expand Down
18 changes: 18 additions & 0 deletions src/umd/shims/ReactComponentTreeHookUMDShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactComponentTreeHookUMDShim
*/

/* globals React */

'use strict';

var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

module.exports = ReactInternals.ReactComponentTreeHook;
18 changes: 18 additions & 0 deletions src/umd/shims/ReactCurrentOwnerUMDShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactCurrentOwnerUMDShim
*/

/* globals React */

'use strict';

var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

module.exports = ReactInternals.ReactCurrentOwner;
16 changes: 16 additions & 0 deletions src/umd/shims/ReactUMDShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactUMDShim
*/

/* globals React */

'use strict';

module.exports = React;

0 comments on commit ecdc185

Please sign in to comment.