From fbe4f1f37e6e2f51855bff1ffba552c6739dc7f1 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 26 Jul 2018 11:42:10 +0200 Subject: [PATCH] perf: do not hash cache key, jest does it underneath --- package.json | 3 ++- src/utils/constants.ts | 1 + src/utils/get-babel-rc.ts | 1 - src/utils/get-cache-key.ts | 27 ++++++++++----------------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index a76fa67e3a..88540da339 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,8 @@ }, "peerDependencies": { "babel-core": "^7.0.0-0", - "jest": "^23.0.0 || ^24.0.0", + "babel-jest": "^23.0.0", + "jest": "^23.0.0", "typescript": "2.x" }, "devDependencies": { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index b8556ac8ac..675384cd92 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -9,4 +9,5 @@ export const TSCONFIG_GLOBALS_KEY = 'ts-jest'; export const PACKAGE_JSON = 'package.json'; export const MY_PACKAGE_CONTENT = readFileSync( resolve(__dirname, '..', '..', PACKAGE_JSON), + 'utf8', ); diff --git a/src/utils/get-babel-rc.ts b/src/utils/get-babel-rc.ts index c49e799531..0e7b665102 100644 --- a/src/utils/get-babel-rc.ts +++ b/src/utils/get-babel-rc.ts @@ -6,7 +6,6 @@ import { PACKAGE_JSON, BABEL_CONFIG_KEY, } from './constants'; -import { BabelTransformOptions } from '../types'; const babelReaders = [ { diff --git a/src/utils/get-cache-key.ts b/src/utils/get-cache-key.ts index b6a969d51a..f213e31923 100644 --- a/src/utils/get-cache-key.ts +++ b/src/utils/get-cache-key.ts @@ -1,4 +1,3 @@ -import { createHash } from 'crypto'; import { JestCacheKeyOptions } from '../types'; import { relative } from 'path'; import { MY_PACKAGE_CONTENT } from './constants'; @@ -14,20 +13,14 @@ export default function getCacheKey( const jestConfig: jest.ProjectConfig = JSON.parse(jestConfigString) || {}; delete jestConfig.cacheDirectory; delete jestConfig.name; - const hash = createHash('md5') - .update(MY_PACKAGE_CONTENT) - .update('\0', 'utf8') - .update(fileData) - .update('\0', 'utf8') - .update(relative(rootDir, filePath)) - .update('\0', 'utf8') - .update(jestConfigString) - .update('\0', 'utf8') - .update(JSON.stringify(getTSConfig(jestConfig))) - .update('\0', 'utf8'); - const babelRc = getBabelRC(filePath); - if (babelRc) { - hash.update(JSON.stringify(babelRc)).update('\0', 'utf8'); - } - return hash.update(instrument ? 'instrument' : '').digest('hex'); + // jest creates hash under the hoods + return JSON.stringify([ + MY_PACKAGE_CONTENT, + fileData, + relative(rootDir, filePath), + jestConfig, + getTSConfig(jestConfig), + getBabelRC(filePath), + instrument, + ]); }