diff --git a/.gitignore b/.gitignore index 69f9a63fb916b..c0588d850062e 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,6 @@ report.asciidoc .yarn-local-mirror # Bazel -bazel -bazel-* +/bazel +/bazel-* .bazelrc.user diff --git a/packages/elastic-datemath/.babelrc b/packages/elastic-datemath/.babelrc new file mode 100644 index 0000000000000..7da72d1779128 --- /dev/null +++ b/packages/elastic-datemath/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@kbn/babel-preset/node_preset"] +} diff --git a/packages/elastic-datemath/BUILD.bazel b/packages/elastic-datemath/BUILD.bazel index 7c5bb7d07c85a..9244705c01550 100644 --- a/packages/elastic-datemath/BUILD.bazel +++ b/packages/elastic-datemath/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 = "elastic-datemath" PKG_REQUIRE_NAME = "@elastic/datemath" @@ -20,15 +21,18 @@ NPM_MODULE_EXTRA_FILES = [ "README.md", ] -SRC_DEPS = [ - "@npm//moment", -] - TYPES_DEPS = [ + "@npm//moment", "@npm//@types/node", ] -DEPS = SRC_DEPS + TYPES_DEPS +DEPS = TYPES_DEPS + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), +) ts_config( name = "tsconfig", @@ -39,14 +43,15 @@ ts_config( ) ts_project( - name = "tsc", + name = "tsc_types", args = ['--pretty'], srcs = SRCS, deps = DEPS, declaration = True, declaration_map = True, - incremental = True, - out_dir = "target", + emit_declaration_only = True, + incremental = False, + out_dir = "target_types", source_map = True, root_dir = "src", tsconfig = ":tsconfig", @@ -55,7 +60,7 @@ ts_project( js_library( name = PKG_BASE_NAME, srcs = NPM_MODULE_EXTRA_FILES, - deps = DEPS + [":tsc"], + deps = DEPS + [":target_node", ":tsc_types"], package_name = PKG_REQUIRE_NAME, visibility = ["//visibility:public"], ) diff --git a/packages/elastic-datemath/package.json b/packages/elastic-datemath/package.json index 67fbb74eb223c..b68a24d6cb7ae 100644 --- a/packages/elastic-datemath/package.json +++ b/packages/elastic-datemath/package.json @@ -3,8 +3,8 @@ "version": "5.0.3", "description": "elasticsearch datemath parser, used in kibana", "license": "Apache-2.0", - "main": "./target/index.js", - "types": "./target/index.d.ts", + "main": "./target_node/index.js", + "types": "./target_types/index.d.ts", "peerDependencies": { "moment": "^2.24.0" } diff --git a/packages/elastic-datemath/tsconfig.json b/packages/elastic-datemath/tsconfig.json index 6e7219c7a8245..dcfadbb7cf262 100644 --- a/packages/elastic-datemath/tsconfig.json +++ b/packages/elastic-datemath/tsconfig.json @@ -3,8 +3,9 @@ "compilerOptions": { "declaration": true, "declarationMap": true, - "incremental": true, - "outDir": "target", + "emitDeclarationOnly": true, + "incremental": false, + "outDir": "target_types", "rootDir": "src", "sourceMap": true, "sourceRoot": "../../../../packages/elastic-datemath/src", diff --git a/src/dev/bazel/BUILD.bazel b/src/dev/bazel/BUILD.bazel new file mode 100644 index 0000000000000..ffd0fb0cdc5bc --- /dev/null +++ b/src/dev/bazel/BUILD.bazel @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) diff --git a/src/dev/bazel/index.bzl b/src/dev/bazel/index.bzl new file mode 100644 index 0000000000000..e38d3d78c0071 --- /dev/null +++ b/src/dev/bazel/index.bzl @@ -0,0 +1,15 @@ +# +# 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. +# + +"""Public API interface for Bazel custom rules. +Please do not import from any other files when looking to use a custom rule +""" + +load("//src/dev/bazel:jsts_transpiler.bzl", _jsts_transpiler = "jsts_transpiler") + +jsts_transpiler = _jsts_transpiler diff --git a/src/dev/bazel/jsts_transpiler.bzl b/src/dev/bazel/jsts_transpiler.bzl new file mode 100644 index 0000000000000..03033bbfa83f8 --- /dev/null +++ b/src/dev/bazel/jsts_transpiler.bzl @@ -0,0 +1,36 @@ +"Simple wrapper over @babel/cli so we can quickly re-use the same configurations over packages" + +load("@npm//@babel/cli:index.bzl", _babel = "babel") + +def jsts_transpiler(name, srcs, build_pkg_name, root_input_dir = "src", config_file = ".babelrc", additional_args = ["--quiet"], **kwargs): + """A macro around the autogenerated babel rule. + + Args: + name: target name + srcs: list of sources + root_input_dir: defines the root input dir to transpile files from, defaults to "src" + config_file: transpiler config file, it defaults to a package local .babelrc + additional_args: Any additional extra arguments, defaults to --quiet + **kwargs: the rest + """ + args = [ + "./%s/%s" % (build_pkg_name, root_input_dir), + "--config-file", + "./%s/%s" % (build_pkg_name, config_file), + "--out-dir", + "$(@D)", + "--extensions", + ".ts,.tsx,.js", + ] + additional_args + + data = [config_file] + srcs + [ + "//packages/kbn-babel-preset", + ] + + _babel( + name = name, + data = data, + output_dir = True, + args = args, + **kwargs + )