diff --git a/react-packager/src/JSTransformer/Cache.js b/react-packager/src/JSTransformer/Cache.js index 4761d15e..584077b6 100644 --- a/react-packager/src/JSTransformer/Cache.js +++ b/react-packager/src/JSTransformer/Cache.js @@ -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); } diff --git a/react-packager/src/JSTransformer/__tests__/Cache-test.js b/react-packager/src/JSTransformer/__tests__/Cache-test.js index 7ad65818..f91490ba 100644 --- a/react-packager/src/JSTransformer/__tests__/Cache-test.js +++ b/react-packager/src/JSTransformer/__tests__/Cache-test.js @@ -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'); }); diff --git a/react-packager/src/JSTransformer/index.js b/react-packager/src/JSTransformer/index.js index 33e01703..2dc5e20b 100644 --- a/react-packager/src/JSTransformer/index.js +++ b/react-packager/src/JSTransformer/index.js @@ -60,6 +60,7 @@ function Transformer(options) { resetCache: options.resetCache, cacheVersion: options.cacheVersion, projectRoots: options.projectRoots, + transformModulePath: options.transformModulePath, }); if (options.transformModulePath != null) {