Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-77102
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 3, 2020
2 parents c6c2105 + d7668a0 commit 2e0d07d
Show file tree
Hide file tree
Showing 132 changed files with 4,221 additions and 1,607 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@
]
},
"dependencies": {
"@babel/core": "^7.11.1",
"@babel/register": "^7.10.5",
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "7.9.1",
"@elastic/eui": "29.0.0",
Expand All @@ -125,7 +123,6 @@
"@hapi/wreck": "^15.0.2",
"@kbn/analytics": "1.0.0",
"@kbn/apm-config-loader": "1.0.0",
"@kbn/babel-preset": "1.0.0",
"@kbn/config": "1.0.0",
"@kbn/config-schema": "1.0.0",
"@kbn/i18n": "1.0.0",
Expand Down Expand Up @@ -211,6 +208,7 @@
"rxjs": "^6.5.5",
"seedrandom": "^3.0.5",
"semver": "^5.7.0",
"source-map-support": "^0.5.19",
"symbol-observable": "^1.2.0",
"tar": "4.4.13",
"tinygradient": "0.4.3",
Expand All @@ -223,7 +221,9 @@
"yauzl": "^2.10.0"
},
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/parser": "^7.11.2",
"@babel/register": "^7.10.5",
"@babel/types": "^7.11.0",
"@elastic/apm-rum": "^5.6.1",
"@elastic/charts": "23.0.0",
Expand All @@ -234,6 +234,7 @@
"@elastic/github-checks-reporter": "0.0.20b3",
"@elastic/makelogs": "^6.0.0",
"@elastic/ui-ace": "0.2.3",
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"@kbn/es": "1.0.0",
"@kbn/es-archiver": "1.0.0",
Expand Down
8 changes: 0 additions & 8 deletions packages/kbn-babel-preset/node_preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,5 @@ module.exports = (_, options = {}) => {
],
require('./common_preset'),
],
plugins: [
[
require.resolve('babel-plugin-transform-define'),
{
'global.__BUILT_WITH_BABEL__': 'true',
},
],
],
};
};
1 change: 0 additions & 1 deletion packages/kbn-babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@babel/preset-typescript": "^7.10.4",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-styled-components": "^1.10.7",
"babel-plugin-transform-define": "^1.3.1",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"react-is": "^16.8.0",
"styled-components": "^5.1.0"
Expand Down
12 changes: 12 additions & 0 deletions packages/kbn-config/src/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ test('pluginSearchPaths contains x-pack/examples plugins path if --run-examples
expect(env.pluginSearchPaths).toContain('/some/home/dir/x-pack/examples');
});

test('pluginSearchPaths does not contain x-pack/examples plugins path if --oss flag is true', () => {
const env = new Env(
'/some/home/dir',
packageInfos,
getEnvOptions({
cliArgs: { runExamples: true, oss: true },
})
);

expect(env.pluginSearchPaths).not.toContain('/some/home/dir/x-pack/examples');
});

