Skip to content

Commit

Permalink
chore(NA): moving @kbn/optimizer into bazel (#102965)
Browse files Browse the repository at this point in the history
* chore(NA): moving @kbn/optimizer into bazel

* chore(NA): fix source import from kbn optimizer

* chore(NA): update snapshots
  • Loading branch information
mistic authored Jun 23, 2021
1 parent 38be1d0 commit e1ec8b0
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 21 deletions.
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 @@ -86,6 +86,7 @@ yarn kbn watch-bazel
- @kbn/logging
- @kbn/mapbox-gl
- @kbn/monaco
- @kbn/optimizer
- @kbn/rule-data-utils
- @kbn/securitysolution-es-utils
- @kbn/securitysolution-hook-utils
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
"@kbn/eslint-import-resolver-kibana": "link:bazel-bin/packages/kbn-eslint-import-resolver-kibana",
"@kbn/eslint-plugin-eslint": "link:bazel-bin/packages/kbn-eslint-plugin-eslint",
"@kbn/expect": "link:bazel-bin/packages/kbn-expect",
"@kbn/optimizer": "link:packages/kbn-optimizer",
"@kbn/optimizer": "link:bazel-bin/packages/kbn-optimizer",
"@kbn/plugin-generator": "link:bazel-bin/packages/kbn-plugin-generator",
"@kbn/plugin-helpers": "link:packages/kbn-plugin-helpers",
"@kbn/pm": "link:packages/kbn-pm",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ filegroup(
"//packages/kbn-logging:build",
"//packages/kbn-mapbox-gl:build",
"//packages/kbn-monaco:build",
"//packages/kbn-optimizer:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-rule-data-utils:build",
"//packages/kbn-securitysolution-list-constants:build",
Expand Down
3 changes: 0 additions & 3 deletions packages/kbn-cli-dev-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@
},
"kibana": {
"devOnly": true
},
"dependencies": {
"@kbn/optimizer": "link:../kbn-optimizer"
}
}
120 changes: 120 additions & 0 deletions packages/kbn-optimizer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-optimizer"
PKG_REQUIRE_NAME = "@kbn/optimizer"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = [
"**/*.test.*",
"**/__fixtures__/**",
"**/__snapshots__/**",
],
)

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"limits.yml",
"package.json",
"postcss.config.js",
"README.md"
]

SRC_DEPS = [
"//packages/kbn-config",
"//packages/kbn-dev-utils",
"//packages/kbn-std",
"//packages/kbn-ui-shared-deps",
"//packages/kbn-utils",
"@npm//chalk",
"@npm//clean-webpack-plugin",
"@npm//compression-webpack-plugin",
"@npm//cpy",
"@npm//del",
"@npm//execa",
"@npm//jest-diff",
"@npm//json-stable-stringify",
"@npm//lmdb-store",
"@npm//loader-utils",
"@npm//node-sass",
"@npm//normalize-path",
"@npm//pirates",
"@npm//resize-observer-polyfill",
"@npm//rxjs",
"@npm//source-map-support",
"@npm//watchpack",
"@npm//webpack",
"@npm//webpack-merge",
"@npm//webpack-sources",
"@npm//zlib"
]

TYPES_DEPS = [
"@npm//@types/compression-webpack-plugin",
"@npm//@types/jest",
"@npm//@types/json-stable-stringify",
"@npm//@types/loader-utils",
"@npm//@types/node",
"@npm//@types/normalize-path",
"@npm//@types/source-map-support",
"@npm//@types/watchpack",
"@npm//@types/webpack",
"@npm//@types/webpack-merge",
"@npm//@types/webpack-sources",
]

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,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":tsc"],
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"],
)
7 changes: 1 addition & 6 deletions packages/kbn-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"scripts": {
"build": "../../node_modules/.bin/tsc",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
}
"types": "./target/index.d.ts"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/worker/bundle_metrics_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class BundleMetricsPlugin {
id: bundle.id,
value: entry.size,
limit: bundle.pageLoadAssetSizeLimit,
limitConfigPath: `packages/kbn-optimizer/limits.yml`,
limitConfigPath: `node_modules/@kbn/optimizer/limits.yml`,
},
{
group: `async chunks size`,
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-optimizer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": false,
"incremental": true,
"outDir": "./target",
"declaration": true,
"declarationMap": true,
"rootDir": "./src",
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-optimizer/src"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/kbn-plugin-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@
"scripts": {
"kbn:bootstrap": "rm -rf target && ../../node_modules/.bin/tsc",
"kbn:watch": "../../node_modules/.bin/tsc --watch"
},
"dependencies": {
"@kbn/optimizer": "link:../kbn-optimizer"
}
}
3 changes: 0 additions & 3 deletions packages/kbn-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@
},
"kibana": {
"devOnly": true
},
"dependencies": {
"@kbn/optimizer": "link:../kbn-optimizer"
}
}
2 changes: 1 addition & 1 deletion packages/kbn-test/src/jest/setup/babel_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
// Note: In theory importing the polyfill should not be needed, as Babel should
// include the necessary polyfills when using `@babel/preset-env`, but for some
// reason it did not work. See https://github.com/elastic/kibana/issues/14506
import '@kbn/optimizer/src/node/polyfill';
import '@kbn/optimizer/target/node/polyfill';
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@
version "0.0.0"
uid ""

"@kbn/optimizer@link:packages/kbn-optimizer":
"@kbn/optimizer@link:bazel-bin/packages/kbn-optimizer":
version "0.0.0"
uid ""

Expand Down

0 comments on commit e1ec8b0

Please sign in to comment.