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

[ES UI Shared] Remove 'brace' from es_ui_shared public #78033

Merged
merged 8 commits into from
Sep 24, 2020
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib
/x-pack/plugins/upgrade_assistant/ @elastic/es-ui
/x-pack/plugins/watcher/ @elastic/es-ui
/x-pack/plugins/ingest_pipelines/ @elastic/es-ui
/packages/kbn-ace/ @elastic/es-ui
/packages/kbn-monaco/ @elastic/es-ui

# Endpoint
/x-pack/plugins/endpoint/ @elastic/endpoint-app-team @elastic/siem
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
"@kbn/telemetry-tools": "1.0.0",
"@kbn/test-subj-selector": "0.2.1",
"@kbn/ui-framework": "1.0.0",
"@kbn/ace": "1.0.0",
"@kbn/monaco": "1.0.0",
"@kbn/ui-shared-deps": "1.0.0",
"@types/yauzl": "^2.9.1",
"JSONStream": "1.3.5",
Expand Down
5 changes: 5 additions & 0 deletions packages/kbn-ace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @kbn/ace

Contains all Kibana-specific brace related code. Excluding the code that still inside of Console because that code is only used inside of console at the moment.

This package enables plugins to use this functionality and import it as needed -- behind an async import so that brace does not bloat the JS code needed for first page load of Kibana.
20 changes: 20 additions & 0 deletions packages/kbn-ace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@kbn/ace",
"version": "1.0.0",
"private": true,
"main": "./target/index.js",
"license": "Apache-2.0",
"scripts": {
"build": "node ./scripts/build.js",
"kbn:bootstrap": "yarn build --dev"
},
"dependencies": {
"brace": "0.11.1"
},
"devDependencies": {
"@kbn/dev-utils": "1.0.0",
"@kbn/babel-preset": "1.0.0",
"raw-loader": "3.1.0",
"typescript": "4.0.2"
}
}
65 changes: 65 additions & 0 deletions packages/kbn-ace/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 del = require('del');
const fs = require('fs');
const supportsColor = require('supports-color');
const { run } = require('@kbn/dev-utils');

const TARGET_BUILD_DIR = path.resolve(__dirname, '../target');
const ROOT_DIR = path.resolve(__dirname, '../');
const WORKER_PATH_SECTION = 'ace/modes/x_json/worker/x_json.ace.worker.js';

