mirror of https://github.com/status-im/metro.git
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
This commit is contained in:
parent
305c6ed6f9
commit
d4008ab33c
|
@ -12,6 +12,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const crypto = require('crypto');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const Cache = require('../node-haste').Cache;
|
const Cache = require('../node-haste').Cache;
|
||||||
const Transformer = require('../JSTransformer');
|
const Transformer = require('../JSTransformer');
|
||||||
|
@ -146,12 +147,13 @@ class Bundler {
|
||||||
|
|
||||||
opts.projectRoots.forEach(verifyRootExists);
|
opts.projectRoots.forEach(verifyRootExists);
|
||||||
|
|
||||||
let mtime;
|
let transformModuleHash;
|
||||||
try {
|
try {
|
||||||
({mtime} = fs.statSync(opts.transformModulePath));
|
const transformModuleStr = fs.readFileSync(opts.transformModulePath);
|
||||||
mtime = String(mtime.getTime());
|
transformModuleHash =
|
||||||
|
crypto.createHash('sha1').update(transformModuleStr).digest('hex');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
mtime = '';
|
transformModuleHash = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const cacheKeyParts = [
|
const cacheKeyParts = [
|
||||||
|
@ -159,7 +161,7 @@ class Bundler {
|
||||||
version,
|
version,
|
||||||
opts.cacheVersion,
|
opts.cacheVersion,
|
||||||
opts.projectRoots.join(',').split(pathSeparator).join('-'),
|
opts.projectRoots.join(',').split(pathSeparator).join('-'),
|
||||||
mtime,
|
transformModuleHash,
|
||||||
];
|
];
|
||||||
|
|
||||||
this._getModuleId = createModuleIdFactory();
|
this._getModuleId = createModuleIdFactory();
|
||||||
|
|
Loading…
Reference in New Issue