From e485f6997defaaf15105f85769118b234ea0d156 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 29 Nov 2016 11:53:16 -0800 Subject: [PATCH] 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 --- packager/react-packager/src/Bundler/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packager/react-packager/src/Bundler/index.js b/packager/react-packager/src/Bundler/index.js index 374fbb421d565d..7c20d1177c50c3 100644 --- a/packager/react-packager/src/Bundler/index.js +++ b/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,12 +147,13 @@ 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 = [ @@ -159,7 +161,7 @@ class Bundler { version, opts.cacheVersion, opts.projectRoots.join(',').split(pathSeparator).join('-'), - mtime, + transformModuleHash, ]; this._getModuleId = createModuleIdFactory();