[7.x] [kbn/optimizer] implement more efficient auto transpilation for node (#79052) (#79395) (#79408)

* [kbn/optimizer] implement more efficient auto transpilation for node (#79052)

Co-authored-by: spalger <spalger@users.noreply.github.com>
# Conflicts:
#	packages/kbn-optimizer/package.json
#	src/dev/build/tasks/create_empty_dirs_and_files_task.ts
#	src/setup_node_env/babel_register/register.js
#	yarn.lock

* fix eslint violation

* add core-js production dependency (#79395)

Co-authored-by: spalger <spalger@users.noreply.github.com>
(cherry picked from commit 9e1c44fcc0)

Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Spencer 2020-10-04 23:30:52 -07:00 committed by GitHub
parent 3b3c7a35ba
commit 634cf0b252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 541 additions and 228 deletions

View file

@ -208,6 +208,30 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---
This product bundles bootstrap@3.3.6 which is available under a
"MIT" license.

View file

@ -150,7 +150,7 @@
"chokidar": "^3.4.2",
"color": "1.0.3",
"commander": "^3.0.2",
"core-js": "^3.6.4",
"core-js": "^3.6.5",
"cypress-promise": "^1.1.0",
"deep-freeze-strict": "^1.1.1",
"del": "^5.1.0",
@ -175,7 +175,7 @@
"inert": "^5.1.0",
"inline-style": "^2.0.0",
"joi": "^13.5.2",
"js-yaml": "3.13.1",
"js-yaml": "^3.14.0",
"json-stable-stringify": "^1.0.1",
"json-stringify-safe": "5.0.1",
"lodash": "^4.17.20",
@ -221,7 +221,7 @@
"yauzl": "^2.10.0"
},
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/core": "^7.11.6",
"@babel/parser": "^7.11.2",
"@babel/register": "^7.10.5",
"@babel/types": "^7.11.0",
@ -258,7 +258,7 @@
"@types/angular": "^1.6.56",
"@types/angular-mocks": "^1.7.0",
"@types/archiver": "^3.1.0",
"@types/babel__core": "^7.1.2",
"@types/babel__core": "^7.1.10",
"@types/bluebird": "^3.1.1",
"@types/boom": "^7.2.0",
"@types/chance": "^1.0.0",

View file

@ -13,7 +13,7 @@
"dependencies": {
"@elastic/safer-lodash-set": "0.0.0",
"@kbn/utils": "1.0.0",
"js-yaml": "3.13.1",
"js-yaml": "^3.14.0",
"lodash": "^4.17.20"
},
"devDependencies": {

View file

@ -16,7 +16,7 @@
"@kbn/logging": "1.0.0",
"@kbn/std": "1.0.0",
"@kbn/utility-types": "1.0.0",
"js-yaml": "3.13.1",
"js-yaml": "^3.14.0",
"load-json-file": "^6.2.0",
"lodash": "^4.17.20",
"moment": "^2.24.0",

View file

@ -10,7 +10,7 @@
"kbn:watch": "yarn build --watch"
},
"dependencies": {
"@babel/core": "^7.11.1",
"@babel/core": "^7.11.6",
"@kbn/utils": "1.0.0",
"axios": "^0.19.2",
"chalk": "^4.1.0",

View file

@ -17,7 +17,7 @@
* under the License.
*/
export { REPO_ROOT } from '@kbn/utils';
export * from '@kbn/utils';
export { withProcRunner, ProcRunner } from './proc_runner';
export * from './tooling_log';
export * from './serializers';

View file

@ -13,7 +13,7 @@
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@babel/core": "^7.11.6",
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"@types/intl-relativeformat": "^2.1.0",

View file

@ -16,7 +16,7 @@
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@babel/core": "^7.11.6",
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.11.0",
"@kbn/babel-preset": "1.0.0",

View file

@ -11,6 +11,7 @@
},
"dependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.6",
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"@kbn/ui-shared-deps": "1.0.0",
@ -19,21 +20,26 @@
"clean-webpack-plugin": "^3.0.0",
"compression-webpack-plugin": "^4.0.0",
"cpy": "^8.0.0",
"core-js": "^3.6.5",
"css-loader": "^3.4.2",
"del": "^5.1.0",
"execa": "^4.0.2",
"file-loader": "^4.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jest-diff": "^25.5.0",
"js-yaml": "^3.14.0",
"json-stable-stringify": "^1.0.1",
"lmdb-store": "^0.6.10",
"loader-utils": "^1.2.3",
"node-sass": "^4.13.1",
"normalize-path": "^3.0.0",
"pirates": "^4.0.1",
"postcss": "^7.0.32",
"postcss-loader": "^3.0.0",
"raw-loader": "^3.1.0",
"rxjs": "^6.5.5",
"sass-loader": "^8.0.2",
"source-map-support": "^0.5.19",
"style-loader": "^1.1.3",
"terser-webpack-plugin": "^2.1.2",
"tinymath": "1.2.1",
@ -44,8 +50,10 @@
"webpack-merge": "^4.2.2"
},
"devDependencies": {
"@types/babel__core": "^7.1.10",
"@types/compression-webpack-plugin": "^2.0.2",
"@types/loader-utils": "^1.1.3",
"@types/source-map-support": "^0.5.3",
"@types/watchpack": "^1.1.5",
"@types/webpack": "^4.41.3"
}

View file

@ -21,3 +21,4 @@ export { OptimizerConfig } from './optimizer';
export * from './run_optimizer';
export * from './log_optimizer_state';
export * from './report_optimizer_stats';
export * from './node';

View file

@ -0,0 +1,171 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import Path from 'path';
// @ts-expect-error no types available
import * as LmdbStore from 'lmdb-store';
import { REPO_ROOT, UPSTREAM_BRANCH } from '@kbn/dev-utils';
const CACHE_DIR = Path.resolve(REPO_ROOT, 'data/node_auto_transpilation_cache', UPSTREAM_BRANCH);
const reportError = () => {
// right now I'm not sure we need to worry about errors, the cache isn't actually
// necessary, and if the cache is broken it should just rebuild on the next restart
// of the process. We don't know how often errors occur though and what types of
// things might fail on different machines so we probably want some way to signal
// to users that something is wrong
};
const GLOBAL_ATIME = `${Date.now()}`;
const MINUTE = 1000 * 60;
const HOUR = MINUTE * 60;
const DAY = HOUR * 24;
interface Lmdb<T> {
get(key: string): T | undefined;
put(key: string, value: T, version?: number, ifVersion?: number): Promise<boolean>;
remove(key: string, ifVersion?: number): Promise<boolean>;
openDB<T>(options: { name: string; encoding: 'msgpack' | 'string' | 'json' | 'binary' }): Lmdb<T>;
getRange(options?: {
start?: T;
end?: T;
reverse?: boolean;
limit?: number;
versions?: boolean;
}): Iterable<{ key: string; value: T }>;
}
export class Cache {
private readonly codes: Lmdb<string>;
private readonly atimes: Lmdb<string>;
private readonly mtimes: Lmdb<string>;
private readonly sourceMaps: Lmdb<any>;
private readonly prefix: string;
constructor(config: { prefix: string }) {
this.prefix = config.prefix;
this.codes = LmdbStore.open({
name: 'codes',
path: CACHE_DIR,
});
this.atimes = this.codes.openDB({
name: 'atimes',
encoding: 'string',
});
this.mtimes = this.codes.openDB({
name: 'mtimes',
encoding: 'string',
});
this.sourceMaps = this.codes.openDB({
name: 'sourceMaps',
encoding: 'msgpack',
});
// after the process has been running for 30 minutes prune the
// keys which haven't been used in 30 days. We use `unref()` to
// make sure this timer doesn't hold other processes open
// unexpectedly
setTimeout(() => {
this.pruneOldKeys();
}, 30 * MINUTE).unref();
}
getMtime(path: string) {
return this.mtimes.get(this.getKey(path));
}
getCode(path: string) {
const key = this.getKey(path);
// when we use a file from the cache set the "atime" of that cache entry
// so that we know which cache items we use and which haven't been
// touched in a long time (currently 30 days)
this.atimes.put(key, GLOBAL_ATIME).catch(reportError);
return this.codes.get(key);
}
getSourceMap(path: string) {
return this.sourceMaps.get(this.getKey(path));
}
update(path: string, file: { mtime: string; code: string; map: any }) {
const key = this.getKey(path);
Promise.all([
this.atimes.put(key, GLOBAL_ATIME),
this.mtimes.put(key, file.mtime),
this.codes.put(key, file.code),
this.sourceMaps.put(key, file.map),
]).catch(reportError);
}
private getKey(path: string) {
return `${this.prefix}${path}`;
}
private async pruneOldKeys() {
try {
const ATIME_LIMIT = Date.now() - 30 * DAY;
const BATCH_SIZE = 1000;
const validKeys: string[] = [];
const invalidKeys: string[] = [];
for (const { key, value } of this.atimes.getRange()) {
const atime = parseInt(value, 10);
if (atime < ATIME_LIMIT) {
invalidKeys.push(key);
} else {
validKeys.push(key);
}
if (validKeys.length + invalidKeys.length >= BATCH_SIZE) {
const promises = new Set();
if (invalidKeys.length) {
for (const k of invalidKeys) {
// all these promises are the same currently, so Set() will
// optimise this to a single promise, but I wouldn't be shocked
// if a future version starts returning independent promises so
// this is just for some future-proofing
promises.add(this.atimes.remove(k));
promises.add(this.mtimes.remove(k));
promises.add(this.codes.remove(k));
promises.add(this.sourceMaps.remove(k));
}
} else {
// delay a smidge to allow other things to happen before the next batch of checks
promises.add(new Promise((resolve) => setTimeout(resolve, 1)));
}
invalidKeys.length = 0;
validKeys.length = 0;
await Promise.all(Array.from(promises));
}
}
} catch {
// ignore errors, the cache is totally disposable and will rebuild if there is some sort of corruption
}
}
}

View file

@ -17,8 +17,4 @@
* under the License.
*/
// register and polyfill need to happen in this
// order and in separate files. Checkout each file
// for a much more detailed explanation
require('./register');
require('./polyfill');
export * from './node_auto_tranpilation';

View file

@ -0,0 +1,187 @@
/* eslint-disable @kbn/eslint/require-license-header */
/**
* This module is based on @babel/register @ 9808d25, modified to use
* a more efficient caching implementation which writes to disk as
* the cache is built rather than keeping the whole cache in memory
* and then dumping it to disk when the process exits.
*/
/**
* @notice
* MIT License
*
* Copyright (c) 2014-present Sebastian McKenzie and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import Fs from 'fs';
import Path from 'path';
import Crypto from 'crypto';
import * as babel from '@babel/core';
import { addHook } from 'pirates';
import { REPO_ROOT } from '@kbn/dev-utils';
import sourceMapSupport from 'source-map-support';
import { Cache } from './cache';
const cwd = process.cwd();
const IGNORE_PATTERNS = [
/[\/\\]kbn-pm[\/\\]dist[\/\\]/,
// ignore paths matching `/node_modules/{a}/{b}`, unless `a`
// is `x-pack` and `b` is not `node_modules`
/[\/\\]node_modules[\/\\](?!x-pack[\/\\](?!node_modules)([^\/\\]+))([^\/\\]+[\/\\][^\/\\]+)/,
// ignore paths matching `/canvas/canvas_plugin/`
/[\/\\]canvas[\/\\]canvas_plugin[\/\\]/,
// ignore any path in the packages, unless it is in the package's
// root `src` directory, in any test or __tests__ directory, or it
// ends with .test.js, .test.ts, or .test.tsx
/[\/\\]packages[\/\\](eslint-|kbn-)[^\/\\]+[\/\\](?!src[\/\\].*|(.+[\/\\])?(test|__tests__)[\/\\].+|.+\.test\.(js|ts|tsx)$)(.+$)/,
];
function getBabelOptions(path: string) {
return babel.loadOptions({
cwd,
sourceRoot: Path.dirname(path) + Path.sep,
filename: path,
babelrc: false,
presets: [require.resolve('@kbn/babel-preset/node_preset')],
sourceMaps: 'both',
ast: false,
})!;
}
/**
* @babel/register uses a JSON encoded copy of the config + babel.version
* as the cache key for files, so we do something similar but we don't need
* a unique cache key for every file as our config isn't different for
* different files (by design). Instead we determine a unique prefix and
* automatically prepend all paths with the prefix to create cache keys
*/
function determineCachePrefix() {
const json = JSON.stringify({
babelVersion: babel.version,
// get a config for a fake js, ts, and tsx file to make sure we
// capture conditional config portions based on the file extension
js: getBabelOptions(Path.resolve(REPO_ROOT, 'foo.js')),
ts: getBabelOptions(Path.resolve(REPO_ROOT, 'foo.ts')),
tsx: getBabelOptions(Path.resolve(REPO_ROOT, 'foo.tsx')),
});
const checksum = Crypto.createHash('sha256').update(json).digest('hex');
return `${checksum}:`;
}
function compile(cache: Cache, source: string, path: string) {
try {
const mtime = `${Fs.statSync(path).mtimeMs}`;
if (cache.getMtime(path) === mtime) {
const code = cache.getCode(path);
if (code) {
// code *should* always be defined, but if it isn't for some reason rebuild it
return code;
}
}
const options = getBabelOptions(path);
const result = babel.transform(source, options);
if (!result || !result.code || !result.map) {
throw new Error(`babel failed to transpile [${path}]`);
}
cache.update(path, {
mtime,
map: result.map,
code: result.code,
});
return result.code;
} catch (error) {
throw error;
}
}
let installed = false;
export function registerNodeAutoTranspilation() {
if (installed) {
return;
}
installed = true;
const cache = new Cache({
prefix: determineCachePrefix(),
});
sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: 'node',
// @ts-expect-error bad source-map-support types
retrieveSourceMap(path: string) {
const map = cache.getSourceMap(path);
if (map) {
return {
url: null,
map,
};
} else {
return null;
}
},
});
let compiling = false;
addHook(
(code, path) => {
if (compiling) {
return code;
}
if (IGNORE_PATTERNS.some((re) => re.test(path))) {
return code;
}
try {
compiling = true;
return compile(cache, code, path);
} finally {
compiling = false;
}
},
{
exts: ['.js', '.ts', '.tsx'],
ignoreNodeModules: false,
}
);
// require the polyfills after setting up the require hook so that @babel/preset-env
// will spot the import in the polyfill file and replace it with the necessary polyfills
// for the current node.js version
require('./polyfill');
}

