From 135c554b23dbe45874fe47c47f91b797347a4c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 8 Sep 2015 17:41:41 -0700 Subject: [PATCH 1/4] Move headers to shared location, use grunt templates --- grunt/config/browserify.js | 36 +++++++++++-------------- grunt/data/header-template-extended.txt | 11 ++++++++ grunt/data/header-template-short.txt | 3 +++ 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 grunt/data/header-template-extended.txt create mode 100644 grunt/data/header-template-short.txt diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index ac84b9beb897f..0caa472976d52 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -13,22 +13,10 @@ var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'}); var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'}); var SIMPLE_TEMPLATE = -'/**\n\ - * @PACKAGE@ v@VERSION@\n\ - */'; + grunt.file.read('./grunt/data/header-template-short.txt'); var LICENSE_TEMPLATE = -'/**\n\ - * @PACKAGE@ v@VERSION@\n\ - *\n\ - * Copyright 2013-2015, Facebook, Inc.\n\ - * All rights reserved.\n\ - *\n\ - * This source code is licensed under the BSD-style license found in the\n\ - * LICENSE file in the root directory of this source tree. An additional grant\n\ - * of patent rights can be found in the PATENTS file in the same directory.\n\ - *\n\ - */'; + grunt.file.read('./grunt/data/header-template-extended.txt'); function minify(src) { return UglifyJS.minify(src, {fromString: true}).code; @@ -38,17 +26,25 @@ function minify(src) { function bannerify(src) { var version = grunt.config.data.pkg.version; var packageName = this.data.packageName || this.data.standalone; - return LICENSE_TEMPLATE.replace('@PACKAGE@', packageName) - .replace('@VERSION@', version) + - '\n' + src; + return ( + grunt.template.process( + LICENSE_TEMPLATE, + {data: {package: packageName, version: version}} + ) + + src + ); } function simpleBannerify(src) { var version = grunt.config.data.pkg.version; var packageName = this.data.packageName || this.data.standalone; - return SIMPLE_TEMPLATE.replace('@PACKAGE@', packageName) - .replace('@VERSION@', version) + - '\n' + src; + return ( + grunt.template.process( + SIMPLE_TEMPLATE, + {data: {package: packageName, version: version}} + ) + + src + ); } // Our basic config which we'll add to to make our other builds diff --git a/grunt/data/header-template-extended.txt b/grunt/data/header-template-extended.txt new file mode 100644 index 0000000000000..addc0bfcd556a --- /dev/null +++ b/grunt/data/header-template-extended.txt @@ -0,0 +1,11 @@ +/** + * <%= package %> v<%= version %> + * + * Copyright 2013-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. + * + */ diff --git a/grunt/data/header-template-short.txt b/grunt/data/header-template-short.txt new file mode 100644 index 0000000000000..ec08497d13a90 --- /dev/null +++ b/grunt/data/header-template-short.txt @@ -0,0 +1,3 @@ + /** + * <%= package %> v<%= version %> + */ From b2ca3349c27b57b1e9462944cbe4aaaf76783d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 8 Sep 2015 10:13:24 -0700 Subject: [PATCH 2/4] Actually build react-dom file with the build --- .eslintignore | 1 + Gruntfile.js | 2 ++ grunt/tasks/react-dom.js | 27 +++++++++++++++++++++++++++ src/React.js | 2 ++ vendor/react-dom.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 grunt/tasks/react-dom.js create mode 100644 vendor/react-dom.js diff --git a/.eslintignore b/.eslintignore index 8b66781299e89..c20a6aa20e3d3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -16,3 +16,4 @@ packages/react-codemod/test/ packages/react-codemod/scripts/ packages/react-codemod/build/ packages/react-codemod/node_modules/ +vendor/react-dom.js diff --git a/Gruntfile.js b/Gruntfile.js index e99175b6a10b1..3f4a02e3e372a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -107,6 +107,7 @@ module.exports = function(grunt) { 'build-modules', 'npm-react:release', ]); + grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom')); grunt.registerTask('test', ['jest']); grunt.registerTask('npm:test', ['build', 'npm:pack']); @@ -124,6 +125,7 @@ module.exports = function(grunt) { 'browserify:addons', 'browserify:min', 'browserify:addonsMin', + 'build:react-dom', 'npm-react:release', 'npm-react:pack', 'npm-react-dom:pack', diff --git a/grunt/tasks/react-dom.js b/grunt/tasks/react-dom.js new file mode 100644 index 0000000000000..78fe2b434f74e --- /dev/null +++ b/grunt/tasks/react-dom.js @@ -0,0 +1,27 @@ +'use strict'; + +var grunt = require('grunt'); +var UglifyJS = require('uglify-js'); + +var LICENSE_TEMPLATE = + grunt.file.read('./grunt/data/header-template-extended.txt'); + +module.exports = function() { + var templateData = { + package: 'ReactDOM', + version: grunt.config.data.pkg.version, + }; + var header = grunt.template.process( + LICENSE_TEMPLATE, + {data: templateData} + ); + var src = grunt.file.read('vendor/react-dom.js'); + grunt.file.write( + 'build/react-dom.js', + header + src + ); + grunt.file.write( + 'build/react-dom.min.js', + header + UglifyJS.minify(src, {fromString: true}).code + ); +}; diff --git a/src/React.js b/src/React.js index ed7b29803e25b..6e11a3a79b1dc 100644 --- a/src/React.js +++ b/src/React.js @@ -64,4 +64,6 @@ assign(React, { ), }); +React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactDOM; + module.exports = React; diff --git a/vendor/react-dom.js b/vendor/react-dom.js new file mode 100644 index 0000000000000..89eeb26e6fb51 --- /dev/null +++ b/vendor/react-dom.js @@ -0,0 +1,31 @@ +// Based off https://github.com/ForbesLindesay/umd/blob/master/template.js +;(function(f) { + // CommonJS + if (typeof exports === "object" && typeof module !== "undefined") { + module.exports = f(require('react')); + + // RequireJS + } else if (typeof define === "function" && define.amd) { + define(['react'], f); + + //