[react-packager] Use transformer name in cache name

Summary:
@public
Shouldn't confuse the cache from files transformed by different transformers. This takes into account the transformer in the cache hash name.

Test Plan:
* start server with --babel
* generate bundle
* start server with --jstransform
* generate bundle
* compare them and they're different
This commit is contained in:
Amjad Masad 2015-05-13 14:44:16 -07:00
parent b47e89a397
commit 5429b5f9cc
3 changed files with 38 additions and 6 deletions

View File

@ -31,6 +31,10 @@ var validateOpts = declareOpts({
type: 'array',
required: true,
},
transformModulePath: {
type:'string',
required: true,
},
});
module.exports = Cache;
@ -162,6 +166,8 @@ function cacheFilePath(options) {
var cacheVersion = options.cacheVersion || '0';
hash.update(cacheVersion);
hash.update(options.transformModulePath);
var name = 'react-packager-cache-' + hash.digest('hex');
return path.join(tmpdir, name);
}

View File

@ -32,10 +32,14 @@ describe('JSTransformer Cache', function() {
describe('getting/setting', function() {
it('calls loader callback for uncached file', function() {
var cache = new Cache({projectRoots: ['/rootDir']});
var cache = new Cache({
projectRoots: ['/rootDir'],
transformModulePath: 'x.js',
});
var loaderCb = jest.genMockFn().mockImpl(function() {
return Promise.resolve();
});
cache.get('/rootDir/someFile', loaderCb);
expect(loaderCb).toBeCalledWith('/rootDir/someFile');
});
@ -48,10 +52,15 @@ describe('JSTransformer Cache', function() {
}
});
});
var cache = new Cache({projectRoots: ['/rootDir']});
var cache = new Cache({
projectRoots: ['/rootDir'],
transformModulePath: 'x.js',
});
var loaderCb = jest.genMockFn().mockImpl(function() {
return Promise.resolve('lol');
});
return cache.get('/rootDir/someFile', loaderCb).then(function(value) {
expect(value).toBe('lol');
});
@ -65,10 +74,15 @@ describe('JSTransformer Cache', function() {
}
});
});
var cache = new Cache({projectRoots: ['/rootDir']});
var cache = new Cache({
projectRoots: ['/rootDir'],
transformModulePath: 'x.js',
});
var loaderCb = jest.genMockFn().mockImpl(function() {
return Promise.resolve('lol');
});
return cache.get('/rootDir/someFile', loaderCb).then(function() {
var shouldNotBeCalled = jest.genMockFn();
return cache.get('/rootDir/someFile', shouldNotBeCalled)
@ -126,8 +140,12 @@ describe('JSTransformer Cache', function() {
});
pit('should load cache from disk', function() {
var cache = new Cache({projectRoots: ['/rootDir']});
var cache = new Cache({
projectRoots: ['/rootDir'],
transformModulePath: 'x.js',
});
var loaderCb = jest.genMockFn();
return cache.get('/rootDir/someFile', loaderCb).then(function(value) {
expect(loaderCb).not.toBeCalled();
expect(value).toBe('oh hai');
@ -152,7 +170,10 @@ describe('JSTransformer Cache', function() {
return 123;
};
var cache = new Cache({projectRoots: ['/rootDir']});
var cache = new Cache({
projectRoots: ['/rootDir'],
transformModulePath: 'x.js',
});
var loaderCb = jest.genMockFn().mockImpl(function() {
return Promise.resolve('new value');
});
@ -193,7 +214,11 @@ describe('JSTransformer Cache', function() {
});
});
var cache = new Cache({projectRoots: ['/rootDir']});
var cache = new Cache({
projectRoots: ['/rootDir'],
transformModulePath: 'x.js',
});
cache.get('/rootDir/bar', function() {
return Promise.resolve('bar value');
});

View File

@ -60,6 +60,7 @@ function Transformer(options) {
resetCache: options.resetCache,
cacheVersion: options.cacheVersion,
projectRoots: options.projectRoots,
transformModulePath: options.transformModulePath,
});
if (options.transformModulePath != null) {