View file

@ -17,13 +17,4 @@
* under the License.
*/
// `@babel/preset-env` looks for and rewrites the following import
// statement into a list of import statements based on the polyfills
// necessary for our target environment (the current version of node)
// but since it does that during compilation, `import 'core-js/stable'`
// must be in a file that is loaded with `require()` AFTER `@babel/register`
// is configured.
//
// This is why we have this single statement in it's own file and require
// it from ./index.js
require('core-js/stable');
import 'core-js/stable';

View file

@ -10,7 +10,7 @@
"prettier": "prettier --write './src/**/*.ts'"
},
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/core": "^7.11.6",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
"@babel/preset-env": "^7.11.0",

View file

@ -30,7 +30,7 @@
"enzyme-adapter-react-16": "^1.9.1"
},
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/core": "^7.11.6",
"@elastic/eui": "29.0.0",
"@kbn/babel-preset": "1.0.0",
"@kbn/optimizer": "1.0.0",
@ -38,7 +38,7 @@
"brace": "0.11.1",
"chalk": "^4.1.0",
"chokidar": "^3.4.2",
"core-js": "^3.6.4",
"core-js": "^3.6.5",
"css-loader": "^3.4.2",
"expose-loader": "^0.7.5",
"file-loader": "^4.2.0",

View file

