Introduce transformer `cacheKey`

Summary:public

At the moment, the packager's cache can only be broken by changing packager's `package.json` version,by supplying a different `cacheKey` or by updating the `mtime` of the transformer. We need to add support for breaking the cache key when a plugin the transformer use gets updated. To do so, lets introduce a property on the transformer, namely `cacheKey`.

Reviewed By: davidaurelio

Differential Revision: D2940267

fb-gh-sync-id: 82c937d06c73abd32708bf97afe5f308c2a3b565
shipit-source-id: 82c937d06c73abd32708bf97afe5f308c2a3b565
This commit is contained in:
Martín Bigio 2016-02-17 10:00:35 -08:00 committed by facebook-github-bot-4
parent 109532086f
commit ccbf9273fe
1 changed files with 16 additions and 7 deletions

View File

@ -103,15 +103,24 @@ class Bundler {
mtime = '';
}
const cacheKeyParts = [
'react-packager-cache',
version,
opts.cacheVersion,
opts.projectRoots.join(',').split(path.sep).join('-'),
mtime,
];
if (opts.transformModulePath) {
const transformer = require(opts.transformModulePath);
if (typeof transformer.cacheKey !== 'undefined') {
cacheKeyParts.push(transformer.cacheKey);
}
}
this._cache = new Cache({
resetCache: opts.resetCache,
cacheKey: [
'react-packager-cache',
version,
opts.cacheVersion,
opts.projectRoots.join(',').split(path.sep).join('-'),
mtime
].join('$'),
cacheKey: cacheKeyParts.join('$'),
});
this._resolver = new Resolver({