Created
June 2, 2015 17:15
-
-
Save zpao/eab5b924f3653c7aab33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/build_helpers/buildNPMInternals.sh b/build_helpers/buildNPMInternals.sh | |
index 8ad0e19..f103381 100755 | |
--- a/build_helpers/buildNPMInternals.sh | |
+++ b/build_helpers/buildNPMInternals.sh | |
@@ -6,6 +6,24 @@ var glob = require('glob'); | |
var path = require('path'); | |
var fs = require('fs'); | |
var babel = require('babel-core'); | |
+var assign = require('object-assign'); | |
+ | |
+var babelRewriteRequires = require('fbjs/scripts/babel/rewrite-requires'); | |
+var babelDevExpression = require('fbjs/scripts/babel/dev-expression'); | |
+ | |
+var moduleMap = assign( | |
+ // All of this could go away if React also ships a module_map.json file. | |
+ { | |
+ React: 'react', | |
+ isEventSupported: 'react/lib/isEventSupported', | |
+ joinClasses: 'react/lib/joinClasses', | |
+ // Might actually be better to use public API React.addons.shallowEqual. | |
+ shallowEqual: 'react/lib/shallowEqual', | |
+ cloneWithProps: 'react/lib/cloneWithProps', | |
+ ReactComponentWithPureRenderMixin: 'react/lib/ReactComponentWithPureRenderMixin', | |
+ }, | |
+ require('fbjs/module_map') | |
+); | |
var internalPath = path.join(__dirname, '../internal'); | |
if (!fs.existsSync(internalPath)) { | |
@@ -13,31 +31,21 @@ if (!fs.existsSync(internalPath)) { | |
} | |
var providesModuleRegex = /@providesModule ([^\s*]+)/; | |
-var moduleRequireRegex = /=\s+require\((?:'|")([\w\.\/]+)(?:'|")\);/gm; | |
-var excludePathRegex = /^react($|\/)/; | |
-var findDEVRegex = /__DEV__/g; | |
- | |
-function replaceRequirePath(match, modulePath) { | |
- var path = modulePath; | |
- | |
- if (!excludePathRegex.test(path)) { | |
- path = './' + path; | |
- } | |
- | |
- return '= require(\'' + path + '\');'; | |
-} | |
var babelConf = JSON.parse( | |
fs.readFileSync('.babelrc', {encoding: 'utf8'}) | |
); | |
+babelConf.plugins.push(babelRewriteRequires, babelDevExpression); | |
+babelConf._moduleMap = moduleMap; | |
+ | |
function processFile(fileName) { | |
+ // Note: Could probably skip the providesModule check, but not sure. | |
+ // If so you could just call babael directly with a file and path output to. | |
var contents = fs.readFileSync(fileName, {encoding: 'utf8'}); | |
var providesModule = providesModuleRegex.exec(contents); | |
if (providesModule) { | |
contents = babel.transform(contents, babelConf).code; | |
- contents = contents.replace(moduleRequireRegex, replaceRequirePath); | |
- contents = contents.replace(findDEVRegex, 'process.env.NODE_ENV !== \'production\''); | |
fs.writeFileSync( | |
path.join(internalPath, providesModule[1] + '.js'), | |
contents | |
diff --git a/package.json b/package.json | |
index aec1643..515f1b9 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -21,6 +21,7 @@ | |
"less-loader": "^2.0.0", | |
"marked": "^0.3.2", | |
"null-loader": "^0.1.0", | |
+ "object-assign": "^2.0.0", | |
"postcss": "^4.0.2", | |
"postcss-custom-properties": "3.0.1", | |
"react": "^0.12.2", | |
diff --git a/src/stubs/invariant.js b/src/stubs/invariant.js | |
deleted file mode 100644 | |
index 2086cc7..0000000 | |
--- a/src/stubs/invariant.js | |
+++ /dev/null | |
@@ -1,53 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 invariant | |
- */ | |
- | |
-"use strict"; | |
- | |
-/** | |
- * Use invariant() to assert state which your program assumes to be true. | |
- * | |
- * Provide sprintf-style format (only %s is supported) and arguments | |
- * to provide information about what broke and what you were | |
- * expecting. | |
- * | |
- * The invariant message will be stripped in production, but the invariant | |
- * will remain to ensure logic does not differ in production. | |
- */ | |
- | |
-var invariant = function(condition, format, a, b, c, d, e, f) { | |
- if (__DEV__) { | |
- if (format === undefined) { | |
- throw new Error('invariant requires an error message argument'); | |
- } | |
- } | |
- | |
- if (!condition) { | |
- var error; | |
- if (format === undefined) { | |
- error = new Error( | |
- 'Minified exception occurred; use the non-minified dev environment ' + | |
- 'for the full error message and additional helpful warnings.' | |
- ); | |
- } else { | |
- var args = [a, b, c, d, e, f]; | |
- var argIndex = 0; | |
- error = new Error( | |
- 'Invariant Violation: ' + | |
- format.replace(/%s/g, function() { return args[argIndex++]; }) | |
- ); | |
- } | |
- | |
- error.framesToPop = 1; // we don't care about invariant's own frame | |
- throw error; | |
- } | |
-}; | |
- | |
-module.exports = invariant; | |
diff --git a/src/stubs/react/React.js b/src/stubs/react/React.js | |
deleted file mode 100644 | |
index 78d6e45..0000000 | |
--- a/src/stubs/react/React.js | |
+++ /dev/null | |
@@ -1,12 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 React | |
- */ | |
- | |
-module.exports = require('react'); | |
diff --git a/src/stubs/react/ReactComponentWithPureRenderMixin.js b/src/stubs/react/ReactComponentWithPureRenderMixin.js | |
deleted file mode 100644 | |
index 90c9704..0000000 | |
--- a/src/stubs/react/ReactComponentWithPureRenderMixin.js | |
+++ /dev/null | |
@@ -1,12 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 ReactComponentWithPureRenderMixin | |
- */ | |
- | |
-module.exports = require('react/lib/ReactComponentWithPureRenderMixin'); | |
diff --git a/src/stubs/react/cloneWithProps.js b/src/stubs/react/cloneWithProps.js | |
deleted file mode 100644 | |
index 6c626c5..0000000 | |
--- a/src/stubs/react/cloneWithProps.js | |
+++ /dev/null | |
@@ -1,12 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 cloneWithProps | |
- */ | |
- | |
-module.exports = require('react/lib/cloneWithProps'); | |
diff --git a/src/vendor_upstream/core/ExecutionEnvironment.js b/src/vendor_upstream/core/ExecutionEnvironment.js | |
deleted file mode 100644 | |
index 060e096..0000000 | |
--- a/src/vendor_upstream/core/ExecutionEnvironment.js | |
+++ /dev/null | |
@@ -1,43 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 ExecutionEnvironment | |
- */ | |
- | |
-/*jslint evil: true */ | |
- | |
-'use strict'; | |
- | |
-var canUseDOM = !!( | |
- typeof window !== 'undefined' && | |
- window.document && | |
- window.document.createElement | |
-); | |
- | |
-/** | |
- * Simple, lightweight module assisting with the detection and context of | |
- * Worker. Helps avoid circular dependencies and allows code to reason about | |
- * whether or not they are in a Worker, even if they never include the main | |
- * `ReactWorker` dependency. | |
- */ | |
-var ExecutionEnvironment = { | |
- | |
- canUseDOM: canUseDOM, | |
- | |
- canUseWorkers: typeof Worker !== 'undefined', | |
- | |
- canUseEventListeners: | |
- canUseDOM && !!(window.addEventListener || window.attachEvent), | |
- | |
- canUseViewport: canUseDOM && !!window.screen, | |
- | |
- isInWorker: !canUseDOM // For now, this is true - might change in the future. | |
- | |
-}; | |
- | |
-module.exports = ExecutionEnvironment; | |
diff --git a/src/vendor_upstream/core/camelize.js b/src/vendor_upstream/core/camelize.js | |
deleted file mode 100644 | |
index b500ec8..0000000 | |
--- a/src/vendor_upstream/core/camelize.js | |
+++ /dev/null | |
@@ -1,30 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 camelize | |
- * @typechecks | |
- */ | |
- | |
-var _hyphenPattern = /-(.)/g; | |
- | |
-/** | |
- * Camelcases a hyphenated string, for example: | |
- * | |
- * > camelize('background-color') | |
- * < "backgroundColor" | |
- * | |
- * @param {string} string | |
- * @return {string} | |
- */ | |
-function camelize(string) { | |
- return string.replace(_hyphenPattern, function(_, character) { | |
- return character.toUpperCase(); | |
- }); | |
-} | |
- | |
-module.exports = camelize; | |
diff --git a/src/vendor_upstream/core/dom/isNode.js b/src/vendor_upstream/core/dom/isNode.js | |
deleted file mode 100644 | |
index de58713..0000000 | |
--- a/src/vendor_upstream/core/dom/isNode.js | |
+++ /dev/null | |
@@ -1,26 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 isNode | |
- * @typechecks | |
- */ | |
- | |
-/** | |
- * @param {*} object The object to check. | |
- * @return {boolean} Whether or not the object is a DOM node. | |
- */ | |
-function isNode(object) { | |
- return !!(object && ( | |
- typeof Node === 'function' ? object instanceof Node : | |
- typeof object === 'object' && | |
- typeof object.nodeType === 'number' && | |
- typeof object.nodeName === 'string' | |
- )); | |
-} | |
- | |
-module.exports = isNode; | |
diff --git a/src/vendor_upstream/core/emptyFunction.js b/src/vendor_upstream/core/emptyFunction.js | |
deleted file mode 100644 | |
index 688035a..0000000 | |
--- a/src/vendor_upstream/core/emptyFunction.js | |
+++ /dev/null | |
@@ -1,32 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 emptyFunction | |
- */ | |
- | |
-function makeEmptyFunction(arg) { | |
- return function() { | |
- return arg; | |
- }; | |
-} | |
- | |
-/** | |
- * This function accepts and discards inputs; it has no side effects. This is | |
- * primarily useful idiomatically for overridable function endpoints which | |
- * always need to be callable, since JS lacks a null-call idiom ala Cocoa. | |
- */ | |
-function emptyFunction() {} | |
- | |
-emptyFunction.thatReturns = makeEmptyFunction; | |
-emptyFunction.thatReturnsFalse = makeEmptyFunction(false); | |
-emptyFunction.thatReturnsTrue = makeEmptyFunction(true); | |
-emptyFunction.thatReturnsNull = makeEmptyFunction(null); | |
-emptyFunction.thatReturnsThis = function() { return this; }; | |
-emptyFunction.thatReturnsArgument = function(arg) { return arg; }; | |
- | |
-module.exports = emptyFunction; | |
diff --git a/src/vendor_upstream/key-mirror/keyMirror.js b/src/vendor_upstream/key-mirror/keyMirror.js | |
deleted file mode 100644 | |
index 810aafa..0000000 | |
--- a/src/vendor_upstream/key-mirror/keyMirror.js | |
+++ /dev/null | |
@@ -1,51 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 keyMirror | |
- * @typechecks static-only | |
- */ | |
- | |
-'use strict'; | |
- | |
-var invariant = require('invariant'); | |
- | |
-/** | |
- * Constructs an enumeration with keys equal to their value. | |
- * | |
- * For example: | |
- * | |
- * var COLORS = keyMirror({blue: null, red: null}); | |
- * var myColor = COLORS.blue; | |
- * var isColorValid = !!COLORS[myColor]; | |
- * | |
- * The last line could not be performed if the values of the generated enum were | |
- * not equal to their keys. | |
- * | |
- * Input: {key1: val1, key2: val2} | |
- * Output: {key1: key1, key2: key2} | |
- * | |
- * @param {object} obj | |
- * @return {object} | |
- */ | |
-var keyMirror = function(obj) { | |
- var ret = {}; | |
- var key; | |
- invariant( | |
- obj instanceof Object && !Array.isArray(obj), | |
- 'keyMirror(...): Argument must be an object.' | |
- ); | |
- for (key in obj) { | |
- if (!obj.hasOwnProperty(key)) { | |
- continue; | |
- } | |
- ret[key] = key; | |
- } | |
- return ret; | |
-}; | |
- | |
-module.exports = keyMirror; | |
diff --git a/src/vendor_upstream/key-mirror/keyOf.js b/src/vendor_upstream/key-mirror/keyOf.js | |
deleted file mode 100644 | |
index 2a981e6..0000000 | |
--- a/src/vendor_upstream/key-mirror/keyOf.js | |
+++ /dev/null | |
@@ -1,34 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 keyOf | |
- */ | |
- | |
-/** | |
- * Allows extraction of a minified key. Let's the build system minify keys | |
- * without losing the ability to dynamically use key strings as values | |
- * themselves. Pass in an object with a single key/val pair and it will return | |
- * you the string key of that single record. Suppose you want to grab the | |
- * value for a key 'className' inside of an object. Key/val minification may | |
- * have aliased that key to be 'xa12'. keyOf({className: null}) will return | |
- * 'xa12' in that case. Resolve keys you want to use once at startup time, then | |
- * reuse those resolutions. | |
- */ | |
-var keyOf = function(oneKeyObj) { | |
- var key; | |
- for (key in oneKeyObj) { | |
- if (!oneKeyObj.hasOwnProperty(key)) { | |
- continue; | |
- } | |
- return key; | |
- } | |
- return null; | |
-}; | |
- | |
- | |
-module.exports = keyOf; | |
diff --git a/src/vendor_upstream/react/browser/ui/dom/isEventSupported.js b/src/vendor_upstream/react/browser/ui/dom/isEventSupported.js | |
deleted file mode 100644 | |
index 1b6fffb..0000000 | |
--- a/src/vendor_upstream/react/browser/ui/dom/isEventSupported.js | |
+++ /dev/null | |
@@ -1,63 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 isEventSupported | |
- */ | |
- | |
-'use strict'; | |
- | |
-var ExecutionEnvironment = require('ExecutionEnvironment'); | |
- | |
-var useHasFeature; | |
-if (ExecutionEnvironment.canUseDOM) { | |
- useHasFeature = | |
- document.implementation && | |
- document.implementation.hasFeature && | |
- // always returns true in newer browsers as per the standard. | |
- // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature | |
- document.implementation.hasFeature('', '') !== true; | |
-} | |
- | |
-/** | |
- * Checks if an event is supported in the current execution environment. | |
- * | |
- * NOTE: This will not work correctly for non-generic events such as `change`, | |
- * `reset`, `load`, `error`, and `select`. | |
- * | |
- * Borrows from Modernizr. | |
- * | |
- * @param {string} eventNameSuffix Event name, e.g. "click". | |
- * @param {?boolean} capture Check if the capture phase is supported. | |
- * @return {boolean} True if the event is supported. | |
- * @internal | |
- * @license Modernizr 3.0.0pre (Custom Build) | MIT | |
- */ | |
-function isEventSupported(eventNameSuffix, capture) { | |
- if (!ExecutionEnvironment.canUseDOM || | |
- capture && !('addEventListener' in document)) { | |
- return false; | |
- } | |
- | |
- var eventName = 'on' + eventNameSuffix; | |
- var isSupported = eventName in document; | |
- | |
- if (!isSupported) { | |
- var element = document.createElement('div'); | |
- element.setAttribute(eventName, 'return;'); | |
- isSupported = typeof element[eventName] === 'function'; | |
- } | |
- | |
- if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') { | |
- // This is the only way to test support for the `wheel` event in IE9+. | |
- isSupported = document.implementation.hasFeature('Events.wheel', '3.0'); | |
- } | |
- | |
- return isSupported; | |
-} | |
- | |
-module.exports = isEventSupported; | |
diff --git a/src/vendor_upstream/react/utils/joinClasses.js b/src/vendor_upstream/react/utils/joinClasses.js | |
deleted file mode 100644 | |
index efccdad..0000000 | |
--- a/src/vendor_upstream/react/utils/joinClasses.js | |
+++ /dev/null | |
@@ -1,39 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 joinClasses | |
- * @typechecks static-only | |
- */ | |
- | |
-'use strict'; | |
- | |
-/** | |
- * Combines multiple className strings into one. | |
- * http://jsperf.com/joinclasses-args-vs-array | |
- * | |
- * @param {...?string} classes | |
- * @return {string} | |
- */ | |
-function joinClasses(className/*, ... */) { | |
- if (!className) { | |
- className = ''; | |
- } | |
- var nextClass; | |
- var argLength = arguments.length; | |
- if (argLength > 1) { | |
- for (var ii = 1; ii < argLength; ii++) { | |
- nextClass = arguments[ii]; | |
- if (nextClass) { | |
- className = (className ? className + ' ' : '') + nextClass; | |
- } | |
- } | |
- } | |
- return className; | |
-} | |
- | |
-module.exports = joinClasses; | |
diff --git a/src/vendor_upstream/react/utils/shallowEqual.js b/src/vendor_upstream/react/utils/shallowEqual.js | |
deleted file mode 100644 | |
index f815bcf..0000000 | |
--- a/src/vendor_upstream/react/utils/shallowEqual.js | |
+++ /dev/null | |
@@ -1,49 +0,0 @@ | |
-/** | |
- * Copyright (c) 2015, 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 shallowEqual | |
- */ | |
- | |
-'use strict'; | |
- | |
-/** | |
- * Performs equality by iterating through keys on an object and returning | |
- * false when any key has values which are not strictly equal between | |
- * objA and objB. Returns true when the values of all keys are strictly equal. | |
- * | |
- * @return {boolean} | |
- */ | |
-function shallowEqual(objA, objB) { | |
- if (objA === objB) { | |
- return true; | |
- } | |
- | |
- if (typeof objA !== 'object' || objA === null || | |
- typeof objB !== 'object' || objB === null) { | |
- return false; | |
- } | |
- | |
- var keysA = Object.keys(objA); | |
- var keysB = Object.keys(objB); | |
- | |
- if (keysA.length !== keysB.length) { | |
- return false; | |
- } | |
- | |
- // Test for A's keys different from B. | |
- var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB); | |
- for (var i = 0; i < keysA.length; i++) { | |
- if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { | |
- return false; | |
- } | |
- } | |
- | |
- return true; | |
-} | |
- | |
-module.exports = shallowEqual; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment