Get rid of outdated_dependencies

Reviewed By: jeanlauliac

Differential Revision: D6485979

fbshipit-source-id: 8cf21a8c531d96df93f66e1cc465fe7ae044ef8e
This commit is contained in:
Rafael Oleza 2017-12-05 10:38:05 -08:00 committed by Facebook Github Bot
parent d8cb904104
commit 0e583a981f
4 changed files with 24 additions and 52 deletions

View File

@ -37,10 +37,7 @@ export type CachedResult = {
map: CompactRawMappings,
};
export type TransformCacheResult = {|
+result: ?CachedResult,
+outdatedDependencies: $ReadOnlyArray<string>,
|};
export type TransformCacheResult = ?CachedResult;
export type CacheOptions = {
reporter: Reporter,
@ -74,8 +71,6 @@ export type TransformCache = {
readSync(props: ReadTransformProps): TransformCacheResult,
};
const EMPTY_ARRAY = [];
/* 1 day */
const GARBAGE_COLLECTION_PERIOD = 24 * 60 * 60 * 1000;
/* 4 days */
@ -181,7 +176,7 @@ class FileBasedCache {
return this._readFilesSync(props);
} catch (error) {
if (error.code === 'ENOENT') {
return {result: null, outdatedDependencies: EMPTY_ARRAY};
return null;
}
throw error;
}
@ -191,11 +186,11 @@ class FileBasedCache {
const cacheFilePaths = this._getCacheFilePaths(props);
const metadata = readMetadataFileSync(cacheFilePaths.metadata);
if (metadata == null) {
return {result: null, outdatedDependencies: EMPTY_ARRAY};
return null;
}
const sourceHash = hashSourceCode(props);
if (sourceHash !== metadata.cachedSourceHash) {
return {result: null, outdatedDependencies: metadata.dependencies};
return null;
}
const transformedCode = fs.readFileSync(
cacheFilePaths.transformedCode,
@ -206,15 +201,12 @@ class FileBasedCache {
.update(transformedCode)
.digest('hex');
if (metadata.cachedResultHash !== codeHash) {
return {result: null, outdatedDependencies: metadata.dependencies};
return null;
}
return {
result: {
code: transformedCode,
dependencies: metadata.dependencies,
map: metadata.sourceMap,
},
outdatedDependencies: EMPTY_ARRAY,
code: transformedCode,
dependencies: metadata.dependencies,
map: metadata.sourceMap,
};
}
@ -411,10 +403,7 @@ function unlinkIfExistsSync(filePath: string) {
function none(): TransformCache {
return {
writeSync: () => {},
readSync: () => ({
result: null,
outdatedDependencies: [],
}),
readSync: () => null,
};
}

View File

@ -49,10 +49,7 @@ class TransformCacheMock {
}
readSync(props) {
return {
result: transformCache.get(transformCacheKeyOf(props)),
outdatedDependencies: [],
};
return transformCache.get(transformCacheKeyOf(props));
}
}

View File

@ -87,7 +87,7 @@ describe('TransformCaching.FileBasedCache', () => {
...args,
cacheOptions: {reporter: {}, resetCache: false},
});
expect(cachedResult.result).toEqual(result);
expect(cachedResult).toEqual(result);
});
});
@ -119,7 +119,7 @@ describe('TransformCaching.FileBasedCache', () => {
...args,
cacheOptions: {reporter: {}, resetCache: false},
});
expect(cachedResult.result).toEqual(result);
expect(cachedResult).toEqual(result);
});
allCases.pop();
allCases.forEach(entry => {
@ -127,8 +127,7 @@ describe('TransformCaching.FileBasedCache', () => {
...argsFor(entry),
cacheOptions: {reporter: {}, resetCache: false},
});
expect(cachedResult.result).toBeNull();
expect(cachedResult.outdatedDependencies).toEqual(['foo', 'bar']);
expect(cachedResult).toBeNull();
});
});
});

View File

@ -19,7 +19,7 @@ const invariant = require('fbjs/lib/invariant');
const isAbsolutePath = require('absolute-path');
const jsonStableStringify = require('json-stable-stringify');
const {join: joinPath, relative: relativePath, extname} = require('path');
const {join: joinPath, relative: relativePath} = require('path');
import type {
TransformedCode,
@ -44,10 +44,7 @@ export type ReadResult = {
+source: string,
};
export type CachedReadResult = {|
+result: ?ReadResult,
+outdatedDependencies: $ReadOnlyArray<string>,
|};
export type CachedReadResult = ?ReadResult;
export type TransformCode = (
module: Module,
@ -248,7 +245,7 @@ class Module {
* To what we read from the cache or worker, we need to add id and source.
*/
_finalizeReadResult(source: string, result: TransformedCode): ReadResult {
return {...result, id: this._getHasteName(), source};
return {...result, source};
}
async _transformCodeFor(
@ -298,8 +295,9 @@ class Module {
read(transformOptions: WorkerOptions): Promise<ReadResult> {
return Promise.resolve().then(() => {
const cached = this.readCached(transformOptions);
if (cached.result != null) {
return cached.result;
if (cached != null) {
return cached;
}
return this.readFresh(transformOptions);
});
@ -334,19 +332,11 @@ class Module {
transformOptionsKey,
);
const cachedResult = this._options.transformCache.readSync(cacheProps);
if (cachedResult.result == null) {
return {
result: null,
outdatedDependencies: cachedResult.outdatedDependencies,
};
if (cachedResult == null) {
return null;
}
return {
result: this._finalizeReadResult(
cacheProps.sourceCode,
cachedResult.result,
),
outdatedDependencies: [],
};
return this._finalizeReadResult(cacheProps.sourceCode, cachedResult);
}
/**
@ -368,10 +358,7 @@ class Module {
cacheProps.sourceCode,
freshResult,
);
this._readResultsByOptionsKey.set(key, {
result: finalResult,
outdatedDependencies: [],
});
this._readResultsByOptionsKey.set(key, finalResult);
return finalResult;
})();
this._readPromises.set(key, freshPromise);