[react-packager] Hash cache file name information to avoid long names

This commit is contained in:
Amjad Masad 2015-03-19 17:03:24 -07:00
parent 3fd4ed1464
commit c68fc1a976
3 changed files with 18 additions and 16 deletions

View File

@ -1,6 +1,6 @@
{
"name": "react-native-cli",
"version": "0.1.0",
"version": "0.1.1",
"description": "Build native apps with React!",
"repository": {
"type": "git",

View File

@ -1,13 +1,14 @@
'use strict';
var path = require('path');
var version = require('../../../../package.json').version;
var tmpdir = require('os').tmpDir();
var isAbsolutePath = require('absolute-path');
var _ = require('underscore');
var crypto = require('crypto');
var declareOpts = require('../lib/declareOpts');
var fs = require('fs');
var _ = require('underscore');
var isAbsolutePath = require('absolute-path');
var path = require('path');
var q = require('q');
var tmpdir = require('os').tmpDir();
var version = require('../../../../package.json').version;
var Promise = q.Promise;
@ -146,15 +147,15 @@ function loadCacheSync(cachePath) {
}
function cacheFilePath(options) {
var hash = crypto.createHash('md5');
hash.update(version);
var roots = options.projectRoots.join(',').split(path.sep).join('-');
hash.update(roots);
var cacheVersion = options.cacheVersion || '0';
return path.join(
tmpdir,
[
'react-packager-cache',
version,
cacheVersion,
roots,
].join('-')
);
hash.update(cacheVersion);
var name = 'react-packager-cache-' + hash.digest('hex');
return path.join(tmpdir, name);
}

View File

@ -4,6 +4,7 @@ jest
.dontMock('underscore')
.dontMock('path')
.dontMock('absolute-path')
.dontMock('crypto')
.dontMock('../Cache');
var q = require('q');
@ -19,7 +20,7 @@ describe('JSTransformer Cache', function() {
Cache = require('../Cache');
});
describe('getting/settig', function() {
describe('getting/setting', function() {
it('calls loader callback for uncached file', function() {
var cache = new Cache({projectRoots: ['/rootDir']});
var loaderCb = jest.genMockFn().mockImpl(function() {