diff --git a/packager/src/Bundler/index.js b/packager/src/Bundler/index.js index 1715c00fe..5b516719a 100644 --- a/packager/src/Bundler/index.js +++ b/packager/src/Bundler/index.js @@ -193,8 +193,8 @@ class Bundler { /* $FlowFixMe: in practice it's always here. */ this._transformer = new Transformer(opts.transformModulePath, maxWorkerCount); - const getTransformCacheKey = (src, filename, options) => { - return transformCacheKey + getCacheKey(src, filename, options); + const getTransformCacheKey = (options) => { + return transformCacheKey + getCacheKey(options); }; this._resolverPromise = Resolver.load({ diff --git a/packager/src/lib/GlobalTransformCache.js b/packager/src/lib/GlobalTransformCache.js index 5572ce1a2..4f0b9c7c4 100644 --- a/packager/src/lib/GlobalTransformCache.js +++ b/packager/src/lib/GlobalTransformCache.js @@ -229,7 +229,7 @@ class URIBasedGlobalTransformCache { const hash = crypto.createHash('sha1'); const {sourceCode, filePath, transformOptions} = props; hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions)); - const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions); + const cacheKey = props.getTransformCacheKey(transformOptions); hash.update(JSON.stringify(cacheKey)); hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex')); const digest = hash.digest('hex'); diff --git a/packager/src/lib/TransformCache.js b/packager/src/lib/TransformCache.js index 652ba7d96..ddceccb51 100644 --- a/packager/src/lib/TransformCache.js +++ b/packager/src/lib/TransformCache.js @@ -25,7 +25,7 @@ import type {MappingsMap} from './SourceMap'; import type {Reporter} from './reporting'; type CacheFilePaths = {transformedCode: string, metadata: string}; -export type GetTransformCacheKey = (sourceCode: string, filename: string, options: {}) => string; +export type GetTransformCacheKey = (options: {}) => string; const CACHE_NAME = 'react-native-packager-cache'; const CACHE_SUB_DIR = 'cache'; @@ -62,11 +62,7 @@ function hashSourceCode(props: { transformOptionsKey: string, }): string { return crypto.createHash('sha1') - .update(props.getTransformCacheKey( - props.sourceCode, - props.filePath, - props.transformOptions, - )) + .update(props.getTransformCacheKey(props.transformOptions)) .update(props.sourceCode) .digest('hex'); } diff --git a/packager/transformer.js b/packager/transformer.js index 76e52dc48..1864bd706 100644 --- a/packager/transformer.js +++ b/packager/transformer.js @@ -11,6 +11,7 @@ 'use strict'; const babel = require('babel-core'); +const crypto = require('crypto'); const externalHelpersPlugin = require('babel-plugin-external-helpers'); const fs = require('fs'); const generate = require('babel-generator').default; @@ -22,6 +23,13 @@ const resolvePlugins = require('babel-preset-react-native/lib/resolvePlugins'); const {compactMapping} = require('./src/Bundler/source-map'); +const cacheKeyParts = [ + fs.readFileSync(__filename), + require('babel-plugin-external-helpers/package.json').version, + require('babel-preset-fbjs/package.json').version, + require('babel-preset-react-native/package.json').version, +]; + /** * Return a memoized function that checks for the existence of a * project level .babelrc file, and if it doesn't exist, reads the @@ -126,4 +134,13 @@ function transform(src, filename, options) { } } -module.exports.transform = transform; +function getCacheKey(options) { + var key = crypto.createHash('md5'); + cacheKeyParts.forEach(part => key.update(part)); + return key.digest('hex'); +} + +module.exports = { + transform, + getCacheKey, +};