Pass only the first projectRoot to transform options

Reviewed By: davidaurelio

Differential Revision: D4955013

fbshipit-source-id: c07254f54a61ad71bf4cf153c97c8e4149fd4809
This commit is contained in:
Karol Kuczmarski 2017-04-28 11:04:35 -07:00 committed by Facebook Github Bot
parent 0c7d61ccc0
commit ff3f15b9ad
7 changed files with 18 additions and 15 deletions

View File

@ -171,7 +171,7 @@ describe('Bundler', function() {
hot: false, hot: false,
inlineRequires: false, inlineRequires: false,
platform: undefined, platform: undefined,
projectRoots, projectRoot: projectRoots[0],
}, },
}, },
}, },

View File

@ -821,7 +821,7 @@ class Bundler {
hot, hot,
inlineRequires: extraOptions.inlineRequires || false, inlineRequires: extraOptions.inlineRequires || false,
platform, platform,
projectRoots: options.projectRoots, projectRoot: options.projectRoots[0],
} }
}, },
preloadedModules: extraOptions.preloadedModules, preloadedModules: extraOptions.preloadedModules,

View File

@ -41,7 +41,7 @@ export type TransformOptions = {|
+hot: boolean, +hot: boolean,
+inlineRequires: {+blacklist: {[string]: true}} | boolean, +inlineRequires: {+blacklist: {[string]: true}} | boolean,
+platform: string, +platform: string,
+projectRoots: Array<string>, +projectRoot: string,
|}; |};
export type Options = {| export type Options = {|

View File

@ -383,7 +383,7 @@ class OptionsHasher {
*/ */
hashTransformOptions(hash: crypto$Hash, options: TransformOptions): crypto$Hash { hashTransformOptions(hash: crypto$Hash, options: TransformOptions): crypto$Hash {
const { const {
generateSourceMaps, dev, hot, inlineRequires, platform, projectRoots, generateSourceMaps, dev, hot, inlineRequires, platform, projectRoot,
...unknowns, ...unknowns,
} = options; } = options;
const unknownKeys = Object.keys(unknowns); const unknownKeys = Object.keys(unknowns);
@ -401,14 +401,17 @@ class OptionsHasher {
if (typeof inlineRequires === 'object') { if (typeof inlineRequires === 'object') {
relativeBlacklist = this.relativizeFilePaths(Object.keys(inlineRequires.blacklist)); relativeBlacklist = this.relativizeFilePaths(Object.keys(inlineRequires.blacklist));
} }
const relativeProjectRoots = this.relativizeFilePaths(projectRoots); const relativeProjectRoot = this.relativizeFilePath(projectRoot);
const optionTuple = [relativeBlacklist, relativeProjectRoots]; const optionTuple = [relativeBlacklist, relativeProjectRoot];
hash.update(JSON.stringify(optionTuple)); hash.update(JSON.stringify(optionTuple));
return hash; return hash;
} }
relativizeFilePaths(filePaths: Array<string>): Array<string> { relativizeFilePaths(filePaths: Array<string>): Array<string> {
return filePaths.map(filepath => path.relative(this._rootPath, filepath)); return filePaths.map(this.relativizeFilePath);
}
relativizeFilePath(filePath: string): string {
return path.relative(this._rootPath, filePath);
} }
} }

View File

@ -51,7 +51,7 @@ describe('GlobalTransformCache', () => {
hot: false, hot: false,
inlineRequires: false, inlineRequires: false,
platform: 'ios', platform: 'ios',
projectRoots: [path.join(__dirname, 'root')], projectRoot: path.join(__dirname, 'root'),
}, },
}; };
const result = await Promise.all([cache.fetch({ const result = await Promise.all([cache.fetch({

View File

@ -19,12 +19,12 @@ Object {
exports[`GlobalTransformCache fetches results 1`] = ` exports[`GlobalTransformCache fetches results 1`] = `
Array [ Array [
Object { Object {
"code": "/* code from http://globalcache.com/57c9f999b0df46812db2a6bea665f5feb9d448ff-foo.js */", "code": "/* code from http://globalcache.com/cd6df9b7e86839dafc5e9b5b493a28cbc55074e7-foo.js */",
"dependencies": Array [], "dependencies": Array [],
"dependencyOffsets": Array [], "dependencyOffsets": Array [],
}, },
Object { Object {
"code": "/* code from http://globalcache.com/df53b0670d117d6b35ce58ff64d09909ece46a09-bar.js */", "code": "/* code from http://globalcache.com/6329a317fcf94d74cc9a1de6442ee7c25e27a507-bar.js */",
"dependencies": Array [], "dependencies": Array [],
"dependencyOffsets": Array [], "dependencyOffsets": Array [],
}, },

View File

@ -30,19 +30,19 @@ const {compactMapping} = require('./src/Bundler/source-map');
const getBabelRC = (function() { const getBabelRC = (function() {
let babelRC = null; let babelRC = null;
return function _getBabelRC(projectRoots) { return function _getBabelRC(projectRoot) {
if (babelRC !== null) { if (babelRC !== null) {
return babelRC; return babelRC;
} }
babelRC = {plugins: []}; // empty babelrc babelRC = {plugins: []}; // empty babelrc
// Let's look for the .babelrc in the first project root. // Let's look for the .babelrc in the project root.
// In the future let's look into adding a command line option to specify // In the future let's look into adding a command line option to specify
// this location. // this location.
let projectBabelRCPath; let projectBabelRCPath;
if (projectRoots && projectRoots.length > 0) { if (projectRoot) {
projectBabelRCPath = path.resolve(projectRoots[0], '.babelrc'); projectBabelRCPath = path.resolve(projectRoot, '.babelrc');
} }
// If a .babelrc file doesn't exist in the project, // If a .babelrc file doesn't exist in the project,
@ -70,7 +70,7 @@ const getBabelRC = (function() {
* config object with the appropriate plugins. * config object with the appropriate plugins.
*/ */
function buildBabelConfig(filename, options) { function buildBabelConfig(filename, options) {
const babelRC = getBabelRC(options.projectRoots); const babelRC = getBabelRC(options.projectRoot);
const extraConfig = { const extraConfig = {
code: false, code: false,