Skip to content

Commit

Permalink
[IDM] define v2 Kibana manifest schema (elastic#137611)
Browse files Browse the repository at this point in the history
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
Spencer and kibanamachine authored Aug 5, 2022
1 parent 4462e16 commit 76f1b8d
Show file tree
Hide file tree
Showing 54 changed files with 1,807 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@
/packages/kbn-ui-shared-deps-npm/ @elastic/kibana-operations
/packages/kbn-ui-shared-deps-src/ @elastic/kibana-operations
/packages/kbn-utils/ @elastic/kibana-operations
/packages/kbn-jsonc/ @elastic/kibana-operations
/packages/kbn-kibana-manifest-parser/ @elastic/kibana-operations
/packages/kbn-kibana-manifest-schema/ @elastic/kibana-operations
/packages/kbn-managed-vscode-config/ @elastic/kibana-operations
/packages/kbn-managed-vscode-config-cli/ @elastic/kibana-operations
/src/cli/keystore/ @elastic/kibana-operations
/.ci/es-snapshots/ @elastic/kibana-operations
/.github/workflows/ @elastic/kibana-operations
Expand Down
14 changes: 14 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ THE SOFTWARE.
This product uses Noto fonts that are licensed under the SIL Open
Font License, Version 1.1.

---
Vendored copy of `strip-json-comments` so that we can use it when npm modules are not available.
https://github.com/sindresorhus/strip-json-comments/tree/34b79cb0f1129aa85ef4b5c3292e8bc546984ef9

MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

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.

---
Based on the scroll-into-view-if-necessary module from npm
https://github.com/stipsan/compute-scroll-into-view/blob/master/src/index.ts#L269-L340
Expand Down
5 changes: 5 additions & 0 deletions dev_docs/operations/operations_landing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,10 @@ layout: landing
{ pageId: "kibDevDocsOpsDevCliRunner" },
{ pageId: "kibDevDocsOpsGetRepoFiles" },
{ pageId: "kibDevDocsOpsRepoSourceClassifier" },
{ pageId: "kibDevDocsOpsJsonc" },
{ pageId: "kibDevDocsOpsKibanaManifestParser" },
{ pageId: "kibDevDocsOpsKibanaManifestSchema" },
{ pageId: "kibDevDocsOpsManagedVscodeConfig" },
{ pageId: "kibDevDocsOpsManagedVscodeConfigCli" },
]}
/>
15 changes: 15 additions & 0 deletions nav-kibana-dev.docnav.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,21 @@
},
{
"id": "kibDevDocsOpsRepoSourceClassifier"
},
{
"id": "kibDevDocsOpsJsonc"
},
{
"id": "kibDevDocsOpsKibanaManifestParser"
},
{
"id": "kibDevDocsOpsKibanaManifestSchema"
},
{
"id": "kibDevDocsOpsManagedVscodeConfig"
},
{
"id": "kibDevDocsOpsManagedVscodeConfigCli"
}
]
}
Expand Down
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@
"@kbn/i18n-react": "link:bazel-bin/packages/kbn-i18n-react",
"@kbn/interpreter": "link:bazel-bin/packages/kbn-interpreter",
"@kbn/io-ts-utils": "link:bazel-bin/packages/kbn-io-ts-utils",
"@kbn/kibana-json-schema": "link:bazel-bin/packages/kbn-kibana-json-schema",
"@kbn/jsonc": "link:bazel-bin/packages/kbn-jsonc",
"@kbn/kibana-manifest-parser": "link:bazel-bin/packages/kbn-kibana-manifest-parser",
"@kbn/kibana-manifest-schema": "link:bazel-bin/packages/kbn-kibana-manifest-schema",
"@kbn/logging": "link:bazel-bin/packages/kbn-logging",
"@kbn/logging-mocks": "link:bazel-bin/packages/kbn-logging-mocks",
"@kbn/mapbox-gl": "link:bazel-bin/packages/kbn-mapbox-gl",
Expand Down Expand Up @@ -641,6 +643,8 @@
"@kbn/get-repo-files": "link:bazel-bin/packages/kbn-get-repo-files",
"@kbn/import-resolver": "link:bazel-bin/packages/kbn-import-resolver",
"@kbn/jest-serializers": "link:bazel-bin/packages/kbn-jest-serializers",
"@kbn/managed-vscode-config": "link:bazel-bin/packages/kbn-managed-vscode-config",
"@kbn/managed-vscode-config-cli": "link:bazel-bin/packages/kbn-managed-vscode-config-cli",
"@kbn/optimizer": "link:bazel-bin/packages/kbn-optimizer",
"@kbn/optimizer-webpack-helpers": "link:bazel-bin/packages/kbn-optimizer-webpack-helpers",
"@kbn/performance-testing-dataset-extractor": "link:bazel-bin/packages/kbn-performance-testing-dataset-extractor",
Expand Down Expand Up @@ -693,6 +697,7 @@
"@types/apidoc": "^0.22.3",
"@types/archiver": "^5.3.1",
"@types/babel__core": "^7.1.19",
"@types/babel__generator": "^7.6.4",
"@types/babel__helper-plugin-utils": "^7.10.0",
"@types/base64-js": "^1.2.5",
"@types/chance": "^1.0.0",
Expand Down Expand Up @@ -751,6 +756,7 @@
"@types/js-search": "^1.4.0",
"@types/js-yaml": "^3.11.1",
"@types/jsdom": "^16.2.14",
"@types/json-schema": "^7",
"@types/json-stable-stringify": "^1.0.32",
"@types/json5": "^0.0.30",
"@types/jsonwebtoken": "^8.5.6",
Expand Down Expand Up @@ -916,10 +922,14 @@
"@types/kbn__interpreter": "link:bazel-bin/packages/kbn-interpreter/npm_module_types",
"@types/kbn__io-ts-utils": "link:bazel-bin/packages/kbn-io-ts-utils/npm_module_types",
"@types/kbn__jest-serializers": "link:bazel-bin/packages/kbn-jest-serializers/npm_module_types",
"@types/kbn__jsonc": "link:bazel-bin/packages/kbn-jsonc/npm_module_types",
"@types/kbn__kbn-ci-stats-performance-metrics": "link:bazel-bin/packages/kbn-kbn-ci-stats-performance-metrics/npm_module_types",
"@types/kbn__kibana-json-schema": "link:bazel-bin/packages/kbn-kibana-json-schema/npm_module_types",
"@types/kbn__kibana-manifest-parser": "link:bazel-bin/packages/kbn-kibana-manifest-parser/npm_module_types",
"@types/kbn__kibana-manifest-schema": "link:bazel-bin/packages/kbn-kibana-manifest-schema/npm_module_types",
"@types/kbn__logging": "link:bazel-bin/packages/kbn-logging/npm_module_types",
"@types/kbn__logging-mocks": "link:bazel-bin/packages/kbn-logging-mocks/npm_module_types",
"@types/kbn__managed-vscode-config": "link:bazel-bin/packages/kbn-managed-vscode-config/npm_module_types",
"@types/kbn__managed-vscode-config-cli": "link:bazel-bin/packages/kbn-managed-vscode-config-cli/npm_module_types",
"@types/kbn__mapbox-gl": "link:bazel-bin/packages/kbn-mapbox-gl/npm_module_types",
"@types/kbn__ml-agg-utils": "link:bazel-bin/x-pack/packages/ml/agg_utils/npm_module_types",
"@types/kbn__ml-is-populated-object": "link:bazel-bin/x-pack/packages/ml/is_populated_object/npm_module_types",
Expand Down Expand Up @@ -1093,6 +1103,7 @@
"@yarnpkg/lockfile": "^1.1.0",
"abab": "^2.0.4",
"aggregate-error": "^3.1.0",
"ajv": "^8.11.0",
"antlr4ts-cli": "^0.5.0-alpha.3",
"apidoc": "^0.29.0",
"apidoc-markdown": "^6.0.0",
Expand Down Expand Up @@ -1195,7 +1206,7 @@
"jest-styled-components": "^7.0.3",
"jimp": "^0.14.0",
"jsdom": "13.1.0",
"json-schema-typed": "^7.0.3",
"json-schema-typed": "^8.0.1",
"json5": "^1.0.1",
"jsondiffpatch": "0.4.1",
"license-checker": "^25.0.1",
Expand Down
12 changes: 10 additions & 2 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,13 @@ filegroup(
"//packages/kbn-interpreter:build",
"//packages/kbn-io-ts-utils:build",
"//packages/kbn-jest-serializers:build",
"//packages/kbn-kibana-json-schema:build",
"//packages/kbn-jsonc:build",
"//packages/kbn-kibana-manifest-parser:build",
"//packages/kbn-kibana-manifest-schema:build",
"//packages/kbn-logging-mocks:build",
"//packages/kbn-logging:build",
"//packages/kbn-managed-vscode-config-cli:build",
"//packages/kbn-managed-vscode-config:build",
"//packages/kbn-mapbox-gl:build",
"//packages/kbn-monaco:build",
"//packages/kbn-optimizer-webpack-helpers:build",
Expand Down Expand Up @@ -424,9 +428,13 @@ filegroup(
"//packages/kbn-interpreter:build_types",
"//packages/kbn-io-ts-utils:build_types",
"//packages/kbn-jest-serializers:build_types",
"//packages/kbn-kibana-json-schema:build_types",
"//packages/kbn-jsonc:build_types",
"//packages/kbn-kibana-manifest-parser:build_types",
"//packages/kbn-kibana-manifest-schema:build_types",
"//packages/kbn-logging-mocks:build_types",
"//packages/kbn-logging:build_types",
"//packages/kbn-managed-vscode-config-cli:build_types",
"//packages/kbn-managed-vscode-config:build_types",
"//packages/kbn-mapbox-gl:build_types",
"//packages/kbn-monaco:build_types",
"//packages/kbn-optimizer-webpack-helpers:build_types",
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-dev-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RUNTIME_DEPS = [
"//packages/kbn-stdio-dev-helpers",
"//packages/kbn-ci-stats-reporter",
"//packages/kbn-jest-serializers",
"//packages/kbn-kibana-json-schema",
"//packages/kbn-kibana-manifest-schema",
"@npm//@babel/core",
"@npm//axios",
"@npm//chalk",
Expand Down Expand Up @@ -84,7 +84,7 @@ TYPES_DEPS = [
"//packages/kbn-stdio-dev-helpers:npm_module_types",
"//packages/kbn-ci-stats-reporter:npm_module_types",
"//packages/kbn-jest-serializers:npm_module_types",
"//packages/kbn-kibana-json-schema:npm_module_types",
"//packages/kbn-kibana-manifest-schema:npm_module_types",
"@npm//@babel/parser",
"@npm//@babel/types",
"@npm//@types/babel__core",
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-dev-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ export * from './plugin_list';
export * from './streams';
export * from './babel';
export * from './extract';
export * from './vscode_config';
export * from './diff_strings';
117 changes: 117 additions & 0 deletions packages/kbn-jsonc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "kbn-jsonc"
PKG_REQUIRE_NAME = "@kbn/jsonc"

SOURCE_FILES = glob(
[
"src/**/*.js",
],
exclude = [
"**/*.test.*",
"**/*.stories.*",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

# In this array place runtime dependencies, including other packages and NPM packages
# which must be available for this code to run.
#
# To reference other packages use:
# "//repo/relative/path/to/package"
# eg. "//packages/kbn-utils"
#
# To reference a NPM package use:
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
]

# In this array place dependencies necessary to build the types, which will include the
# :npm_module_types target of other packages and packages from NPM, including @types/*
# packages.
#
# To reference the types for another package use:
# "//repo/relative/path/to/package:npm_module_types"
# eg. "//packages/kbn-utils:npm_module_types"
#
# References to NPM packages work the same as RUNTIME_DEPS
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
allow_js = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)
20 changes: 20 additions & 0 deletions packages/kbn-jsonc/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
id: kibDevDocsOpsJsonc
slug: /kibana-dev-docs/ops/jsonc
title: "@kbn/jsonc"
description: A package for parsing jsonc
date: 2022-05-24
tags: ['kibana', 'dev', 'contributor', 'operations', 'json', 'jsonc']
---

This package exposes a simple `parse(jsonc: string)` function for parsing JSON-C content. JSON-C is a variant of JSON which supports both block and line comments, which are incredibly useful for configuration files that are committed to the repository and would benefit from the context of comments.

Additionally supported in JSON-C... TRAILING COMMAS!

VSCode and TypeScript use jsonc for their config files, so we're already using it in a lot of places, but we're going to start using it in more places too. This package is implemented in vanilla JS with a vendored copy of [`strip-json-comments`](https://github.com/sindresorhus/strip-json-comments) so that we can use this code from kbn_pm without node modules installed.

## API

### parse(jsonc: string): any

Parses a JSON-C string into the value defined by the content.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
* Side Public License, v 1.
*/

export { KibanaJsonSchema } from './kibana_json_schema';
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-jsonc'],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@kbn/kibana-json-schema",
"name": "@kbn/jsonc",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
Expand Down
23 changes: 23 additions & 0 deletions packages/kbn-jsonc/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const { stripJsonComments } = require('./strip_json_comments');

/**
* @param {string} jsonWithComments
*/
function parse(jsonWithComments) {
return JSON.parse(
stripJsonComments(jsonWithComments, {
whitespace: false,
trailingCommas: true,
})
);
}

module.exports = { parse };
Loading

0 comments on commit 76f1b8d

Please sign in to comment.