Skip to content

Commit

Permalink
chore(NA): moving @elastic/datemath to babel transpiler (#106860) (#1…
Browse files Browse the repository at this point in the history
…06921)

* chore(NA): first custom rules for jsts_transpiler

* chore(NA): update jsts_transpiler macro

* chore(NA): moving @elastic/datemath to babel transpiler

* chore(NA): change gitignore rules for bazel

Co-authored-by: Tiago Costa <[email protected]>
  • Loading branch information
kibanamachine and mistic authored Jul 27, 2021
1 parent cfa379f commit 69d0a7a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ report.asciidoc
.yarn-local-mirror

# Bazel
bazel
bazel-*
/bazel
/bazel-*
.bazelrc.user
3 changes: 3 additions & 0 deletions packages/elastic-datemath/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@kbn/babel-preset/node_preset"]
}
23 changes: 14 additions & 9 deletions packages/elastic-datemath/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"],
)
Expand Down
4 changes: 2 additions & 2 deletions packages/elastic-datemath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/elastic-datemath/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/dev/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
15 changes: 15 additions & 0 deletions src/dev/bazel/index.bzl
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions src/dev/bazel/jsts_transpiler.bzl
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 69d0a7a

Please sign in to comment.