From d459b33bed3b923bea11ca81a21fe8e8bf5f6a73 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 19 Aug 2021 19:31:31 -0400 Subject: [PATCH] chore(NA): moving @kbn/optimizer to babel transpiler (#109231) (#109315) * chore(NA): adds 7.16 into backportrc * chore(NA): moving @kbn/optimizer to babel transpiler Co-authored-by: Tiago Costa --- packages/kbn-optimizer/.babelrc | 4 +++ packages/kbn-optimizer/BUILD.bazel | 34 +++++++++++++++---- packages/kbn-optimizer/babel.config.js | 12 ------- packages/kbn-optimizer/package.json | 4 +-- packages/kbn-optimizer/tsconfig.json | 3 +- .../kbn-test/src/jest/setup/babel_polyfill.js | 2 +- 6 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 packages/kbn-optimizer/.babelrc delete mode 100644 packages/kbn-optimizer/babel.config.js diff --git a/packages/kbn-optimizer/.babelrc b/packages/kbn-optimizer/.babelrc new file mode 100644 index 0000000000000..1685d1644d94a --- /dev/null +++ b/packages/kbn-optimizer/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["@kbn/babel-preset/node_preset"], + "ignore": ["**/*.test.js"] +} diff --git a/packages/kbn-optimizer/BUILD.bazel b/packages/kbn-optimizer/BUILD.bazel index ddf2a05519682..7f04aa4b262b0 100644 --- a/packages/kbn-optimizer/BUILD.bazel +++ b/packages/kbn-optimizer/BUILD.bazel @@ -1,5 +1,6 @@ load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project") load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm") +load("//src/dev/bazel:index.bzl", "jsts_transpiler") PKG_BASE_NAME = "kbn-optimizer" PKG_REQUIRE_NAME = "@kbn/optimizer" @@ -29,7 +30,7 @@ NPM_MODULE_EXTRA_FILES = [ "README.md" ] -SRC_DEPS = [ +RUNTIME_DEPS = [ "//packages/kbn-config", "//packages/kbn-dev-utils", "//packages/kbn-std", @@ -59,6 +60,22 @@ SRC_DEPS = [ ] TYPES_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//cpy", + "@npm//del", + "@npm//execa", + "@npm//jest-diff", + "@npm//lmdb-store", + "@npm//pirates", + "@npm//resize-observer-polyfill", + "@npm//rxjs", + "@npm//zlib", "@npm//@types/compression-webpack-plugin", "@npm//@types/jest", "@npm//@types/json-stable-stringify", @@ -72,7 +89,11 @@ TYPES_DEPS = [ "@npm//@types/webpack-sources", ] -DEPS = SRC_DEPS + TYPES_DEPS +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), +) ts_config( name = "tsconfig", @@ -84,13 +105,14 @@ ts_config( ) ts_project( - name = "tsc", + name = "tsc_types", args = ['--pretty'], srcs = SRCS, - deps = DEPS, + deps = TYPES_DEPS, declaration = True, declaration_map = True, - out_dir = "target", + emit_declaration_only = True, + out_dir = "target_types", source_map = True, root_dir = "src", tsconfig = ":tsconfig", @@ -99,7 +121,7 @@ ts_project( js_library( name = PKG_BASE_NAME, srcs = NPM_MODULE_EXTRA_FILES, - deps = DEPS + [":tsc"], + deps = RUNTIME_DEPS + [":target_node", ":tsc_types"], package_name = PKG_REQUIRE_NAME, visibility = ["//visibility:public"], ) diff --git a/packages/kbn-optimizer/babel.config.js b/packages/kbn-optimizer/babel.config.js deleted file mode 100644 index e3a412717fb6e..0000000000000 --- a/packages/kbn-optimizer/babel.config.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - * 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. - */ - -module.exports = { - presets: ['@kbn/babel-preset/node_preset'], - ignore: ['**/*.test.js'], -}; diff --git a/packages/kbn-optimizer/package.json b/packages/kbn-optimizer/package.json index d23512f7c418d..488e1b5dbfde8 100644 --- a/packages/kbn-optimizer/package.json +++ b/packages/kbn-optimizer/package.json @@ -3,6 +3,6 @@ "version": "1.0.0", "private": true, "license": "SSPL-1.0 OR Elastic License 2.0", - "main": "./target/index.js", - "types": "./target/index.d.ts" + "main": "./target_node/index.js", + "types": "./target_types/index.d.ts" } \ No newline at end of file diff --git a/packages/kbn-optimizer/tsconfig.json b/packages/kbn-optimizer/tsconfig.json index 047c98db8a806..5fbd02106e777 100644 --- a/packages/kbn-optimizer/tsconfig.json +++ b/packages/kbn-optimizer/tsconfig.json @@ -1,9 +1,10 @@ { "extends": "../../tsconfig.bazel.json", "compilerOptions": { - "outDir": "./target/types", "declaration": true, "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "./target_types", "rootDir": "./src", "sourceMap": true, "sourceRoot": "../../../../packages/kbn-optimizer/src", diff --git a/packages/kbn-test/src/jest/setup/babel_polyfill.js b/packages/kbn-test/src/jest/setup/babel_polyfill.js index 7dda4cceec65c..7981eb668f38f 100644 --- a/packages/kbn-test/src/jest/setup/babel_polyfill.js +++ b/packages/kbn-test/src/jest/setup/babel_polyfill.js @@ -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/target/node/polyfill'; +import '@kbn/optimizer/target_node/node/polyfill';