Make the global cache logic aware of the assetDataPlugins transform option

Reviewed By: jeanlauliac

Differential Revision: D6727589

fbshipit-source-id: d15fb501c7b1cd64c5fb494523a9154322a63dc6
This commit is contained in:
Rafael Oleza 2018-01-16 10:17:30 -08:00 committed by Facebook Github Bot
parent dfcaa30f26
commit 3c3d95fb15
5 changed files with 74 additions and 12 deletions

View File

@ -24,6 +24,8 @@ const {
traverseDependencies,
} = require('../traverseDependencies');
const getTransformOptions = require('../../__fixtures__/getTransformOptions');
describe('DeltaCalculator', () => {
const entryModule = createModule({path: '/bundle', name: 'bundle'});
const moduleFoo = createModule({path: '/foo', name: 'foo'});
@ -308,6 +310,14 @@ describe('DeltaCalculator', () => {
});
});
it('should return the same params as the standard options', async () => {
const options = await deltaCalculator.getTransformerOptions();
expect(Object.keys(options).sort()).toEqual(
Object.keys(await getTransformOptions()).sort(),
);
});
it('should handle inlineRequires=true correctly', async () => {
Bundler.prototype.getTransformOptionsForEntryFile.mockReturnValue(
Promise.resolve({

View File

@ -0,0 +1,55 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+javascript_foundation
* @format
*/
'use strict';
const DeltaCalculator = require('../DeltaBundler/DeltaCalculator');
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
async function getTransformOptions(): Promise<JSTransformerOptions> {
const bundler = {
getGlobalTransformOptions() {
return {
enableBabelRCLookup: true,
projectRoot: '/root',
};
},
async getTransformOptionsForEntryFile() {
return {
inlineRequires: true,
};
},
};
const dependencyGraph = {
getWatcher() {
return {on() {}};
},
};
const options = {
assetPlugins: [],
dev: true,
hot: true,
minify: false,
platform: 'ios',
};
const deltaCalculator = new DeltaCalculator(
bundler,
dependencyGraph,
options,
);
return await deltaCalculator.getTransformerOptions();
}
module.exports = getTransformOptions;

View File

@ -439,6 +439,7 @@ class OptionsHasher {
options: TransformOptionsStrict,
): crypto$Hash {
const {
assetDataPlugins,
enableBabelRCLookup,
dev,
hot,
@ -466,8 +467,9 @@ class OptionsHasher {
(+minify << 5),
]),
);
/* eslint-enable no-bitwise */
/* eslint-enable no-bitwise */
hash.update(JSON.stringify(assetDataPlugins));
hash.update(JSON.stringify(platform));
hash.update(JSON.stringify(this.toLocalPath(projectRoot)));

View File

@ -19,7 +19,8 @@ jest.mock('node-fetch', () => mockFetch);
const {URIBasedGlobalTransformCache} = require('../GlobalTransformCache');
const FetchError = require('node-fetch/lib/fetch-error');
const path = require('path');
const getTransformOptions = require('../../__fixtures__/getTransformOptions');
async function fetchResultURIs(
keys: Array<string>,
@ -44,14 +45,8 @@ describe('GlobalTransformCache', () => {
rootPath: __dirname,
storeResults: null,
});
const transformOptions = {
dev: false,
hot: false,
inlineRequires: false,
minify: false,
platform: 'ios',
projectRoot: path.join(__dirname, 'root'),
};
const transformOptions = await getTransformOptions();
const result = await Promise.all([
cache.fetch({
localPath: 'some/where/foo.js',

View File

@ -19,12 +19,12 @@ Object {
exports[`GlobalTransformCache fetches results 1`] = `
Array [
Object {
"code": "/* code from http://globalcache.com/c78d72e5b503433212dce49b558b0ee350b6d578-foo.js */",
"code": "/* code from http://globalcache.com/e4d11b53d671aa56b44f2fdda2cd77b31f3a5cad-foo.js */",
"dependencies": Array [],
"dependencyOffsets": Array [],
},
Object {
"code": "/* code from http://globalcache.com/47637fbb61b7dfeda3a0d0a36241510b4669e4da-bar.js */",
"code": "/* code from http://globalcache.com/bf01163f2c3c2575e7da85343e20e9ff0013bbe8-bar.js */",
"dependencies": Array [],
"dependencyOffsets": Array [],
},