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,
inlineRequires: false,
platform: undefined,
projectRoots,
projectRoot: projectRoots[0],
},
},
},

View File

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

View File

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

View File

@ -383,7 +383,7 @@ class OptionsHasher {
*/
hashTransformOptions(hash: crypto$Hash, options: TransformOptions): crypto$Hash {
const {
generateSourceMaps, dev, hot, inlineRequires, platform, projectRoots,
generateSourceMaps, dev, hot, inlineRequires, platform, projectRoot,
...unknowns,
} = options;
const unknownKeys = Object.keys(unknowns);
@ -401,14 +401,17 @@ class OptionsHasher {
if (typeof inlineRequires === 'object') {
relativeBlacklist = this.relativizeFilePaths(Object.keys(inlineRequires.blacklist));
}
const relativeProjectRoots = this.relativizeFilePaths(projectRoots);
const optionTuple = [relativeBlacklist, relativeProjectRoots];
const relativeProjectRoot = this.relativizeFilePath(projectRoot);
const optionTuple = [relativeBlacklist, relativeProjectRoot];
hash.update(JSON.stringify(optionTuple));
return hash;
}
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,
inlineRequires: false,
platform: 'ios',
projectRoots: [path.join(__dirname, 'root')],
projectRoot: path.join(__dirname, 'root'),
},
};
const result = await Promise.all([cache.fetch({

View File

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

View File

@ -30,19 +30,19 @@ const {compactMapping} = require('./src/Bundler/source-map');
const getBabelRC = (function() {
let babelRC = null;
return function _getBabelRC(projectRoots) {
return function _getBabelRC(projectRoot) {
if (babelRC !== null) {
return 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
// this location.
let projectBabelRCPath;
if (projectRoots && projectRoots.length > 0) {
projectBabelRCPath = path.resolve(projectRoots[0], '.babelrc');
if (projectRoot) {
projectBabelRCPath = path.resolve(projectRoot, '.babelrc');
}
// If a .babelrc file doesn't exist in the project,
@ -70,7 +70,7 @@ const getBabelRC = (function() {
* config object with the appropriate plugins.
*/
function buildBabelConfig(filename, options) {
const babelRC = getBabelRC(options.projectRoots);
const babelRC = getBabelRC(options.projectRoot);
const extraConfig = {
code: false,