From 831e9d39611ba46ff6b88e35faf4112d7d618076 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 7 Oct 2021 20:20:01 +0000 Subject: [PATCH 1/3] fixup build process to better support front-end packages --- .../kbn-optimizer/src/worker/webpack.config.ts | 10 +++++++++- packages/kbn-react-page-template/BUILD.bazel | 17 ++++++++++++----- packages/kbn-react-page-template/package.json | 1 + .../kbn-react-page-template/react/package.json | 4 ---- .../src/assets/texture.svg | 1 + .../src/solution_nav/solution_nav_avatar.scss | 2 +- src/dev/bazel/jsts_transpiler.bzl | 1 + 7 files changed, 25 insertions(+), 11 deletions(-) delete mode 100644 packages/kbn-react-page-template/react/package.json create mode 100644 packages/kbn-react-page-template/src/assets/texture.svg diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts index 9a0863237fab1..6a76e23b7b3e9 100644 --- a/packages/kbn-optimizer/src/worker/webpack.config.ts +++ b/packages/kbn-optimizer/src/worker/webpack.config.ts @@ -28,6 +28,14 @@ const IS_CODE_COVERAGE = !!process.env.CODE_COVERAGE; const ISTANBUL_PRESET_PATH = require.resolve('@kbn/babel-preset/istanbul_preset'); const BABEL_PRESET_PATH = require.resolve('@kbn/babel-preset/webpack_preset'); +const nodeModulesButNotKbnPackages = (path: string) => { + if (!path.includes('node_modules')) { + return false; + } + + return !path.includes(`node_modules${Path.sep}@kbn${Path.sep}`); +}; + export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker: WorkerConfig) { const ENTRY_CREATOR = require.resolve('./entry_point_creator'); @@ -134,7 +142,7 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker: }, { test: /\.scss$/, - exclude: /node_modules/, + exclude: nodeModulesButNotKbnPackages, oneOf: [ ...worker.themeTags.map((theme) => ({ resourceQuery: `?${theme}`, diff --git a/packages/kbn-react-page-template/BUILD.bazel b/packages/kbn-react-page-template/BUILD.bazel index bb24d7196b107..a82d35ae0ecfc 100644 --- a/packages/kbn-react-page-template/BUILD.bazel +++ b/packages/kbn-react-page-template/BUILD.bazel @@ -9,7 +9,8 @@ SOURCE_FILES = glob( [ "src/**/*.ts", "src/**/*.tsx", - "types/**/*.ts" + "src/**/*.scss", + "src/**/*.svg", ], exclude = [ "**/*.test.*", @@ -26,7 +27,6 @@ filegroup( ) NPM_MODULE_EXTRA_FILES = [ - "react/package.json", "package.json", "README.md" ] @@ -41,22 +41,29 @@ RUNTIME_DEPS = [ TYPES_DEPS = [ "//packages/kbn-babel-preset", + "//packages/kbn-i18n", "@npm//tslib", "@npm//@types/jest", "@npm//@types/prop-types", "@npm//@types/classnames", "@npm//@types/react", "@npm//@elastic/eui", - "//packages/kbn-i18n", ] jsts_transpiler( - name = "target_node", + name = "target_webpack", srcs = SRCS, build_pkg_name = package_name(), web = True, ) +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), + web = False, +) + ts_config( name = "tsconfig", src = "tsconfig.json", @@ -83,7 +90,7 @@ ts_project( js_library( name = PKG_BASE_NAME, srcs = NPM_MODULE_EXTRA_FILES, - deps = RUNTIME_DEPS + [":target_node", ":tsc_types"], + deps = RUNTIME_DEPS + [":target_node", ":target_webpack", ":tsc_types"], package_name = PKG_REQUIRE_NAME, visibility = ["//visibility:public"], ) diff --git a/packages/kbn-react-page-template/package.json b/packages/kbn-react-page-template/package.json index 23b6217478b68..1ce17915a6e8c 100644 --- a/packages/kbn-react-page-template/package.json +++ b/packages/kbn-react-page-template/package.json @@ -1,6 +1,7 @@ { "name": "@kbn/react-page-template", "main": "./target_node/index.js", + "browser": "./target_webpack/index.js", "types": "./target_types/index.d.ts", "version": "1.0.0", "license": "SSPL-1.0 OR Elastic License 2.0", diff --git a/packages/kbn-react-page-template/react/package.json b/packages/kbn-react-page-template/react/package.json deleted file mode 100644 index 109e1c7bb9975..0000000000000 --- a/packages/kbn-react-page-template/react/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../target_node/react", - "types": "../target_types/react/index.d.ts" -} \ No newline at end of file diff --git a/packages/kbn-react-page-template/src/assets/texture.svg b/packages/kbn-react-page-template/src/assets/texture.svg new file mode 100644 index 0000000000000..fea0d6954343d --- /dev/null +++ b/packages/kbn-react-page-template/src/assets/texture.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kbn-react-page-template/src/solution_nav/solution_nav_avatar.scss b/packages/kbn-react-page-template/src/solution_nav/solution_nav_avatar.scss index 4b47fefc65891..d055e13a61616 100644 --- a/packages/kbn-react-page-template/src/solution_nav/solution_nav_avatar.scss +++ b/packages/kbn-react-page-template/src/solution_nav/solution_nav_avatar.scss @@ -7,7 +7,7 @@ line-height: 100px; border-radius: 100px; display: inline-block; - background: $euiColorEmptyShade url('../../assets/texture.svg') no-repeat; + background: $euiColorEmptyShade url('../assets/texture.svg') no-repeat; background-size: cover, 125%; text-align: center; } diff --git a/src/dev/bazel/jsts_transpiler.bzl b/src/dev/bazel/jsts_transpiler.bzl index 5116c73adb3c7..6028ec51e83c4 100644 --- a/src/dev/bazel/jsts_transpiler.bzl +++ b/src/dev/bazel/jsts_transpiler.bzl @@ -33,6 +33,7 @@ def jsts_transpiler(name, srcs, build_pkg_name, web = False, root_input_dir = "s "--out-dir", "$(@D)", "--no-babelrc", + "--copy-files", "--extensions", ".ts,.tsx,.js", ] + inline_presets + additional_args From 31dcf13ab29ed3ae62332a9c46f9e26483f0e991 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 7 Oct 2021 21:34:15 -0500 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Tiago Costa --- packages/kbn-react-page-template/BUILD.bazel | 5 ++++- src/dev/bazel/jsts_transpiler.bzl | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/kbn-react-page-template/BUILD.bazel b/packages/kbn-react-page-template/BUILD.bazel index a82d35ae0ecfc..c9bc63499feff 100644 --- a/packages/kbn-react-page-template/BUILD.bazel +++ b/packages/kbn-react-page-template/BUILD.bazel @@ -61,7 +61,10 @@ jsts_transpiler( name = "target_node", srcs = SRCS, build_pkg_name = package_name(), - web = False, + additional_args = [ + "--copy-files", + "--quiet" + ], ) ts_config( diff --git a/src/dev/bazel/jsts_transpiler.bzl b/src/dev/bazel/jsts_transpiler.bzl index 6028ec51e83c4..5116c73adb3c7 100644 --- a/src/dev/bazel/jsts_transpiler.bzl +++ b/src/dev/bazel/jsts_transpiler.bzl @@ -33,7 +33,6 @@ def jsts_transpiler(name, srcs, build_pkg_name, web = False, root_input_dir = "s "--out-dir", "$(@D)", "--no-babelrc", - "--copy-files", "--extensions", ".ts,.tsx,.js", ] + inline_presets + additional_args From e7e81199179ae324b683a364602a88baecfcad7c Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 7 Oct 2021 21:36:02 -0500 Subject: [PATCH 3/3] Update BUILD.bazel --- packages/kbn-react-page-template/BUILD.bazel | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/kbn-react-page-template/BUILD.bazel b/packages/kbn-react-page-template/BUILD.bazel index c9bc63499feff..e04911d4954db 100644 --- a/packages/kbn-react-page-template/BUILD.bazel +++ b/packages/kbn-react-page-template/BUILD.bazel @@ -55,6 +55,10 @@ jsts_transpiler( srcs = SRCS, build_pkg_name = package_name(), web = True, + additional_args = [ + "--copy-files", + "--quiet" + ], ) jsts_transpiler(