Skip to content

Commit

Permalink
Migrate App services plugins to TS projects (#87294)
Browse files Browse the repository at this point in the history
* migrate expressions to ts project refs

* bfetch to ts project

* ui_actions to ts project

* move fitures to data plugins

* add data ts project

* remove outdated ts-expect-error

* add data to x-pack tsconfigs

* navigation to ts project

* cleanup licensing tsconfig

* saved_objects to ts project

* embeddable to ts project

* ui_actions_enhanced to ts project

* embeddable_enhanced to ts project

* features to ts project

* data_enhanced to ts project refs

* fix i18n check

* fix find_plugins_ready_to_migrate_to_ts_refs script

* add a comment for bug ignoring json for composite projects

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mshustov and kibanamachine authored Jan 7, 2021
1 parent 1d49166 commit 69e2c38
Show file tree
Hide file tree
Showing 39 changed files with 1,187 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/dev/run_find_plugins_ready_migrate_to_ts_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import Path from 'path';
import Fs from 'fs';
import JSON5 from 'json5';
import { get } from 'lodash';
import { run, KibanaPlatformPlugin } from '@kbn/dev-utils';
import { getPluginDeps, findPlugins } from './plugin_discovery';
Expand Down Expand Up @@ -46,7 +47,8 @@ run(
id: pluginId,
});

if (deps.size === 0 && errors.size === 0) {
const allDepsMigrated = [...deps].every((p) => isMigratedToTsProjectRefs(p.directory));
if (allDepsMigrated && errors.size === 0) {
readyToMigrate.add(pluginMap.get(pluginId)!);
}
}
Expand Down Expand Up @@ -82,7 +84,7 @@ function isMigratedToTsProjectRefs(dir: string): boolean {
try {
const path = Path.join(dir, 'tsconfig.json');
const content = Fs.readFileSync(path, { encoding: 'utf8' });
return get(JSON.parse(content), 'compilerOptions.composite', false);
return get(JSON5.parse(content), 'compilerOptions.composite', false);
} catch (e) {
return false;
}
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/bfetch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": ["common/**/*", "public/**/*", "server/**/*", "index.ts"],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../kibana_utils/tsconfig.json" },
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.
*/
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { shouldReadFieldFromDocValues, castEsToKbnFieldTypeName } from '../../../../server';

function stubbedLogstashFields() {
return [
// |aggregatable
// | |searchable
// name esType | | |metadata | subType
['bytes', 'long', true, true, { count: 10 }],
['ssl', 'boolean', true, true, { count: 20 }],
['@timestamp', 'date', true, true, { count: 30 }],
['time', 'date', true, true, { count: 30 }],
['@tags', 'keyword', true, true],
['utc_time', 'date', true, true],
['phpmemory', 'integer', true, true],
['ip', 'ip', true, true],
['request_body', 'attachment', true, true],
['point', 'geo_point', true, true],
['area', 'geo_shape', true, true],
['hashed', 'murmur3', false, true],
['geo.coordinates', 'geo_point', true, true],
['extension', 'text', true, true],
['extension.keyword', 'keyword', true, true, {}, { multi: { parent: 'extension' } }],
['machine.os', 'text', true, true],
['machine.os.raw', 'keyword', true, true, {}, { multi: { parent: 'machine.os' } }],
['geo.src', 'keyword', true, true],
['_id', '_id', true, true],
['_type', '_type', true, true],
['_source', '_source', true, true],
['non-filterable', 'text', true, false],
['non-sortable', 'text', false, false],
['custom_user_field', 'conflict', true, true],
['script string', 'text', true, false, { script: "'i am a string'" }],
['script number', 'long', true, false, { script: '1234' }],
['script date', 'date', true, false, { script: '1234', lang: 'painless' }],
['script murmur3', 'murmur3', true, false, { script: '1234' }],
].map(function (row) {
const [name, esType, aggregatable, searchable, metadata = {}, subType = undefined] = row;

const {
count = 0,
script,
lang = script ? 'expression' : undefined,
scripted = !!script,
} = metadata;

// the conflict type is actually a kbnFieldType, we
// don't have any other way to represent it here
const type = esType === 'conflict' ? esType : castEsToKbnFieldTypeName(esType);

return {
name,
type,
esTypes: [esType],
readFromDocValues: shouldReadFieldFromDocValues(aggregatable, esType),
aggregatable,
searchable,
count,
script,
lang,
scripted,
subType,
};
});
}

export default stubbedLogstashFields;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

// @ts-expect-error
import stubbedLogstashFields from './logstash_fields';

const mockLogstashFields = stubbedLogstashFields();

export function stubbedSavedObjectIndexPattern(id: string | null = null) {
return {
id,
type: 'index-pattern',
attributes: {
timeFieldName: 'timestamp',
customFormats: {},
fields: mockLogstashFields,
title: 'title',
},
version: '2',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { IndexPattern } from './index_pattern';

import { DuplicateField } from '../../../../kibana_utils/common';
// @ts-expect-error
import mockLogStashFields from '../../../../../fixtures/logstash_fields';
import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern';
import mockLogStashFields from './fixtures/logstash_fields';
import { stubbedSavedObjectIndexPattern } from './fixtures/stubbed_saved_object_index_pattern';
import { IndexPatternField } from '../fields';

import { fieldFormatsMock } from '../../field_formats/mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { defaults } from 'lodash';
import { IndexPatternsService, IndexPattern } from '.';
import { fieldFormatsMock } from '../../field_formats/mocks';
import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern';
import { stubbedSavedObjectIndexPattern } from './fixtures/stubbed_saved_object_index_pattern';
import { UiSettingsCommon, SavedObjectsClientCommon, SavedObject } from '../types';

const createFieldsFetcher = jest.fn().mockImplementation(() => ({
Expand Down
Loading

0 comments on commit 69e2c38

Please sign in to comment.