From c8f7215b200e37f1679da2bebfc2b68876fb15a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Thu, 11 Aug 2016 20:17:37 -0700 Subject: [PATCH] Use aliasify everywhere instead of browserify-global-shim (#7476) 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. --- grunt/config/browserify.js | 39 +++++-------------- gulpfile.js | 2 +- package.json | 1 - .../shims/ReactComponentTreeHookUMDShim.js | 18 +++++++++ src/umd/shims/ReactCurrentOwnerUMDShim.js | 18 +++++++++ src/umd/shims/ReactUMDShim.js | 16 ++++++++ 6 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 src/umd/shims/ReactComponentTreeHookUMDShim.js create mode 100644 src/umd/shims/ReactCurrentOwnerUMDShim.js create mode 100644 src/umd/shims/ReactUMDShim.js diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index 3c06303a3c41f..0ef4c5f8ac22f 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -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': { @@ -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], @@ -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 diff --git a/gulpfile.js b/gulpfile.js index d5bd834620a49..8daaad7f68737 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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', diff --git a/package.json b/package.json index fb871741cb471..7d3e6b3d729c2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/umd/shims/ReactComponentTreeHookUMDShim.js b/src/umd/shims/ReactComponentTreeHookUMDShim.js new file mode 100644 index 0000000000000..82a5cf6e15215 --- /dev/null +++ b/src/umd/shims/ReactComponentTreeHookUMDShim.js @@ -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; diff --git a/src/umd/shims/ReactCurrentOwnerUMDShim.js b/src/umd/shims/ReactCurrentOwnerUMDShim.js new file mode 100644 index 0000000000000..79ef232b54b07 --- /dev/null +++ b/src/umd/shims/ReactCurrentOwnerUMDShim.js @@ -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; diff --git a/src/umd/shims/ReactUMDShim.js b/src/umd/shims/ReactUMDShim.js new file mode 100644 index 0000000000000..84ae35c47505b --- /dev/null +++ b/src/umd/shims/ReactUMDShim.js @@ -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;