Permalink
Browse files

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
  • Loading branch information...
jeanlauliac authored and Facebook Github Bot committed Nov 29, 2016
1 parent e485f69 commit 188093ae29a7d1d7ba74ba35ce5f37984fc9c6f1
Showing with 10 additions and 5 deletions.
  1. +10 −5 packager/react-packager/src/Bundler/index.js
@@ -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];
};
}

0 comments on commit 188093a

Please sign in to comment.