Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getTransformer(
projectRoot: string,
{transformerPath, transformerConfig}: TransformerConfig,
): Transformer {
const transformerKey = stableHash([
projectRoot,
transformerPath,
transformerConfig,
]).toString('hex');
if (transformers[transformerKey]) {
return transformers[transformerKey];
}
// eslint-disable-next-line lint/flow-no-fixme
// $FlowFixMe Transforming fixed types to generic types during refactor.
const Transformer = require(transformerPath);
transformers[transformerKey] = new Transformer(
projectRoot,
transformerConfig,
);
platform,
type,
...extra
} = transformerOptions;
for (const key in extra) {
if (hasOwnProperty.call(extra, key)) {
throw new Error(
'Extra keys detected: ' + Object.keys(extra).join(', '),
);
}
}
const localPath = path.relative(this._config.projectRoot, filePath);
const partialKey = stableHash([
// This is the hash related to the global Bundler config.
this._baseHash,
// Path.
localPath,
customTransformOptions,
dev,
experimentalImportSupport,
hot,
inlinePlatform,
inlineRequires,
minify,
unstable_disableES6Transforms,
platform,
type,
} = this._config.transformer;
const transformerOptions: TransformerConfig = {
transformerPath: this._config.transformerPath,
transformerConfig,
};
this._workerFarm = new WorkerFarm(config, transformerOptions);
const globalCacheKey = getTransformCacheKey({
cacheVersion: this._config.cacheVersion,
projectRoot: this._config.projectRoot,
transformerConfig: transformerOptions,
});
this._baseHash = stableHash([globalCacheKey]).toString('binary');
}
require.resolve('../lib/getMinifier'),
require.resolve('./worker/inline-plugin'),
require.resolve('./worker/import-export-plugin'),
require.resolve('./worker/normalizePseudoglobals'),
require.resolve('../ModuleGraph/worker/optimizeDependencies'),
require.resolve('../ModuleGraph/worker/generateImportNames'),
]);
const babelTransformer = require(babelTransformerPath);
const babelTransformerKey = babelTransformer.getCacheKey
? babelTransformer.getCacheKey()
: '';
return [
filesKey,
stableHash(config).toString('hex'),
babelTransformerKey,
].join('$');
}
}