mirror of https://github.com/status-im/metro.git
Add getCacheKey() to the open source transformer
Reviewed By: davidaurelio Differential Revision: D4965737 fbshipit-source-id: a343d0cd2e8832567e4e2eed1e2ac0b1657d91a0
This commit is contained in:
parent
95db7be042
commit
054b5aa4ce
|
@ -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({
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue