inline requires + preprocessor updates
Reviewed By: @DmitrySoshnikov Differential Revision: D2455903
This commit is contained in:
parent
f802998599
commit
3fca7f4d7b
|
@ -8,10 +8,18 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
var transformer = require('../packager/transformer.js');
|
||||
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
|
||||
const path = require('path');
|
||||
const transformer = require('../packager/transformer.js');
|
||||
|
||||
module.exports = {
|
||||
process(src, file) {
|
||||
return transformer.transform(src, file).code;
|
||||
}
|
||||
},
|
||||
|
||||
getCacheKey: createCacheKeyFunction([
|
||||
__filename,
|
||||
path.join(__dirname, '../packager/transformer.js'),
|
||||
path.join(__dirname, '../node_modules/babel-core/package.json'),
|
||||
]),
|
||||
};
|
||||
|
|
|
@ -2071,6 +2071,308 @@
|
|||
"from": "eslint-plugin-react@3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-3.3.1.tgz"
|
||||
},
|
||||
"fbjs-scripts": {
|
||||
"version": "0.2.1",
|
||||
"from": "fbjs-scripts@>=0.2.1 <0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/fbjs-scripts/-/fbjs-scripts-0.2.1.tgz",
|
||||
"dependencies": {
|
||||
"core-js": {
|
||||
"version": "1.1.4",
|
||||
"from": "core-js@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.1.4.tgz"
|
||||
},
|
||||
"gulp-util": {
|
||||
"version": "3.0.6",
|
||||
"from": "gulp-util@>=3.0.4 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/gulp-util/-/gulp-util-3.0.6.tgz",
|
||||
"dependencies": {
|
||||
"array-differ": {
|
||||
"version": "1.0.0",
|
||||
"from": "array-differ@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/array-differ/-/array-differ-1.0.0.tgz"
|
||||
},
|
||||
"array-uniq": {
|
||||
"version": "1.0.2",
|
||||
"from": "array-uniq@>=1.0.2 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.2.tgz"
|
||||
},
|
||||
"beeper": {
|
||||
"version": "1.1.0",
|
||||
"from": "beeper@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/beeper/-/beeper-1.1.0.tgz"
|
||||
},
|
||||
"dateformat": {
|
||||
"version": "1.0.11",
|
||||
"from": "dateformat@>=1.0.11 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.11.tgz",
|
||||
"dependencies": {
|
||||
"get-stdin": {
|
||||
"version": "5.0.0",
|
||||
"from": "get-stdin@*",
|
||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.0.tgz"
|
||||
},
|
||||
"meow": {
|
||||
"version": "3.3.0",
|
||||
"from": "meow@*",
|
||||
"resolved": "https://registry.npmjs.org/meow/-/meow-3.3.0.tgz",
|
||||
"dependencies": {
|
||||
"camelcase-keys": {
|
||||
"version": "1.0.0",
|
||||
"from": "camelcase-keys@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-1.0.0.tgz",
|
||||
"dependencies": {
|
||||
"camelcase": {
|
||||
"version": "1.2.1",
|
||||
"from": "camelcase@>=1.0.1 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz"
|
||||
},
|
||||
"map-obj": {
|
||||
"version": "1.0.1",
|
||||
"from": "map-obj@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"indent-string": {
|
||||
"version": "1.2.2",
|
||||
"from": "indent-string@>=1.1.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/indent-string/-/indent-string-1.2.2.tgz",
|
||||
"dependencies": {
|
||||
"get-stdin": {
|
||||
"version": "4.0.1",
|
||||
"from": "get-stdin@>=4.0.1 <5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz"
|
||||
},
|
||||
"repeating": {
|
||||
"version": "1.1.3",
|
||||
"from": "repeating@>=1.1.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/repeating/-/repeating-1.1.3.tgz",
|
||||
"dependencies": {
|
||||
"is-finite": {
|
||||
"version": "1.0.1",
|
||||
"from": "is-finite@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.1.tgz",
|
||||
"dependencies": {
|
||||
"number-is-nan": {
|
||||
"version": "1.0.0",
|
||||
"from": "number-is-nan@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"lodash._reescape": {
|
||||
"version": "3.0.0",
|
||||
"from": "lodash._reescape@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._reescape/-/lodash._reescape-3.0.0.tgz"
|
||||
},
|
||||
"lodash._reevaluate": {
|
||||
"version": "3.0.0",
|
||||
"from": "lodash._reevaluate@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._reevaluate/-/lodash._reevaluate-3.0.0.tgz"
|
||||
},
|
||||
"lodash._reinterpolate": {
|
||||
"version": "3.0.0",
|
||||
"from": "lodash._reinterpolate@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz"
|
||||
},
|
||||
"lodash.template": {
|
||||
"version": "3.6.2",
|
||||
"from": "lodash.template@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-3.6.2.tgz",
|
||||
"dependencies": {
|
||||
"lodash._basecopy": {
|
||||
"version": "3.0.1",
|
||||
"from": "lodash._basecopy@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz"
|
||||
},
|
||||
"lodash._basetostring": {
|
||||
"version": "3.0.1",
|
||||
"from": "lodash._basetostring@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz"
|
||||
},
|
||||
"lodash._basevalues": {
|
||||
"version": "3.0.0",
|
||||
"from": "lodash._basevalues@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basevalues/-/lodash._basevalues-3.0.0.tgz"
|
||||
},
|
||||
"lodash._isiterateecall": {
|
||||
"version": "3.0.9",
|
||||
"from": "lodash._isiterateecall@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz"
|
||||
},
|
||||
"lodash.escape": {
|
||||
"version": "3.0.0",
|
||||
"from": "lodash.escape@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-3.0.0.tgz"
|
||||
},
|
||||
"lodash.keys": {
|
||||
"version": "3.1.2",
|
||||
"from": "lodash.keys@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
|
||||
"dependencies": {
|
||||
"lodash._getnative": {
|
||||
"version": "3.9.1",
|
||||
"from": "lodash._getnative@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz"
|
||||
},
|
||||
"lodash.isarguments": {
|
||||
"version": "3.0.4",
|
||||
"from": "lodash.isarguments@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.0.4.tgz"
|
||||
},
|
||||
"lodash.isarray": {
|
||||
"version": "3.0.4",
|
||||
"from": "lodash.isarray@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"lodash.restparam": {
|
||||
"version": "3.6.1",
|
||||
"from": "lodash.restparam@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz"
|
||||
},
|
||||
"lodash.templatesettings": {
|
||||
"version": "3.1.0",
|
||||
"from": "lodash.templatesettings@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-3.1.0.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"from": "minimist@>=1.1.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz"
|
||||
},
|
||||
"multipipe": {
|
||||
"version": "0.1.2",
|
||||
"from": "multipipe@>=0.1.2 <0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/multipipe/-/multipipe-0.1.2.tgz",
|
||||
"dependencies": {
|
||||
"duplexer2": {
|
||||
"version": "0.0.2",
|
||||
"from": "duplexer2@0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz",
|
||||
"dependencies": {
|
||||
"readable-stream": {
|
||||
"version": "1.1.13",
|
||||
"from": "readable-stream@>=1.1.9 <1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.13.tgz",
|
||||
"dependencies": {
|
||||
"core-util-is": {
|
||||
"version": "1.0.1",
|
||||
"from": "core-util-is@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz"
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"from": "isarray@0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"from": "string_decoder@>=0.10.0 <0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz"
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.1",
|
||||
"from": "inherits@>=2.0.1 <2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"replace-ext": {
|
||||
"version": "0.0.1",
|
||||
"from": "replace-ext@0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-0.0.1.tgz"
|
||||
},
|
||||
"vinyl": {
|
||||
"version": "0.5.3",
|
||||
"from": "vinyl@>=0.5.0 <0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/vinyl/-/vinyl-0.5.3.tgz",
|
||||
"dependencies": {
|
||||
"clone": {
|
||||
"version": "1.0.2",
|
||||
"from": "clone@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.2.tgz"
|
||||
},
|
||||
"clone-stats": {
|
||||
"version": "0.0.1",
|
||||
"from": "clone-stats@>=0.0.1 <0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-0.0.1.tgz"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "3.0.0",
|
||||
"from": "object-assign@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz"
|
||||
},
|
||||
"through2": {
|
||||
"version": "2.0.0",
|
||||
"from": "through2@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.0.tgz",
|
||||
"dependencies": {
|
||||
"readable-stream": {
|
||||
"version": "2.0.2",
|
||||
"from": "readable-stream@>=2.0.0 <2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.2.tgz",
|
||||
"dependencies": {
|
||||
"core-util-is": {
|
||||
"version": "1.0.1",
|
||||
"from": "core-util-is@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz"
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.1",
|
||||
"from": "inherits@>=2.0.1 <2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz"
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"from": "isarray@0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "1.0.3",
|
||||
"from": "process-nextick-args@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.3.tgz"
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"from": "string_decoder@>=0.10.0 <0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz"
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.1",
|
||||
"from": "util-deprecate@>=1.0.1 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.1.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.0",
|
||||
"from": "xtend@>=4.0.0 <4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.0.tgz"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.1.2",
|
||||
"from": "graceful-fs@4.1.2",
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
"chalk": "^1.1.1",
|
||||
"connect": "^2.8.3",
|
||||
"debug": "^2.2.0",
|
||||
"fbjs-scripts": "^0.2.1",
|
||||
"graceful-fs": "^4.1.2",
|
||||
"image-size": "^0.3.5",
|
||||
"immutable": "^3.7.5",
|
||||
|
|
|
@ -10,20 +10,26 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
var babel = require('babel-core');
|
||||
const babel = require('babel-core');
|
||||
const inlineRequires = require('fbjs-scripts/babel/inline-requires');
|
||||
|
||||
function transform(srcTxt, filename, options) {
|
||||
var plugins = [];
|
||||
function transform(src, filename, options) {
|
||||
const plugins = [];
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
plugins = plugins.concat(['node-env-inline', 'dunderscore-dev-inline']);
|
||||
plugins.push('node-env-inline', 'dunderscore-dev-inline');
|
||||
} else if (process.env.NODE_ENV === 'test') {
|
||||
plugins.push({
|
||||
position: 'after',
|
||||
transformer: inlineRequires,
|
||||
});
|
||||
}
|
||||
|
||||
var result = babel.transform(srcTxt, {
|
||||
const result = babel.transform(src, {
|
||||
retainLines: true,
|
||||
compact: true,
|
||||
comments: false,
|
||||
filename: filename,
|
||||
filename,
|
||||
whitelist: [
|
||||
'es6.arrowFunctions',
|
||||
'es6.blockScoping',
|
||||
|
@ -42,24 +48,21 @@ function transform(srcTxt, filename, options) {
|
|||
'react.displayName',
|
||||
'regenerator',
|
||||
],
|
||||
plugins: plugins,
|
||||
plugins,
|
||||
sourceFileName: filename,
|
||||
sourceMaps: false,
|
||||
extra: options || {},
|
||||
});
|
||||
|
||||
return {
|
||||
code: result.code,
|
||||
code: result.code
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = function(data, callback) {
|
||||
var result;
|
||||
let result;
|
||||
try {
|
||||
result = transform(
|
||||
data.sourceCode,
|
||||
data.filename
|
||||
);
|
||||
result = transform(data.sourceCode, data.filename);
|
||||
} catch (e) {
|
||||
callback(e);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue