Skip to content

Commit

Permalink
chore(NA): moving @kbn/ui-shared-deps into bazel (#101669)
Browse files Browse the repository at this point in the history
* chore(NA): moving @kbn/io-ts-utils into bazel

* chore(NA): moving @kbn/ui-shared-deps into bazel

* chore(NA): compelte working build for @kbn/ui-shared-deps

* chore(NA): solve eslint problems

* chore(NA): solve typechecking

* chore(NA): debugger changes

* chore(NA): update optimizer basic integration tests

* chore(NA): ship kbn/ui-shared-deps metrics.json from new location at shared_built_assets

* chore(NA): use correct ui-shared-deps metrics file location

* chore(NA): remove webpack bazel config

* chore(NA): implement improvements on webpack config

* chore(NA): remove extra comment

* chore(NA): try esbuild-loader minimizer

* Revert "chore(NA): try esbuild-loader minimizer"

This reverts commit bffc49a.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
mistic and kibanamachine committed Jun 18, 2021
1 parent 853de83 commit cee33b0
Show file tree
Hide file tree
Showing 50 changed files with 289 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/post_build_kibana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [[ ! "${DISABLE_CI_STATS_SHIPPING:-}" ]]; then
echo "--- Ship Kibana Distribution Metrics to CI Stats"
node scripts/ship_ci_stats \
--metrics target/optimizer_bundle_metrics.json \
--metrics packages/kbn-ui-shared-deps/target/metrics.json
--metrics node_modules/@kbn/ui-shared-deps/shared_built_assets/metrics.json
fi

echo "--- Upload Build Artifacts"
Expand Down
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ snapshots.js
/packages/kbn-test/src/functional_test_runner/__tests__/fixtures/
/packages/kbn-test/src/functional_test_runner/lib/config/__tests__/fixtures/
/packages/kbn-ui-framework/dist
/packages/kbn-ui-shared-deps/flot_charts
/packages/kbn-ui-shared-deps/src/flot_charts
/packages/kbn-monaco/src/painless/antlr

# Bazel
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ module.exports = {
},
},
{
files: ['packages/kbn-ui-shared-deps/flot_charts/**/*.js'],
files: ['packages/kbn-ui-shared-deps/src/flot_charts/**/*.js'],
env: {
jquery: true,
},
Expand Down
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"uiActionsExamples": "examples/ui_action_examples",
"share": "src/plugins/share",
"home": "src/plugins/home",
"flot": "packages/kbn-ui-shared-deps/flot_charts",
"flot": "packages/kbn-ui-shared-deps/src/flot_charts",
"charts": "src/plugins/charts",
"esUi": "src/plugins/es_ui_shared",
"devTools": "src/plugins/dev_tools",
Expand Down
1 change: 1 addition & 0 deletions docs/developer/getting-started/monorepo-packages.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ yarn kbn watch-bazel
- @kbn/std
- @kbn/telemetry-utils
- @kbn/tinymath
- @kbn/ui-shared-deps
- @kbn/utility-types
- @kbn/utils
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"@kbn/std": "link:bazel-bin/packages/kbn-std",
"@kbn/tinymath": "link:bazel-bin/packages/kbn-tinymath",
"@kbn/ui-framework": "link:packages/kbn-ui-framework",
"@kbn/ui-shared-deps": "link:packages/kbn-ui-shared-deps",
"@kbn/ui-shared-deps": "link:bazel-bin/packages/kbn-ui-shared-deps",
"@kbn/utility-types": "link:bazel-bin/packages/kbn-utility-types",
"@kbn/common-utils": "link:bazel-bin/packages/kbn-common-utils",
"@kbn/utils": "link:bazel-bin/packages/kbn-utils",
Expand Down Expand Up @@ -291,6 +291,7 @@
"mapbox-gl-draw-rectangle-mode": "1.0.4",
"markdown-it": "^10.0.0",
"md5": "^2.1.0",
"mdast-util-to-hast": "10.0.1",
"memoize-one": "^5.0.0",
"mime": "^2.4.4",
"mime-types": "^2.1.27",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ filegroup(
"//packages/kbn-std:build",
"//packages/kbn-telemetry-tools:build",
"//packages/kbn-tinymath:build",
"//packages/kbn-ui-shared-deps:build",
"//packages/kbn-utility-types:build",
"//packages/kbn-utils:build",
],
Expand Down
3 changes: 0 additions & 3 deletions packages/kbn-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@
"build": "../../node_modules/.bin/tsc",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},
"dependencies": {
"@kbn/ui-shared-deps": "link:../kbn-ui-shared-deps"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import cpy from 'cpy';
import del from 'del';
import { tap, filter } from 'rxjs/operators';
import { REPO_ROOT } from '@kbn/utils';
import { ToolingLog } from '@kbn/dev-utils';
import { ToolingLog, createReplaceSerializer } from '@kbn/dev-utils';
import { runOptimizer, OptimizerConfig, OptimizerUpdate, logOptimizerState } from '../index';

import { allValuesFrom } from '../common';
Expand All @@ -29,6 +29,8 @@ expect.addSnapshotSerializer({
test: (value: any) => typeof value === 'string' && value.includes(REPO_ROOT),
});

expect.addSnapshotSerializer(createReplaceSerializer(/\w+-fastbuild/, '<platform>-fastbuild'));

const log = new ToolingLog({
level: 'error',
writeTo: {
Expand Down Expand Up @@ -130,13 +132,13 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
expect(foo.cache.getModuleCount()).toBe(6);
expect(foo.cache.getReferencedFiles()).toMatchInlineSnapshot(`
Array [
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/bazel-out/<platform>-fastbuild/bin/packages/kbn-ui-shared-deps/target/public_path_module_creator.js,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/kibana.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/async_import.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/ext.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/index.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/lib.ts,
<absolute path>/packages/kbn-optimizer/src/worker/entry_point_creator.ts,
<absolute path>/packages/kbn-ui-shared-deps/public_path_module_creator.js,
]
`);

Expand All @@ -153,6 +155,7 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
<absolute path>/node_modules/@kbn/optimizer/postcss.config.js,
<absolute path>/node_modules/css-loader/package.json,
<absolute path>/node_modules/style-loader/package.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/bazel-out/<platform>-fastbuild/bin/packages/kbn-ui-shared-deps/target/public_path_module_creator.js,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/kibana.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.ts,
Expand All @@ -162,7 +165,6 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/core_app/styles/_globals_v8dark.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/core_app/styles/_globals_v8light.scss,
<absolute path>/packages/kbn-optimizer/src/worker/entry_point_creator.ts,
<absolute path>/packages/kbn-ui-shared-deps/public_path_module_creator.js,
]
`);

Expand All @@ -173,10 +175,10 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {

expect(baz.cache.getReferencedFiles()).toMatchInlineSnapshot(`
Array [
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/bazel-out/<platform>-fastbuild/bin/packages/kbn-ui-shared-deps/target/public_path_module_creator.js,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/x-pack/baz/kibana.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/x-pack/baz/public/index.ts,
<absolute path>/packages/kbn-optimizer/src/worker/entry_point_creator.ts,
<absolute path>/packages/kbn-ui-shared-deps/public_path_module_creator.js,
]
`);
});
Expand Down
15 changes: 13 additions & 2 deletions packages/kbn-optimizer/src/worker/populate_bundle_cache_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ export class PopulateBundleCachePlugin {
for (const module of compilation.modules) {
if (isNormalModule(module)) {
moduleCount += 1;
const path = getModulePath(module);
const parsedPath = parseFilePath(path);
let path = getModulePath(module);
let parsedPath = parseFilePath(path);

if (parsedPath.dirs.includes('bazel-out')) {
const index = parsedPath.dirs.indexOf('bazel-out');
path = Path.join(
workerConfig.repoRoot,
'bazel-out',
...parsedPath.dirs.slice(index + 1),
parsedPath.filename ?? ''
);
parsedPath = parseFilePath(path);
}

if (!parsedPath.dirs.includes('node_modules')) {
referencedFiles.add(path);
Expand Down
145 changes: 145 additions & 0 deletions packages/kbn-ui-shared-deps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
load("@npm//webpack-cli:index.bzl", webpack = "webpack_cli")

PKG_BASE_NAME = "kbn-ui-shared-deps"
PKG_REQUIRE_NAME = "@kbn/ui-shared-deps"

SOURCE_FILES = glob(
[
"src/**/*",
],
exclude = [
"**/*.md",
],
)

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"flot_charts/package.json",
"theme/package.json",
"package.json",
"README.md"
]

SRC_DEPS = [
"//packages/elastic-datemath",
"//packages/elastic-safer-lodash-set",
"//packages/kbn-analytics",
"//packages/kbn-babel-preset",
"//packages/kbn-i18n",
"//packages/kbn-monaco",
"//packages/kbn-std",
"//packages/kbn-utils",
"@npm//@elastic/charts",
"@npm//@elastic/eui",
"@npm//@elastic/numeral",
"@npm//abortcontroller-polyfill",
"@npm//angular",
"@npm//babel-loader",
"@npm//compression-webpack-plugin",
"@npm//core-js",
"@npm//css-minimizer-webpack-plugin",
"@npm//css-loader",
"@npm//fflate",
"@npm//jquery",
"@npm//loader-utils",
# TODO: we can remove this once EUI patches the dependencies
"@npm//mdast-util-to-hast",
"@npm//mini-css-extract-plugin",
"@npm//moment",
"@npm//moment-timezone",
"@npm//raw-loader",
"@npm//react",
"@npm//react-dom",
"@npm//react-intl",
"@npm//react-is",
"@npm//react-router",
"@npm//react-router-dom",
"@npm//regenerator-runtime",
"@npm//resize-observer-polyfill",
"@npm//rison-node",
"@npm//rxjs",
"@npm//styled-components",
"@npm//symbol-observable",
"@npm//terser-webpack-plugin",
"@npm//url-loader",
"@npm//val-loader",
"@npm//whatwg-fetch"
]

TYPES_DEPS = [
"@npm//@types/node",
]

DEPS = SRC_DEPS + TYPES_DEPS

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

ts_project(
name = "tsc",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
allow_js = True,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

webpack(
name = "shared_built_assets",
data = DEPS + [
"//:package.json",
":srcs",
":tsconfig",
":webpack.config.js",
],
output_dir = True,
args = [
"--config",
"$(location webpack.config.js)",
"--output-path",
"$(@D)",
"--display=minimal"
],
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":tsc", ":shared_built_assets"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
]
)

filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions packages/kbn-ui-shared-deps/flot_charts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target/flot_charts/index.js",
"types": "../target/flot_charts/index.d.ts"
}
59 changes: 0 additions & 59 deletions packages/kbn-ui-shared-deps/index.d.ts

This file was deleted.

7 changes: 2 additions & 5 deletions packages/kbn-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "1.0.0",
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"scripts": {
"build": "node scripts/build",
"kbn:bootstrap": "node scripts/build --dev",
"kbn:watch": "node scripts/build --dev --watch"
}
"main": "target/index.js",
"types": "target/index.d.ts"
}
Loading

0 comments on commit cee33b0

Please sign in to comment.