Permalink
Browse files

packager: Bundler: use transform module hash instead of mtime

Summary: mtime is a problem for the global cache, because everyone has different times at which they rebased/cloned the repo. Use the actual content instead. Of course, the file could depend on other files we don't take into account... but the mtime solution was already problematic in that regard, so I assume this is a safe change.

Reviewed By: davidaurelio

Differential Revision: D4237826

fbshipit-source-id: 9dc18eb422cddd4d5ed097d1ebeef4b8c361ff39
  • Loading branch information...
jeanlauliac authored and Facebook Github Bot committed Nov 29, 2016
1 parent a50bafa commit e485f6997defaaf15105f85769118b234ea0d156
Showing with 7 additions and 5 deletions.
  1. +7 −5 packager/react-packager/src/Bundler/index.js
@@ -12,6 +12,7 @@
'use strict';
const assert = require('assert');
const crypto = require('crypto');
const fs = require('fs');
const Cache = require('../node-haste').Cache;
const Transformer = require('../JSTransformer');
@@ -146,20 +147,21 @@ class Bundler {
opts.projectRoots.forEach(verifyRootExists);
let mtime;
let transformModuleHash;
try {
({mtime} = fs.statSync(opts.transformModulePath));
mtime = String(mtime.getTime());
const transformModuleStr = fs.readFileSync(opts.transformModulePath);
transformModuleHash =
crypto.createHash('sha1').update(transformModuleStr).digest('hex');
} catch (error) {
mtime = '';
transformModuleHash = '';
}
const cacheKeyParts = [
'react-packager-cache',
version,
opts.cacheVersion,
opts.projectRoots.join(',').split(pathSeparator).join('-'),
mtime,
transformModuleHash,
];
this._getModuleId = createModuleIdFactory();

0 comments on commit e485f69

Please sign in to comment.