mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
After https://github.com/elastic/kibana/pull/146212 it feels like the babel-register cache is getting invalidated more frequently for some reason. The current version of the cache only stores a single cache entry for each file path, which shouldn't be too big of a problem but with these changes several versions of a file will be cached. The performance seems about equal, but because the cache contains multiple versions of a single file we should spend less time transpiling files when switching branches often. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
28 lines
809 B
JavaScript
28 lines
809 B
JavaScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
* Side Public License, v 1.
|
|
*/
|
|
|
|
const { transformCode } = require('@kbn/babel-transform');
|
|
|
|
/** @type {import('./types').Transform} */
|
|
const babelTransform = (path, source, cache) => {
|
|
const key = cache.getKey(path, source);
|
|
const cached = cache.getCode(key);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
|
|
const result = transformCode(path, source);
|
|
cache.update(key, {
|
|
code: result.code,
|
|
map: result.map,
|
|
});
|
|
|
|
return result.code;
|
|
};
|
|
|
|
module.exports = { babelTransform };
|