Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move vendor to fbjs package #4167

Merged
merged 3 commits into from
Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 34 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 @@ -101,11 +118,13 @@ module.exports = function(grunt) {
grunt.registerTask('test', ['jest']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);

grunt.registerTask('jest', require('./grunt/tasks/jest'));

// 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 +160,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
16 changes: 12 additions & 4 deletions grunt/config/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var uglifyify = require('uglifyify');
var derequire = require('derequire');
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 SIMPLE_TEMPLATE =
'/**\n\
* @PACKAGE@ v@VERSION@\n\
Expand Down Expand Up @@ -56,7 +59,8 @@ var basic = {
outfile: './build/react.js',
debug: false,
standalone: 'React',
transforms: [envify({NODE_ENV: process.env.NODE_ENV || 'development'})],
// Apply as global transform so that we also envify fbjs and any other deps
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, simpleBannerify],
};
Expand All @@ -68,7 +72,10 @@ var min = {
outfile: './build/react.min.js',
debug: false,
standalone: 'React',
transforms: [envify({NODE_ENV: process.env.NODE_ENV || 'production'}), uglifyify],
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
// the "require" calls.
Expand Down Expand Up @@ -100,7 +107,7 @@ var addons = {
debug: false,
standalone: 'React',
packageName: 'React (with addons)',
transforms: [envify({NODE_ENV: process.env.NODE_ENV || 'development'})],
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, simpleBannerify],
};
Expand All @@ -113,7 +120,8 @@ var addonsMin = {
debug: false,
standalone: 'React',
packageName: 'React (with addons)',
transforms: [envify({NODE_ENV: process.env.NODE_ENV || 'production'}), uglifyify],
transforms: [envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
// the "require" calls.
Expand Down
8 changes: 8 additions & 0 deletions grunt/tasks/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ module.exports = function() {
// grunt.config.requires('outfile');
// grunt.config.requires('entries');
config.transforms = config.transforms || [];
config.globalTransforms = config.globalTransforms || [];
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 All @@ -32,6 +36,10 @@ module.exports = function() {
bundle.transform({}, transform);
});

config.globalTransforms.forEach(function(transform) {
bundle.transform({global: true}, transform);
});

config.plugins.forEach(bundle.plugin, bundle);

// Actually bundle it up
Expand Down
30 changes: 30 additions & 0 deletions grunt/tasks/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// We run our own grunt task instead of using grunt-jest so that we can have
// more control. Specifically we want to set NODE_ENV and make sure stdio is
// inherited. We also run with --harmony directly so that we don't have to
// respawn immediately. We should be able to reduce some of this complexity
// when jest 0.5 is run on top of iojs.

'use strict';

var grunt = require('grunt');
var path = require('path');

module.exports = function() {
var done = this.async();
grunt.log.writeln('running jest (this may take a while)');
grunt.util.spawn({
cmd: 'node',
args: ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')],
opts: {stdio: 'inherit', env: {NODE_ENV: 'test'}},
}, function(err, result, code) {
if (err) {
grunt.log.error('jest failed');
grunt.log.error(err);
} else {
grunt.log.ok('jest passed');
}
grunt.log.writeln(result.stdout);

done(code === 0);
});
};
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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in a .babelrc file (which gulp-babel reads). You might be able to better share the configuration between this and jest that way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way ahead of you. There are reasons it's not and we'll work them out.

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cache somehow? Seems to take ~3s on my computer which feels weirdly fast.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. My ~/.babel.json doesn't get touched so I'm pretty sure that's not doing something we're not expecting.

.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.