test('pluginSearchPaths does not contains examples plugins path if --run-examples flag is false', () => {
const env = new Env(
'/some/home/dir',
Expand Down
5 changes: 3 additions & 2 deletions packages/kbn-config/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ export class Env {
resolve(this.homeDir, 'src', 'plugins'),
...(options.cliArgs.oss ? [] : [resolve(this.homeDir, 'x-pack', 'plugins')]),
resolve(this.homeDir, 'plugins'),
...(options.cliArgs.runExamples
? [resolve(this.homeDir, 'examples'), resolve(this.homeDir, 'x-pack', 'examples')]
...(options.cliArgs.runExamples ? [resolve(this.homeDir, 'examples')] : []),
...(options.cliArgs.runExamples && !options.cliArgs.oss
? [resolve(this.homeDir, 'x-pack', 'examples')]
: []),
resolve(this.homeDir, '..', 'kibana-extra'),
];
Expand Down
18 changes: 18 additions & 0 deletions packages/kbn-telemetry-tools/src/tools/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,22 @@ describe('getDescriptor', () => {
},
});
});

it('serializes RecordWithKnownProps', () => {
const usageInterface = usageInterfaces.get('RecordWithKnownProps')!;
const descriptor = getDescriptor(usageInterface, tsProgram);
expect(descriptor).toEqual({
prop1: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
prop2: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
});
});

it('serializes IndexedAccessType', () => {
const usageInterface = usageInterfaces.get('IndexedAccessType')!;
const descriptor = getDescriptor(usageInterface, tsProgram);
expect(descriptor).toEqual({
prop1: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
prop2: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
});
});
});
33 changes: 29 additions & 4 deletions packages/kbn-telemetry-tools/src/tools/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import * as ts from 'typescript';
import { uniqBy } from 'lodash';
import { uniqBy, pick } from 'lodash';
import {
getResolvedModuleSourceFile,
getIdentifierDeclarationFromSource,
Expand Down Expand Up @@ -95,7 +95,16 @@ export function getConstraints(node: ts.Node, program: ts.Program): any {
return node.literal.text;
}

throw Error(`Unsupported constraint`);
if (ts.isImportSpecifier(node)) {
const source = node.getSourceFile();
const importedModuleName = getModuleSpecifier(node);

const declarationSource = getResolvedModuleSourceFile(source, program, importedModuleName);
const declarationNode = getIdentifierDeclarationFromSource(node.name, declarationSource);
return getConstraints(declarationNode, program);
}

throw Error(`Unsupported constraint of kind ${node.kind} [${ts.SyntaxKind[node.kind]}]`);
}