@ -17,7 +17,7 @@
"abortcontroller-polyfill": "^1.4.0",
"angular": "^1.8.0",
"compression-webpack-plugin": "^4.0.0",
"core-js": "^3.6.4",
"core-js": "^3.6.5",
"custom-event-polyfill": "^0.3.0",
"jquery": "^3.5.0",
"lodash": "^4.17.20",

View file

@ -22,38 +22,50 @@ import Fs from 'fs';
import loadJsonFile from 'load-json-file';
const isKibanaDir = (dir: string) => {
const readKibanaPkgJson = (dir: string) => {
try {
const path = Path.resolve(dir, 'package.json');
const json = loadJsonFile.sync(path);
if (json && typeof json === 'object' && 'name' in json && json.name === 'kibana') {
return true;
return json;
}
} catch (error) {
if (error && error.code === 'ENOENT') {
return false;
return;
}
throw error;
}
};
// search for the kibana directory, since this file is moved around it might
// not be where we think but should always be a relatively close parent
// of this directory
const startDir = Fs.realpathSync(__dirname);
const { root: rootDir } = Path.parse(startDir);
let cursor = startDir;
while (true) {
if (isKibanaDir(cursor)) {
break;
}
const findKibanaPackageJson = () => {
// search for the kibana directory, since this file is moved around it might
// not be where we think but should always be a relatively close parent
// of this directory
const startDir = Fs.realpathSync(__dirname);
const { root: rootDir } = Path.parse(startDir);
let cursor = startDir;
while (true) {
const kibanaPkgJson = readKibanaPkgJson(cursor);
if (kibanaPkgJson) {
return {
kibanaDir: cursor,
kibanaPkgJson: kibanaPkgJson as {
name: string;
branch: string;
},
};
}
const parent = Path.dirname(cursor);
if (parent === rootDir) {
throw new Error(`unable to find kibana directory from ${startDir}`);
const parent = Path.dirname(cursor);
if (parent === rootDir) {
throw new Error(`unable to find kibana directory from ${startDir}`);
}
cursor = parent;
}
cursor = parent;
}
};
export const REPO_ROOT = cursor;
const { kibanaDir, kibanaPkgJson } = findKibanaPackageJson();
export const REPO_ROOT = kibanaDir;
export const UPSTREAM_BRANCH = kibanaPkgJson.branch;

View file

@ -17,5 +17,5 @@
* under the License.
*/
require('../src/setup_node_env/babel_register');
require('@kbn/optimizer').registerNodeAutoTranspilation();
require('../src/dev/run_precommit_hook');

View file

@ -19,5 +19,5 @@
require('../apm')();
require('../setup_node_env/no_transpilation');
require('../setup_node_env/babel_register/polyfill');
require('core-js/stable');
require('./cli');

View file

@ -17,16 +17,12 @@
* under the License.
*/
import { mkdirp, write, Task } from '../lib';
import { mkdirp, Task } from '../lib';
export const CreateEmptyDirsAndFiles: Task = {
description: 'Creating some empty directories and files to prevent file-permission issues',
async run(config, log, build) {
await Promise.all([
mkdirp(build.resolvePath('plugins')),
mkdirp(build.resolvePath('data')),
write(build.resolvePath('optimize/.babel_register_cache.json'), '{}'),
]);
await Promise.all([mkdirp(build.resolvePath('plugins')), mkdirp(build.resolvePath('data'))]);
},
};

View file

@ -10,6 +10,4 @@ nice=""
# The default behavior is to simply log a message "program stop failed; still running"
KILL_ON_STOP_TIMEOUT=0
BABEL_CACHE_PATH="/var/lib/kibana/optimize/.babel_register_cache.json"
KBN_PATH_CONF="/etc/kibana"

View file

@ -24,15 +24,6 @@ export NODE_OPTIONS="$NODE_OPTIONS --max-old-space-size=4096"
###
export FORCE_COLOR=1
###
### The @babel/register cache collects the build output from each file in
### a map, in memory, and then when the process exits it writes that to the
### babel cache file as a JSON encoded object. Stringifying that object
### causes OOMs on CI regularly enough that we need to find another solution,
### and until we do we need to disable the cache
###
export BABEL_DISABLE_CACHE=true
###
### check that we seem to be in a kibana project
###

View file

@ -20,4 +20,4 @@
// Note: In theory importing the polyfill should not be needed, as Babel should
// include the necessary polyfills when using `@babel/preset-env`, but for some
// reason it did not work. See https://github.com/elastic/kibana/issues/14506
import '../../../setup_node_env/babel_register/polyfill';
import '@kbn/optimizer/src/node/polyfill';

View file

@ -1,60 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var resolve = require('path').resolve;
// this must happen before `require('@babel/register')` and can't be changed
// once the module has been loaded
if (!process.env.BABEL_CACHE_PATH) {
process.env.BABEL_CACHE_PATH = resolve(__dirname, '../../../optimize/.babel_register_cache.json');
}
// paths that @babel/register should ignore
var ignore = [
/[\/\\]bower_components[\/\\]/,
/[\/\\]kbn-pm[\/\\]dist[\/\\]/,
// TODO: remove this and just transpile plugins at build time, but
// has tricky edge cases that will probably require better eslint
// restrictions to make sure that code destined for the server/browser
// follows respects the limitations of each environment.
//
// https://github.com/elastic/kibana/issues/14800#issuecomment-366130268
// ignore paths matching `/node_modules/{a}/{b}`, unless `a`
// is `x-pack` and `b` is not `node_modules`
/[\/\\]node_modules[\/\\](?!x-pack[\/\\](?!node_modules)([^\/\\]+))([^\/\\]+[\/\\][^\/\\]+)/,
// ignore paths matching `/canvas/canvas_plugin/`
/[\/\\]canvas[\/\\]canvas_plugin[\/\\]/,
// ignore any path in the packages, unless it is in the package's
// root `src` directory, in any test or __tests__ directory, or it
// ends with .test.js, .test.ts, or .test.tsx
/[\/\\]packages[\/\\](eslint-|kbn-)[^\/\\]+[\/\\](?!src[\/\\].*|(.+[\/\\])?(test|__tests__)[\/\\].+|.+\.test\.(js|ts|tsx)$)(.+$)/,
];
// modifies all future calls to require() to automatically
// compile the required source with babel
require('@babel/register')({
ignore,
babelrc: false,
presets: [require.resolve('@kbn/babel-preset/node_preset')],
extensions: ['.js', '.ts', '.tsx'],
});

View file

@ -18,4 +18,4 @@
*/
require('./no_transpilation');
require('./babel_register');
require('@kbn/optimizer').registerNodeAutoTranspilation();

View file

@ -272,8 +272,7 @@
"yargs": "^15.4.1"
},
"dependencies": {
"@babel/core": "^7.11.1",
"@babel/register": "^7.10.5",
"@babel/core": "^7.11.6",
"@babel/runtime": "^7.11.2",
"@elastic/datemath": "5.0.3",
"@elastic/ems-client": "7.10.0",
@ -335,7 +334,7 @@
"isbinaryfile": "4.0.2",
"joi": "^13.5.2",
"jquery": "^3.5.0",
"js-yaml": "3.13.1",
"js-yaml": "^3.14.0",
"json-stable-stringify": "^1.0.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",

View file

@ -4,17 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
// eslint-disable-next-line import/no-extraneous-dependencies
require('@babel/register')({
extensions: ['.ts'],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
],
presets: [
'@babel/typescript',
['@babel/preset-env', { targets: { node: 'current' } }],
],
});
require('@kbn/optimizer').registerNodeAutoTranspilation();
const {
aggregateLatencyMetrics,

View file

@ -6,13 +6,6 @@
// compile typescript on the fly
// eslint-disable-next-line import/no-extraneous-dependencies
require('@babel/register')({
extensions: ['.js', '.ts'],
plugins: ['@babel/plugin-proposal-optional-chaining'],
presets: [
'@babel/typescript',
['@babel/preset-env', { targets: { node: 'current' } }],
],
});
require('@kbn/optimizer').registerNodeAutoTranspilation();
require('./create-functional-tests-archive/index.ts');

View file

@ -4,14 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
// eslint-disable-next-line import/no-extraneous-dependencies
require('@babel/register')({
extensions: ['.js'],
plugins: [],
presets: [
'@babel/typescript',
['@babel/preset-env', { targets: { node: 'current' } }],
],
});
require('@kbn/optimizer').registerNodeAutoTranspilation();
// eslint-disable-next-line import/no-extraneous-dependencies
const { run } = require('jest');

View file

@ -17,13 +17,6 @@
// compile typescript on the fly
// eslint-disable-next-line import/no-extraneous-dependencies
require('@babel/register')({
extensions: ['.ts'],
plugins: ['@babel/plugin-proposal-optional-chaining'],
presets: [
'@babel/typescript',
['@babel/preset-env', { targets: { node: 'current' } }],
],
});
require('@kbn/optimizer').registerNodeAutoTranspilation();
require('./kibana-security/setup-custom-kibana-user-role.ts');

View file

@ -6,16 +6,6 @@
// compile typescript on the fly
// eslint-disable-next-line import/no-extraneous-dependencies
require('@babel/register')({
extensions: ['.ts'],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
],
presets: [
'@babel/typescript',
['@babel/preset-env', { targets: { node: 'current' } }],
],
});
require('@kbn/optimizer').registerNodeAutoTranspilation();
require('./upload-telemetry-data/index.ts');

140
yarn.lock
View file

@ -41,29 +41,7 @@
invariant "^2.2.4"
semver "^5.5.0"
"@babel/core@^7.1.0", "@babel/core@^7.7.5":
version "7.11.6"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.11.6.tgz#3a9455dc7387ff1bac45770650bc13ba04a15651"
integrity sha512-Wpcv03AGnmkgm6uS6k8iwhIwTrcP0m17TL1n1sy7qD0qelDu4XNeW0dN0mHfa+Gei211yDaLoEe/VlbXQzM4Bg==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/generator" "^7.11.6"
"@babel/helper-module-transforms" "^7.11.0"
"@babel/helpers" "^7.10.4"
"@babel/parser" "^7.11.5"
"@babel/template" "^7.10.4"
"@babel/traverse" "^7.11.5"
"@babel/types" "^7.11.5"
convert-source-map "^1.7.0"
debug "^4.1.0"
gensync "^1.0.0-beta.1"
json5 "^2.1.2"
lodash "^4.17.19"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"
"@babel/core@^7.11.1", "@babel/core@^7.4.3":
"@babel/core@^7.1.0", "@babel/core@^7.4.3", "@babel/core@^7.7.5":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.11.1.tgz#2c55b604e73a40dc21b0e52650b11c65cf276643"
integrity sha512-XqF7F6FWQdKGGWAzGELL+aCO1p+lRY5Tj5/tbT3St1G8NaH70jhhDIKknIZaDans0OQBG5wRAldROLHSt44BgQ==
@ -85,7 +63,29 @@
semver "^5.4.1"
source-map "^0.5.0"
"@babel/generator@^7.0.0", "@babel/generator@^7.11.0":
"@babel/core@^7.11.6":
version "7.11.6"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.11.6.tgz#3a9455dc7387ff1bac45770650bc13ba04a15651"
integrity sha512-Wpcv03AGnmkgm6uS6k8iwhIwTrcP0m17TL1n1sy7qD0qelDu4XNeW0dN0mHfa+Gei211yDaLoEe/VlbXQzM4Bg==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/generator" "^7.11.6"
"@babel/helper-module-transforms" "^7.11.0"
"@babel/helpers" "^7.10.4"
"@babel/parser" "^7.11.5"
"@babel/template" "^7.10.4"
"@babel/traverse" "^7.11.5"
"@babel/types" "^7.11.5"
convert-source-map "^1.7.0"
debug "^4.1.0"
gensync "^1.0.0-beta.1"
json5 "^2.1.2"
lodash "^4.17.19"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"
"@babel/generator@^7.0.0", "@babel/generator@^7.10.5", "@babel/generator@^7.11.0":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.11.0.tgz#4b90c78d8c12825024568cbe83ee6c9af193585c"
integrity sha512-fEm3Uzw7Mc9Xi//qU20cBKatTfs2aOtKqmvy/Vm7RkJEGFQ4xc9myCfbXxqK//ZS8MR/ciOHw6meGASJuKmDfQ==
@ -94,7 +94,7 @@
jsesc "^2.5.1"
source-map "^0.5.0"
"@babel/generator@^7.10.5", "@babel/generator@^7.11.5", "@babel/generator@^7.11.6":
"@babel/generator@^7.11.5", "@babel/generator@^7.11.6":
version "7.11.6"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.11.6.tgz#b868900f81b163b4d464ea24545c61cbac4dc620"
integrity sha512-DWtQ1PV3r+cLbySoHrwn9RWEgKMBLLma4OBQloPRyDYvc5msJM9kvTLo1YnlJd1P/ZuKbdli3ijr5q3FvAF3uA==
@ -1128,19 +1128,19 @@
globals "^11.1.0"
lodash "^4.17.19"
"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.11.0", "@babel/types@^7.11.5", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
version "7.11.5"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.5.tgz#d9de577d01252d77c6800cee039ee64faf75662d"
integrity sha512-bvM7Qz6eKnJVFIn+1LPtjlBFPVN5jNDc1XmN15vWe7Q3DPBufWWsLiIvUu7xW87uTG6QoggpIDnUgLQvPheU+Q==
"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.11.0", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.0.tgz#2ae6bf1ba9ae8c3c43824e5861269871b206e90d"
integrity sha512-O53yME4ZZI0jO1EVGtF1ePGl0LHirG4P1ibcD80XyzZcKhcMFeCXmh4Xb1ifGBIV233Qg12x4rBfQgA+tmOukA==
dependencies:
"@babel/helper-validator-identifier" "^7.10.4"
lodash "^4.17.19"
to-fast-properties "^2.0.0"
"@babel/types@^7.4.0":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.0.tgz#2ae6bf1ba9ae8c3c43824e5861269871b206e90d"
integrity sha512-O53yME4ZZI0jO1EVGtF1ePGl0LHirG4P1ibcD80XyzZcKhcMFeCXmh4Xb1ifGBIV233Qg12x4rBfQgA+tmOukA==
"@babel/types@^7.11.5":
version "7.11.5"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.5.tgz#d9de577d01252d77c6800cee039ee64faf75662d"
integrity sha512-bvM7Qz6eKnJVFIn+1LPtjlBFPVN5jNDc1XmN15vWe7Q3DPBufWWsLiIvUu7xW87uTG6QoggpIDnUgLQvPheU+Q==
dependencies:
"@babel/helper-validator-identifier" "^7.10.4"
lodash "^4.17.19"
@ -3377,18 +3377,7 @@
resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.4.tgz#bfd5b0d0d1ba13e351dff65b6e52783b816826c8"
integrity sha512-WiZhq3SVJHFRgRYLXvpf65XnV6ipVHhnNaNvE8yCimejrGglkg38kEj0JcizqwSHxmPSjcTlig/6JouxLGEhGw==
"@types/babel__core@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.2.tgz#608c74f55928033fce18b99b213c16be4b3d114f"
integrity sha512-cfCCrFmiGY/yq0NuKNxIQvZFy9kY/1immpSpTngOnyIbD4+eJOG5mxphhHDv3CHL9GltO4GcKr54kGBg3RNdbg==
dependencies:
"@babel/parser" "^7.1.0"
"@babel/types" "^7.0.0"
"@types/babel__generator" "*"
"@types/babel__template" "*"
"@types/babel__traverse" "*"
"@types/babel__core@^7.1.7":
"@types/babel__core@^7.1.10", "@types/babel__core@^7.1.7":
version "7.1.10"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.10.tgz#ca58fc195dd9734e77e57c6f2df565623636ab40"
integrity sha512-x8OM8XzITIMyiwl5Vmo2B1cR1S1Ipkyv4mdlbJjMa1lmuKvKY9FrBbEANIaMlnWn5Rf7uO+rC/VgYabNkE17Hw==
@ -4599,6 +4588,13 @@
resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
integrity sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==
"@types/source-map-support@^0.5.3":
version "0.5.3"
resolved "https://registry.yarnpkg.com/@types/source-map-support/-/source-map-support-0.5.3.tgz#acb6b3e499c20692552d16934c16162c84594e16"
integrity sha512-fvjMjVH8Rmokw2dWh1dkj90iX5R8FPjeZzjNH+6eFXReh0QnHFf1YBl3B0CF0RohIAA3SDRJsGeeUWKl6d7HqA==
dependencies:
source-map "^0.6.0"
"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@ -9166,15 +9162,15 @@ core-js@^2.4.0, core-js@^2.5.0, core-js@^2.5.3, core-js@^2.6.5, core-js@^2.6.9:
integrity sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A==
core-js@^3.0.1, core-js@^3.0.4:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==
core-js@^3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.4.tgz#440a83536b458114b9cb2ac1580ba377dc470647"
integrity sha512-4paDGScNgZP2IXXilaffL9X7968RuvwlkK3xWtZRVqgd8SYNiVKRJvkFd1aqqEuPfN7E68ZHEp9hDj6lHj4Hyw==
core-js@^3.6.5:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==
core-util-is@1.0.2, core-util-is@^1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@ -17264,6 +17260,14 @@ js-yaml@3.13.1, js-yaml@^3.10.0, js-yaml@^3.13.1, js-yaml@^3.4.6, js-yaml@^3.5.1
argparse "^1.0.7"
esprima "^4.0.0"
js-yaml@^3.14.0:
version "3.14.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"
jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
@ -17955,6 +17959,17 @@ livereload-js@^2.3.0:
resolved "https://registry.yarnpkg.com/livereload-js/-/livereload-js-2.4.0.tgz#447c31cf1ea9ab52fc20db615c5ddf678f78009c"
integrity sha512-XPQH8Z2GDP/Hwz2PCDrh2mth4yFejwA1OZ/81Ti3LgKyhDcEjsSsqFWZojHG0va/duGd+WyosY7eXLDoOyqcPw==
lmdb-store@^0.6.10:
version "0.6.10"
resolved "https://registry.yarnpkg.com/lmdb-store/-/lmdb-store-0.6.10.tgz#db8efde6e052aabd17ebc63c8a913e1f31694129"
integrity sha512-ZLvp3qbBQ5VlBmaWa4EUAPyYEZ8qdUHsW69HmxkDi84pFQ37WMxYhFaF/7PQkdtxS/vyiKkZigd9TFgHjek1Nw==
dependencies:
fs-extra "^9.0.1"
msgpackr "^0.5.0"
nan "^2.14.1"
node-gyp-build "^4.2.3"
weak-lru-cache "^0.2.0"
load-bmfont@^1.3.1, load-bmfont@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/load-bmfont/-/load-bmfont-1.4.0.tgz#75f17070b14a8c785fe7f5bee2e6fd4f98093b6b"
@ -19521,6 +19536,21 @@ ms@2.1.1, ms@^2.0.0, ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==
msgpackr-extract@^0.3.4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/msgpackr-extract/-/msgpackr-extract-0.3.4.tgz#8ee5e73d1135340e564c498e8c593134365eb060"
integrity sha512-d3+qwTJzgqqsq2L2sQuH0SoO4StvpUhMqMAKy6tMimn7XdBaRtDlquFzRJsp0iMGt2hnU4UOqD8Tz9mb0KglTA==
dependencies:
nan "^2.14.1"
node-gyp-build "^4.2.3"
msgpackr@^0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/msgpackr/-/msgpackr-0.5.1.tgz#7eecbf342645b7718dd2e3386894368d06732b3f"
integrity sha512-nK2uJl67Q5KU3MWkYBUlYynqKS1UUzJ5M1h6TQejuJtJzD3hW2Suv2T1pf01E9lUEr93xaLokf/xC+jwBShMPQ==
optionalDependencies:
msgpackr-extract "^0.3.4"
multicast-dns-service-types@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz#899f11d9686e5e05cb91b35d5f0e63b773cfc901"
@ -19829,6 +19859,11 @@ node-forge@^0.10.0, node-forge@^0.7.6:
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==
node-gyp-build@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==
node-gyp@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c"
@ -28374,6 +28409,11 @@ wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"
weak-lru-cache@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/weak-lru-cache/-/weak-lru-cache-0.2.0.tgz#447379ccff6dfda1b7a9566c9ef168260be859d1"
integrity sha512-M1l5CzKvM7maa7tCbtL0NW6sOnp8gqup853+9Aq7GL0XNWKNnFOkeE3v3Z5X2IeMzedPwQyPbi4RlFvD6rxs7A==
web-namespaces@^1.0.0, web-namespaces@^1.1.2:
version "1.1.4"
resolved "https://registry.yarnpkg.com/web-namespaces/-/web-namespaces-1.1.4.tgz#bc98a3de60dadd7faefc403d1076d529f5e030ec"