Skip to content

Commit

Permalink
Use fbjs package from npm, gulp
Browse files Browse the repository at this point in the history
This reworks a few things in building and distributing React. The biggest change is using fbjs to share dependencies with other libraries. We're also using Gulp for some build steps.
  • Loading branch information
zpao committed Jul 23, 2015
1 parent ac5e5d7 commit 1d0c1b1
Show file tree
Hide file tree
Showing 49 changed files with 167 additions and 1,637 deletions.
43 changes: 32 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

var assign = require('object-assign');
var path = require('path');

module.exports = function(grunt) {

grunt.initConfig({
Expand All @@ -21,6 +24,21 @@ module.exports = function(grunt) {

grunt.config.set('compress', require('./grunt/config/compress'));

function spawnGulp(args, opts, done) {
grunt.util.spawn({
// This could be more flexible (require.resolve & lookup bin in package)
// but if it breaks we'll fix it then.
cmd: path.join('node_modules', '.bin', 'gulpp'),
args: args,
opts: assign({stdio: 'inherit'}, opts),
}, function(err, result, code) {
if (err) {
grunt.fail.fatal('Something went wrong running gulp: ', result);
}
done(code === 0);
});
}

Object.keys(grunt.file.readJSON('package.json').devDependencies)
.filter(function(npmTaskName) {
return npmTaskName.indexOf('grunt-') === 0;
Expand All @@ -37,9 +55,8 @@ module.exports = function(grunt) {
grunt.registerTask('lint', ['eslint']);

grunt.registerTask('delete-build-modules', function() {
if (grunt.file.exists('build/modules')) {
grunt.file.delete('build/modules');
}
// Use gulp here
spawnGulp(['react:clean'], null, this.async());
});

// Register jsx:normal and :release tasks.
Expand Down Expand Up @@ -68,30 +85,30 @@ module.exports = function(grunt) {
grunt.registerTask('version-check', require('./grunt/tasks/version-check'));

grunt.registerTask('build:basic', [
'jsx:normal',
'build-modules',
'version-check',
'browserify:basic',
]);
grunt.registerTask('build:addons', [
'jsx:normal',
'build-modules',
'browserify:addons',
]);
grunt.registerTask('build:transformer', [
'jsx:normal',
'build-modules',
'browserify:transformer',
]);
grunt.registerTask('build:min', [
'jsx:normal',
'build-modules',
'version-check',
'browserify:min',
]);
grunt.registerTask('build:addons-min', [
'jsx:normal',
'build-modules',
'browserify:addonsMin',
]);
grunt.registerTask('build:npm-react', [
'version-check',
'jsx:normal',
'build-modules',
'npm-react:release',
]);

Expand All @@ -102,10 +119,10 @@ module.exports = function(grunt) {
grunt.registerTask('npm:test', ['build', 'npm:pack']);

// Optimized build task that does all of our builds. The subtasks will be run
// in order so we can take advantage of that and only run jsx:normal once.
// in order so we can take advantage of that and only run build-modules once.
grunt.registerTask('build', [
'delete-build-modules',
'jsx:normal',
'build-modules',
'version-check',
'browserify:basic',
'browserify:transformer',
Expand Down Expand Up @@ -141,6 +158,10 @@ module.exports = function(grunt) {
'release:msg',
]);

grunt.registerTask('build-modules', function() {
spawnGulp(['react:modules'], null, this.async());
});

// The default task - build - to keep setup easy.
grunt.registerTask('default', ['build']);
};
13 changes: 7 additions & 6 deletions bin/jsx-internal
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env node
// -*- mode: js -*-
// vim: set ft=javascript :
"use strict";

'use strict';

var babel = require('babel');

var constants = require('../vendor/constants')(babel);
var devExpressionPlugin = require('fbjs/scripts/babel/dev-expression');

var TRANSFORM_IGNORE_RE = /^WebComponents$/;

require("commoner").version(
require("../package.json").version
require('commoner').version(
require('../package.json').version
).resolve(function(id) {
var context = this;

Expand Down Expand Up @@ -38,8 +39,8 @@ require("commoner").version(
// This is where JSX, ES6, etc. desugaring happens.
source = babel.transform(source, {
blacklist: ['spec.functionName', 'validation.react'],
plugins: [constants],
filename: id
plugins: [devExpressionPlugin],
filename: id,
}).code;
}

Expand Down
3 changes: 3 additions & 0 deletions grunt/tasks/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ module.exports = function() {
config.transforms = config.transforms || [];
config.plugins = config.plugins || [];
config.after = config.after || [];
config.paths = config.paths || [];

// create the bundle we'll work with
var entries = grunt.file.expand(config.entries);
var paths = grunt.file.expand(config.paths);

// Extract other options
var options = {
entries: entries,
debug: config.debug, // sourcemaps
standalone: config.standalone, // global
paths: paths,
};

var bundle = browserify(options);
Expand Down
56 changes: 56 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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.
*/

'use strict';

var gulp = require('gulp');
var babel = require('gulp-babel');
var flatten = require('gulp-flatten');
var del = require('del');

var babelPluginDEV = require('fbjs/scripts/babel/dev-expression');
var babelPluginRequires = require('fbjs/scripts/babel/rewrite-requires');

var paths = {
react: {
src: [
'src/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/modules',
},
};

var babelOpts = {
nonStandard: true,
blacklist: [
'spec.functionName',
],
optional: [
'es7.trailingFunctionCommas',
],
plugins: [babelPluginDEV, babelPluginRequires],
ignore: ['third_party'],
_moduleMap: require('fbjs/module-map'),
};

gulp.task('react:clean', function(cb) {
del([paths.react.lib], cb);
});

gulp.task('react:modules', function() {
return gulp
.src(paths.react.src)
.pipe(babel(babelOpts))
.pipe(flatten())
.pipe(gulp.dest(paths.react.lib));
});

gulp.task('default', ['react:modules']);
32 changes: 0 additions & 32 deletions jest/preprocessor.js

This file was deleted.

20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,31 @@
"browserify": "^9.0.3",
"bundle-collapser": "^1.1.1",
"coffee-script": "^1.8.0",
"del": "^1.2.0",
"derequire": "^2.0.0",
"envify": "^3.0.0",
"eslint": "^0.24.1",
"eslint-plugin-react": "^2.5.0",
"eslint-plugin-react-internal": "file:eslint-rules",
"eslint-tester": "^0.7.0",
"fbjs": "^0.1.0-alpha.0",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-compare-size": "^0.4.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compress": "^0.13.0",
"grunt-jest": "^0.1.3",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-flatten": "^0.1.0",
"gulp-util": "^3.0.5",
"gzip-js": "~0.3.2",
"jest-cli": "^0.4.13",
"object-assign": "^3.0.0",
"optimist": "^0.6.1",
"platform": "^1.1.0",
"run-sequence": "^1.1.0",
"through2": "^2.0.0",
"tmp": "~0.0.18",
"typescript": "~1.4.0",
"uglify-js": "^2.4.23",
Expand All @@ -66,29 +74,29 @@
},
"scripts": {
"build": "grunt build",
"jest": "jest",
"jest": "test",
"linc": "git diff --name-only --diff-filter=ACMRTUB `git merge-base HEAD master` | grep '\\.js$' | xargs eslint --",
"lint": "grunt lint",
"test": "jest"
"test": "NODE_ENV=test jest"
},
"jest": {
"modulePathIgnorePatterns": [
"/.module-cache/",
"/node_modules/",
"/react/build/"
],
"persistModuleRegistryBetweenSpecs": true,
"rootDir": "",
"scriptPreprocessor": "jest/preprocessor.js",
"setupEnvScriptFile": "jest/environment.js",
"scriptPreprocessor": "scripts/jest/preprocessor.js",
"setupEnvScriptFile": "scripts/jest/environment.js",
"testFileExtensions": [
"coffee",
"js",
"ts"
],
"testPathDirs": [
"<rootDir>/eslint-rules",
"<rootDir>/src"
"<rootDir>/src",
"node_modules/fbjs"
],
"unmockedModulePathPatterns": [
""
Expand Down
1 change: 1 addition & 0 deletions packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"homepage": "https://github.com/facebook/react/tree/master/npm-react-dom",
"dependencies": {
"fbjs": "0.1.0-alpha.0",
"react": "^0.14.0-beta1"
}
}
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"node": ">=0.10.0"
},
"dependencies": {
"envify": "^3.0.0"
"envify": "^3.0.0",
"fbjs": "0.1.0-alpha.0"
},
"browserify": {
"transform": [
Expand Down
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions scripts/jest/preprocessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

var babel = require('babel');
var coffee = require('coffee-script');

var tsPreprocessor = require('./ts-preprocessor');

var defaultLibraries = [
require.resolve('./jest.d.ts'),
require.resolve('../../src/isomorphic/modern/class/React.d.ts'),
];

var ts = tsPreprocessor(defaultLibraries);

// This assumes the module map has been built. This might not be safe.
// We should consider consuming this from a built fbjs module from npm.
var moduleMap = require('fbjs/module-map');
var babelPluginDEV = require('fbjs/scripts/babel/dev-expression');
var babelPluginRequires = require('fbjs/scripts/babel/rewrite-requires');

module.exports = {
process: function(src, path) {
if (path.match(/\.coffee$/)) {
return coffee.compile(src, {'bare': true});
}
if (path.match(/\.ts$/) && !path.match(/\.d\.ts$/)) {
return ts.compile(src, path);
}
// TODO: make sure this stays in sync with gulpfile
if (!path.match(/\/node_modules\//) && !path.match(/\/third_party\//)) {
var rv = babel.transform(src, {
nonStandard: true,
blacklist: [
'spec.functionName',
'validation.react',
],
optional: [
'es7.trailingFunctionCommas',
],
plugins: [babelPluginDEV, babelPluginRequires],
ignore: ['third_party'],
filename: path,
retainLines: true,
_moduleMap: moduleMap,
}).code;
return rv;
}
return src;
},
};
File renamed without changes.
4 changes: 0 additions & 4 deletions src/isomorphic/deprecated/__tests__/cloneWithProps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

'use strict';

require('mock-modules')
.dontMock('cloneWithProps')
.dontMock('emptyObject');

var React;
var ReactTestUtils;

Expand Down
Loading

0 comments on commit 1d0c1b1

Please sign in to comment.