blob: d2de5a24c1d4bc115d0066ac1ada89c283a6d1d7 [file]
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "npm_package_bin")
load("@npm//@bazel/esbuild:index.bzl", "esbuild")
load("@npm//@bazel/typescript:index.bzl", "ts_project")
# build the Typescript to JS with ts_project
ts_project(
name = "lib",
srcs = [
"main.ts",
"name.ts",
],
tsconfig = {
"compilerOptions": {
"esModuleInterop": True,
},
},
deps = [
"@npm//chalk",
],
)
# create a single bundle of the JS sources
esbuild(
name = "bundle",
entry_point = "main.ts",
minify = True,
# setting node as the platform will default us to CJS
platform = "node",
deps = [
":lib",
],
)
# binary for running our tool
nodejs_binary(
name = "bin",
data = [
":bundle",
],
entry_point = "bundle.js",
)
# run the built tool, capturing the stdout to the text file
npm_package_bin(
name = "greeter",
stdout = "greeting.txt",
tool = ":bin",
)
# ensure our text file is what we are expecting
generated_file_test(
name = "test",
src = "greeting.golden.txt",
generated = "greeting.txt",
)