Skip to content

Commit

Permalink
packager: Bundler: use stable paths for cache key
Browse files Browse the repository at this point in the history
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
Jean Lauliac authored and Facebook Github Bot committed Nov 29, 2016
1 parent e485f69 commit 188093a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packager/react-packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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,
];

Expand Down Expand Up @@ -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];
};
}

Expand Down

0 comments on commit 188093a

Please sign in to comment.