run(
async ({ procRunner, log }) => {
log.info('Deleting old output');

await del(TARGET_BUILD_DIR);

const cwd = ROOT_DIR;
const env = { ...process.env };

if (supportsColor.stdout) {
env.FORCE_COLOR = 'true';
}

await procRunner.run('tsc ', {
cmd: 'tsc',
args: [],
wait: true,
env,
cwd,
});

log.success('Copying worker file to target.');

fs.copyFileSync(
path.resolve(__dirname, '..', 'src', WORKER_PATH_SECTION),
path.resolve(__dirname, '..', 'target', WORKER_PATH_SECTION)
);

log.success('Complete');
},
{
flags: {
boolean: ['dev'],
},
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@
* under the License.
*/

export { useXJsonMode } from '../../__packages_do_not_import__/monaco';
export {
ElasticsearchSqlHighlightRules,
ScriptHighlightRules,
XJsonHighlightRules,
addXJsonToRules,
XJsonMode,
installXJsonMode,
} from './ace/modes';
15 changes: 15 additions & 0 deletions packages/kbn-ace/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target",
"declaration": true,
"sourceMap": true,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}
1 change: 1 addition & 0 deletions packages/kbn-ace/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { EuiScreenReaderOnly } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect, useRef } from 'react';
import { expandLiteralStrings } from '../../../../../../../es_ui_shared/public';
import { expandLiteralStrings } from '../../../../../shared_imports';
import {
useEditorReadContext,
useRequestReadContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { extractDeprecationMessages } from '../../../lib/utils';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/public';
import { XJson } from '../../../../../es_ui_shared/public';
const { collapseLiteralStrings } = XJson;
// @ts-ignore
import * as es from '../../../lib/es/es';
import { BaseResponseType } from '../../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import ace from 'brace';
import { addXJsonToRules } from '../../../../../../es_ui_shared/public';
import { addXJsonToRules } from '@kbn/ace';

export function addEOL(tokens, reg, nextIfEOL, normalNext) {
if (typeof reg === 'object') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import ace from 'brace';
import 'brace/mode/json';
import { addXJsonToRules } from '../../../../../../es_ui_shared/public';
import { addXJsonToRules } from '@kbn/ace';

const oop = ace.acequire('ace/lib/oop');
const JsonHighlightRules = ace.acequire('ace/mode/json_highlight_rules').JsonHighlightRules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import ace from 'brace';
import { ScriptHighlightRules } from '../../../../../../es_ui_shared/public';
import { ScriptHighlightRules } from '@kbn/ace';

const oop = ace.acequire('ace/lib/oop');
const TextMode = ace.acequire('ace/mode/text').Mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import $ from 'jquery';
import _ from 'lodash';

import { create } from '../create';
import { collapseLiteralStrings } from '../../../../../../es_ui_shared/public';
import { XJson } from '../../../../../../es_ui_shared/public';
import editorInput1 from './editor_input1.txt';

const { collapseLiteralStrings } = XJson;

describe('Editor', () => {
let input;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import _ from 'lodash';
import RowParser from '../../../lib/row_parser';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/public';
import { XJson } from '../../../../../es_ui_shared/public';
import * as utils from '../../../lib/utils';

// @ts-ignore
Expand All @@ -30,6 +30,8 @@ import { createTokenIterator } from '../../factories';

import Autocomplete from '../../../lib/autocomplete/autocomplete';

const { collapseLiteralStrings } = XJson;

export class SenseEditor {
currentReqRange: (Range & { markerRef: any }) | null;
parser: any;
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/console/public/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/

import _ from 'lodash';
import { expandLiteralStrings, collapseLiteralStrings } from '../../../../es_ui_shared/public';
import { XJson } from '../../../../es_ui_shared/public';

const { collapseLiteralStrings, expandLiteralStrings } = XJson;

export function textFromRequest(request: any) {
let data = request.data;
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/console/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { sendRequest } from '../../es_ui_shared/public';
import { sendRequest, XJson } from '../../es_ui_shared/public';

export { sendRequest };
const { collapseLiteralStrings, expandLiteralStrings } = XJson;

export { sendRequest, collapseLiteralStrings, expandLiteralStrings };

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
*/

export { useXJsonMode } from './use_xjson_mode';

export { collapseLiteralStrings, expandLiteralStrings } from './json_xjson_translation_tools';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { useState, Dispatch } from 'react';
import { collapseLiteralStrings, expandLiteralStrings } from '../../public';

import { collapseLiteralStrings, expandLiteralStrings } from './json_xjson_translation_tools';

interface ReturnValue {
xJson: string;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/es_ui_shared/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"ui": true,
"server": true,
"extraPublicDirs": [
"static/ace_x_json/hooks",
"static/validators/string",
"static/forms/hook_form_lib",
"static/forms/helpers",
Expand Down
32 changes: 0 additions & 32 deletions src/plugins/es_ui_shared/public/console_lang/index.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/plugins/es_ui_shared/public/console_lang/lib/index.ts

This file was deleted.

15 changes: 2 additions & 13 deletions src/plugins/es_ui_shared/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* In the future, each top level folder should be exported like that to avoid naming collision
*/
import * as Forms from './forms';
import * as Monaco from './monaco';
import * as ace from './ace';
import * as GlobalFlyout from './global_flyout';
import * as XJson from './xjson';

export { JsonEditor, OnJsonEditorUpdateHandler, JsonEditorState } from './components/json_editor';

Expand All @@ -43,17 +43,6 @@ export {

export { indices } from './indices';

export {
installXJsonMode,
XJsonMode,
ElasticsearchSqlHighlightRules,
addXJsonToRules,
ScriptHighlightRules,
XJsonHighlightRules,
collapseLiteralStrings,
expandLiteralStrings,
} from './console_lang';

export {
AuthorizationContext,
AuthorizationProvider,
Expand All @@ -66,7 +55,7 @@ export {
useAuthorizationContext,
} from './authorization';

export { Monaco, Forms, ace, GlobalFlyout };
export { Forms, ace, GlobalFlyout, XJson };

export { extractQueryParams } from './url';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { useXJsonMode } from './use_xjson_mode';
export * from '../../__packages_do_not_import__/xjson';
Loading