export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor | DescriptorValue {
Expand Down Expand Up @@ -157,9 +166,25 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
return { kind: TelemetryKinds.Date, type: 'Date' };
}
// Support `Record<string, SOMETHING>`
if (symbolName === 'Record' && node.typeArguments![0].kind === ts.SyntaxKind.StringKeyword) {
return { '@@INDEX@@': getDescriptor(node.typeArguments![1], program) };
if (symbolName === 'Record') {
const descriptor = getDescriptor(node.typeArguments![1], program);
if (node.typeArguments![0].kind === ts.SyntaxKind.StringKeyword) {
return { '@@INDEX@@': descriptor };
}
const constraints = getConstraints(node.typeArguments![0], program);
const constraintsArray = Array.isArray(constraints) ? constraints : [constraints];
if (typeof constraintsArray[0] === 'string') {
return constraintsArray.reduce((acc, c) => ({ ...acc, [c]: descriptor }), {});
}
}

// Support `Pick<SOMETHING, 'prop1' | 'prop2'>`
if (symbolName === 'Pick') {
const parentDescriptor = getDescriptor(node.typeArguments![0], program);
const pickPropNames = getConstraints(node.typeArguments![1], program);
return pick(parentDescriptor, pickPropNames);
}

const declaration = (symbol?.getDeclarations() || [])[0];
if (declaration) {
return getDescriptor(declaration, program);
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-telemetry-tools/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export function getIdentifierDeclarationFromSource(node: ts.Node, source: ts.Sou
const identifierName = node.getText();
const identifierDefinition: ts.Node = (source as any).locals.get(identifierName);
if (!identifierDefinition) {
throw new Error(`Unable to fine identifier in source ${identifierName}`);
throw new Error(`Unable to find identifier in source ${identifierName}`);
}
const declarations = (identifierDefinition as any).declarations as ts.Node[];

const latestDeclaration: ts.Node | false | undefined =
Array.isArray(declarations) && declarations[declarations.length - 1];
if (!latestDeclaration) {
throw new Error(`Unable to fine declaration for identifier ${identifierName}`);
throw new Error(`Unable to find declaration for identifier ${identifierName}`);
}

return latestDeclaration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/

const Path = require('path');

const { REPO_ROOT } = require('@kbn/dev-utils');

// modifies all future calls to require() to automatically
// compile the required source with babel
require('@babel/register')({
ignore: [/[\/\\](node_modules|target|dist)[\/\\]/],
only: [
Path.resolve(REPO_ROOT, 'test'),
Path.resolve(REPO_ROOT, 'x-pack/test'),
Path.resolve(REPO_ROOT, 'examples'),
Path.resolve(REPO_ROOT, 'x-pack/examples'),
// TODO: should should probably remove this link back to the source
Path.resolve(REPO_ROOT, 'x-pack/plugins/task_manager/server/config.ts'),
],
babelrc: false,
presets: [require.resolve('@kbn/babel-preset/node_preset')],
extensions: ['.js', '.ts', '.tsx'],
});
20 changes: 19 additions & 1 deletion packages/kbn-test/src/functional_tests/lib/run_kibana_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@
* under the License.
*/

import { resolve } from 'path';
import { resolve, relative } from 'path';
import { KIBANA_ROOT, KIBANA_EXEC, KIBANA_EXEC_PATH } from './paths';

function extendNodeOptions(installDir) {
if (!installDir) {
return {};
}

const testOnlyRegisterPath = relative(
installDir,
require.resolve('./babel_register_for_test_plugins')
);

return {
NODE_OPTIONS: `--require=${testOnlyRegisterPath}${
process.env.NODE_OPTIONS ? ` ${process.env.NODE_OPTIONS}` : ''
}`,
};
}

export async function runKibanaServer({ procs, config, options }) {
const { installDir } = options;

Expand All @@ -29,6 +46,7 @@ export async function runKibanaServer({ procs, config, options }) {
env: {
FORCE_COLOR: 1,
...process.env,
...extendNodeOptions(installDir),
},
cwd: installDir || KIBANA_ROOT,
wait: /http server running/,
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_plugin_list_docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/dev-utils').runPluginListCli();
2 changes: 1 addition & 1 deletion scripts/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');

var resolve = require('path').resolve;
var pkg = require('../package.json');
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/plugin-generator').runCli();
4 changes: 1 addition & 3 deletions scripts/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
* under the License.
*/

require('../src/apm')(process.env.ELASTIC_APM_PROXY_SERVICE_NAME || 'kibana-proxy');
require('../src/setup_node_env');
require('../src/cli/cli');
require('../src/cli/dev');
2 changes: 1 addition & 1 deletion scripts/plugin_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/plugin-helpers').runCli();
2 changes: 1 addition & 1 deletion scripts/register_git_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/dev-utils/target/precommit_hook/cli');
2 changes: 1 addition & 1 deletion scripts/release_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/release-notes').runReleaseNotesCli();
2 changes: 1 addition & 1 deletion scripts/telemetry_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/telemetry-tools').runTelemetryCheck();
2 changes: 1 addition & 1 deletion scripts/telemetry_extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

require('../src/setup_node_env/prebuilt_dev_only_entry');
require('../src/setup_node_env/no_transpilation');
require('@kbn/telemetry-tools').runTelemetryExtract();
2 changes: 1 addition & 1 deletion src/cli/cluster/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { EventEmitter } from 'events';
import { BinderFor } from './binder_for';
import { fromRoot } from '../../core/server/utils';

const cliPath = fromRoot('src/cli');
const cliPath = fromRoot('src/cli/dev');
const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);
const baseArgv = [process.execPath, cliPath].concat(baseArgs);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.js → src/cli/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

require('../apm')();
require('../apm')(process.env.ELASTIC_APM_PROXY_SERVICE_NAME || 'kibana-proxy');
require('../setup_node_env');
require('./cli');
23 changes: 23 additions & 0 deletions src/cli/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

require('../apm')();
require('../setup_node_env/no_transpilation');
require('../setup_node_env/babel_register/polyfill');
require('./cli');
Loading

0 comments on commit 2e0d07d

Please sign in to comment.