Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate App services plugins to TS projects #87294

Merged
merged 22 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines -85 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an issue with the default JSON parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} 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
mshustov marked this conversation as resolved.
Show resolved Hide resolved
['bytes', 'long', true, true, { count: 10 }],
['ssl', 'boolean', true, true, { count: 20 }],
['@timestamp', 'date', true, true, { count: 30 }],
Copy link
Contributor

@lizozom lizozom Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture still exists in src/fixtures and is being used in other plugins, any reason why we started duplicating them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixtures folder doesn't have an owner. This file is used by data and discover plugins only. If you want to keep them in sync, we might need to consider exporting them from the data plugin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what would be the rule of thumb of what goes into src/fixtures?

Copy link
Contributor Author

@mshustov mshustov Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what goes into src/fixtures?

nothing. it should be removed eventually. global folders won't exist when we move to domain-based folder structure #71566

['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