Skip to content

Commit 188093a

Browse files
Jean LauliacFacebook Github Bot
Jean Lauliac
authored and
Facebook Github Bot
committed
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
1 parent e485f69 commit 188093a

File tree

1 file changed

+10
-5
lines changed
  • packager/react-packager/src/Bundler

1 file changed

+10
-5
lines changed

packager/react-packager/src/Bundler/index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const HMRBundle = require('./HMRBundle');
2222
const ModuleTransport = require('../lib/ModuleTransport');
2323
const declareOpts = require('../lib/declareOpts');
2424
const imageSize = require('image-size');
25+
const path = require('path');
2526
const version = require('../../../../package.json').version;
2627
const denodeify = require('denodeify');
2728

@@ -156,11 +157,15 @@ class Bundler {
156157
transformModuleHash = '';
157158
}
158159

160+
const stableProjectRoots = opts.projectRoots.map(p => {
161+
return path.relative(path.join(__dirname, '../../../..'), p);
162+
});
163+
159164
const cacheKeyParts = [
160165
'react-packager-cache',
161166
version,
162167
opts.cacheVersion,
163-
opts.projectRoots.join(',').split(pathSeparator).join('-'),
168+
stableProjectRoots.join(',').split(pathSeparator).join('-'),
164169
transformModuleHash,
165170
];
166171

@@ -775,12 +780,12 @@ function verifyRootExists(root) {
775780
function createModuleIdFactory() {
776781
const fileToIdMap = Object.create(null);
777782
let nextId = 0;
778-
return ({path}) => {
779-
if (!(path in fileToIdMap)) {
780-
fileToIdMap[path] = nextId;
783+
return ({path: modulePath}) => {
784+
if (!(modulePath in fileToIdMap)) {
785+
fileToIdMap[modulePath] = nextId;
781786
nextId += 1;
782787
}
783-
return fileToIdMap[path];
788+
return fileToIdMap[modulePath];
784789
};
785790
}
786791

0 commit comments

Comments
 (0)