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

Build with babel-preset-fbjs #6876

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
{
"presets": ["react"],
"ignore": ["third_party"],
"ignore": [
"third_party",
"node_modules",
],
"plugins": [
"fbjs-scripts/babel-6/dev-expression",
"syntax-trailing-function-commas",
"babel-plugin-transform-object-rest-spread",
"transform-es2015-template-literals",
"transform-es2015-literals",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
["transform-es2015-classes", { "loose": true }],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
"transform-es2015-computed-properties",
"transform-es2015-for-of",
"check-es2015-constants",
["transform-es2015-spread", { "loose": true }],
"transform-es2015-parameters",
["transform-es2015-destructuring", { "loose": true }],
"transform-es2015-block-scoping",
"transform-es2015-modules-commonjs",
"transform-es3-member-expression-literals",
"transform-es3-property-literals",
"./scripts/babel/transform-object-assign-require",
"transform-react-jsx-source"
]
}
15 changes: 10 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var babel = require('gulp-babel');
var flatten = require('gulp-flatten');
var del = require('del');

var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
var fbjsConfigurePreset = require('babel-preset-fbjs/configure');

var paths = {
react: {
Expand Down Expand Up @@ -46,9 +46,14 @@ var moduleMap = Object.assign(
}
);

var babelOpts = {
plugins: [
[babelPluginModules, { map: moduleMap }],
var babelOptions = {
presets: [
fbjsConfigurePreset({
stripDEV: true,
rewriteModules: {
map: moduleMap,
},
}),
],
};

Expand All @@ -59,7 +64,7 @@ gulp.task('react:clean', function() {
gulp.task('react:modules', function() {
return gulp
.src(paths.react.src)
.pipe(babel(babelOpts))
.pipe(babel(babelOptions))
.pipe(flatten())
.pipe(gulp.dest(paths.react.lib));
});
Expand Down
23 changes: 2 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,8 @@
"babel-cli": "^6.6.5",
"babel-core": "^6.0.0",
"babel-eslint": "^5.0.0",
"babel-plugin-check-es2015-constants": "^6.5.0",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.5.0",
"babel-plugin-transform-es2015-block-scoping": "^6.5.0",
"babel-plugin-transform-es2015-classes": "^6.5.2",
"babel-plugin-transform-es2015-computed-properties": "^6.5.2",
"babel-plugin-transform-es2015-destructuring": "^6.5.0",
"babel-plugin-transform-es2015-for-of": "^6.5.2",
"babel-plugin-transform-es2015-literals": "^6.5.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2",
"babel-plugin-transform-es2015-object-super": "^6.5.0",
"babel-plugin-transform-es2015-parameters": "^6.5.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.5.0",
"babel-plugin-transform-es2015-spread": "^6.5.2",
"babel-plugin-transform-es2015-template-literals": "^6.5.2",
"babel-plugin-transform-es3-member-expression-literals": "^6.5.0",
"babel-plugin-transform-es3-property-literals": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-plugin-transform-react-jsx-source": "^6.8.0",
"babel-preset-react": "^6.5.0",
"babel-preset-fbjs": "^2.0.0-alpha.1",
"browserify": "^13.0.0",
"bundle-collapser": "^1.1.1",
"coffee-script": "^1.8.0",
Expand All @@ -40,7 +21,7 @@
"eslint-plugin-react": "4.1.0",
"eslint-plugin-react-internal": "file:eslint-rules",
"fbjs": "^0.8.1",
"fbjs-scripts": "^0.6.0",
"fbjs-scripts": "^0.7.0",
"flow-bin": "^0.24.0",
"glob": "^6.0.1",
"grunt": "^0.4.5",
Expand Down
36 changes: 18 additions & 18 deletions scripts/jest/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,26 @@ var tsPreprocessor = require('./ts-preprocessor');

// 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 babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
var fbjsConfigurePreset = require('babel-preset-fbjs/configure');
var createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');

// Use require.resolve to be resilient to file moves, npm updates, etc
var pathToBabel = path.join(require.resolve('babel-core'), '..', 'package.json');
var pathToModuleMap = require.resolve('fbjs/module-map');
var pathToBabelPluginDev = require.resolve('fbjs-scripts/babel-6/dev-expression');
var pathToBabelPluginModules = require.resolve('fbjs-scripts/babel-6/rewrite-modules');
var pathToBabelrc = path.join(__dirname, '..', '..', '.babelrc');
var pathToFBJSPreset = path.join(require.resolve('babel-preset-fbjs'), '..', 'package.json');
var pathToModuleMap = require.resolve('fbjs/module-map');

// TODO: make sure this stays in sync with gulpfile
var babelOptions = {
plugins: [
[babelPluginModules, {
map: Object.assign(
{},
moduleMap,
{
'object-assign': 'object-assign',
}
),
}],
presets: [
fbjsConfigurePreset({
rewriteModules: {
map: Object.assign(
{'object-assign': 'object-assign'},
require('fbjs/module-map')
),
},
}),
],
retainLines: true,
};
Expand All @@ -52,13 +49,17 @@ module.exports = {
!filePath.match(/\/node_modules\//) &&
!filePath.match(/\/third_party\//)
) {
return babel.transform(
var code =
babel.transform(
src,
Object.assign(
{filename: path.relative(process.cwd(), filePath)},
babelOptions
)
).code;
if (/ReactElementValidator\-test/.test(filePath))
console.log(code);
Copy link
Member Author

Choose a reason for hiding this comment

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

oooooops, this is how I try to debug to see if the transform did something weird. This would obviously go away.

return code;
}
return src;
},
Expand All @@ -67,8 +68,7 @@ module.exports = {
__filename,
pathToBabel,
pathToBabelrc,
pathToFBJSPreset,
pathToModuleMap,
pathToBabelPluginDev,
pathToBabelPluginModules,
]),
};