From b7df3ca666122edd6813dd1a336818b3f5f8a0fc Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Sat, 14 Nov 2015 03:23:46 -0800 Subject: [PATCH] Unbreak jest tests (and travis e2e tests) Reviewed By: mkonicek Differential Revision: D2652002 fb-gh-sync-id: 8aab8da47dd737acc4ee9acddc484bd3bbdf1184 --- react-packager/.babelrc | 2 +- transformer.js | 56 ++++++++++++++--------------------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/react-packager/.babelrc b/react-packager/.babelrc index 3882b9be..c72259da 100644 --- a/react-packager/.babelrc +++ b/react-packager/.babelrc @@ -6,6 +6,7 @@ "syntax-async-functions", "syntax-class-properties", "syntax-trailing-function-commas", + "transform-class-properties", "transform-es2015-arrow-functions", "transform-es2015-block-scoping", "transform-es2015-classes", @@ -17,7 +18,6 @@ "transform-es2015-shorthand-properties", "transform-es2015-spread", "transform-es2015-template-literals", - "transform-class-properties", "transform-flow-strip-types", "transform-object-assign", "transform-object-rest-spread", diff --git a/transformer.js b/transformer.js index 01bb8e07..ce984be9 100644 --- a/transformer.js +++ b/transformer.js @@ -11,51 +11,33 @@ 'use strict'; const babel = require('babel-core'); +const fs = require('fs'); const inlineRequires = require('fbjs-scripts/babel-6/inline-requires'); +const json5 = require('json5'); +const path = require('path'); + +const babelRC = + json5.parse( + fs.readFileSync( + path.resolve(__dirname, 'react-packager', '.babelrc'))); function transform(src, filename, options) { options = options || {}; - const plugins = []; + + const extraPlugins = ['external-helpers-2']; + const extraConfig = { + filename, + sourceFileName: filename, + }; + + const config = Object.assign({}, babelRC, extraConfig); if (options.inlineRequires) { - plugins.push([inlineRequires]); + extraPlugins.push(inlineRequires); } + config.plugins = extraPlugins.concat(config.plugins); - const result = babel.transform(src, { - retainLines: true, - compact: true, - comments: false, - filename, - plugins: plugins.concat([ - // Keep in sync with packager/react-packager/.babelrc - 'external-helpers-2', - 'syntax-async-functions', - 'syntax-class-properties', - 'syntax-jsx', - 'syntax-trailing-function-commas', - 'transform-class-properties', - 'transform-es2015-arrow-functions', - 'transform-es2015-block-scoping', - 'transform-es2015-classes', - 'transform-es2015-computed-properties', - 'transform-es2015-constants', - 'transform-es2015-destructuring', - ['transform-es2015-modules-commonjs', {strict: false, allowTopLevelThis: true}], - 'transform-es2015-parameters', - 'transform-es2015-shorthand-properties', - 'transform-es2015-spread', - 'transform-es2015-template-literals', - 'transform-flow-strip-types', - 'transform-object-assign', - 'transform-object-rest-spread', - 'transform-object-assign', - 'transform-react-display-name', - 'transform-react-jsx', - 'transform-regenerator', - ]), - sourceFileName: filename, - sourceMaps: false, - }); + const result = babel.transform(src, Object.assign({}, babelRC, config)); return { code: result.code