Skip to content

Commit e485f69

Browse files
Jean LauliacFacebook Github Bot
Jean Lauliac
authored and
Facebook Github Bot
committed
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
1 parent a50bafa commit e485f69

File tree

1 file changed

+7
-5
lines changed
  • packager/react-packager/src/Bundler

1 file changed

+7
-5
lines changed

packager/react-packager/src/Bundler/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313

1414
const assert = require('assert');
15+
const crypto = require('crypto');
1516
const fs = require('fs');
1617
const Cache = require('../node-haste').Cache;
1718
const Transformer = require('../JSTransformer');
@@ -146,20 +147,21 @@ class Bundler {
146147

147148
opts.projectRoots.forEach(verifyRootExists);
148149

149-
let mtime;
150+
let transformModuleHash;
150151
try {
151-
({mtime} = fs.statSync(opts.transformModulePath));
152-
mtime = String(mtime.getTime());
152+
const transformModuleStr = fs.readFileSync(opts.transformModulePath);
153+
transformModuleHash =
154+
crypto.createHash('sha1').update(transformModuleStr).digest('hex');
153155
} catch (error) {
154-
mtime = '';
156+
transformModuleHash = '';
155157
}
156158

157159
const cacheKeyParts = [
158160
'react-packager-cache',
159161
version,
160162
opts.cacheVersion,
161163
opts.projectRoots.join(',').split(pathSeparator).join('-'),
162-
mtime,
164+
transformModuleHash,
163165
];
164166

165167
this._getModuleId = createModuleIdFactory();

0 commit comments

Comments
 (0)