packager: Bundler: use stable paths for cache key

Summary: For having a global cache, we need cache keys that are the same from different machines, so we cannot include user/machine-specific information. In that regard, I suggest we consider the paths relatively to the install directory of the React Native instead of being absolute, so that they are more chances they stay stables between different installations, users, machines.

Reviewed By: davidaurelio

Differential Revision: D4237840

fbshipit-source-id: d864b9739550ac2c95d5693db12bd1592411f80a
This commit is contained in:
Jean Lauliac 2016-11-29 11:53:19 -08:00 committed by Facebook Github Bot
parent d4008ab33c
commit 2322db4f81
1 changed files with 10 additions and 5 deletions

View File

@ -22,6 +22,7 @@ const HMRBundle = require('./HMRBundle');
const ModuleTransport = require('../lib/ModuleTransport');
const declareOpts = require('../lib/declareOpts');
const imageSize = require('image-size');
const path = require('path');
const version = require('../../../../package.json').version;
const denodeify = require('denodeify');
@ -156,11 +157,15 @@ class Bundler {
transformModuleHash = '';
}
const stableProjectRoots = opts.projectRoots.map(p => {
return path.relative(path.join(__dirname, '../../../..'), p);
});
const cacheKeyParts = [
'react-packager-cache',
version,
opts.cacheVersion,
opts.projectRoots.join(',').split(pathSeparator).join('-'),
stableProjectRoots.join(',').split(pathSeparator).join('-'),
transformModuleHash,
];
@ -775,12 +780,12 @@ function verifyRootExists(root) {
function createModuleIdFactory() {
const fileToIdMap = Object.create(null);
let nextId = 0;
return ({path}) => {
if (!(path in fileToIdMap)) {
fileToIdMap[path] = nextId;
return ({path: modulePath}) => {
if (!(modulePath in fileToIdMap)) {
fileToIdMap[modulePath] = nextId;
nextId += 1;
}
return fileToIdMap[path];
return fileToIdMap[modulePath];
};
}