I want to pile some Typescript files and create a Node.js Image from the piled Javascript files. It works fine when I have only one Typescript file with this BUILD
file:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "pile",
srcs = ["src/index.ts"],
)
filegroup(
name = "files",
srcs = ["pile"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
entry_point = "files",
)
But as soon as I introduce multiple Typescript files like this:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "pile",
srcs = ["src/index.ts", "src/util.ts"],
)
filegroup(
name = "files",
srcs = ["pile"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
data = ["files"],
entry_point = "files/src/index.js",
)
Bazel doesn't find the entrypoint file:
ERROR: missing input file '//server:files/src/index.js'
ERROR: /home/flo/Desktop/my-own-minimal-bazel/server/BUILD:15:1: //server:server: missing input file '//server:files/src/index.js'
Target //server:server failed to build
Use --verbose_failures to see the mand lines of failed build steps.
ERROR: /home/flo/Desktop/my-own-minimal-bazel/server/BUILD:15:1 1 input file(s) do not exist
I want to pile some Typescript files and create a Node.js Image from the piled Javascript files. It works fine when I have only one Typescript file with this BUILD
file:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "pile",
srcs = ["src/index.ts"],
)
filegroup(
name = "files",
srcs = ["pile"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
entry_point = "files",
)
But as soon as I introduce multiple Typescript files like this:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "pile",
srcs = ["src/index.ts", "src/util.ts"],
)
filegroup(
name = "files",
srcs = ["pile"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
data = ["files"],
entry_point = "files/src/index.js",
)
Bazel doesn't find the entrypoint file:
ERROR: missing input file '//server:files/src/index.js'
ERROR: /home/flo/Desktop/my-own-minimal-bazel/server/BUILD:15:1: //server:server: missing input file '//server:files/src/index.js'
Target //server:server failed to build
Use --verbose_failures to see the mand lines of failed build steps.
ERROR: /home/flo/Desktop/my-own-minimal-bazel/server/BUILD:15:1 1 input file(s) do not exist
Share
Improve this question
edited Dec 8, 2019 at 13:33
Florian Ludewig
asked Dec 8, 2019 at 9:16
Florian LudewigFlorian Ludewig
6,04216 gold badges83 silver badges157 bronze badges
3 Answers
Reset to default 6 +100I can only get the repo to build if I break up the ts_library into two seperate ts_libs, one for the library, and one for the index.ts:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = [
"util.ts",
],
)
ts_library(
name = "main",
srcs = [
"index.ts",
],
deps = [":lib"],
)
filegroup(
name = "libfiles",
srcs = ["lib"],
output_group = "es5_sources",
)
filegroup(
name = "mainfile",
srcs = ["main"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
data = [
":libfiles",
":mainfile",
],
entry_point = ":mainfile",
)
The above code is in a pull request to your repo. I'm not sure why you are unable to reference a single file of the filegroup!
(Blind fix, I cannot try it now.)
I believe you need to use entry_point = "src/index.js",
because files
is just the name of the filegroup, it's not part of the paths.
Either that, or entry_point = "server/src/index.js",
in case nodejs_image
expects a package-root-relative path.
You should be able to fix this with the $(location LABEL)
make variable pointed at the output file by name, src/index.js
:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "pile",
srcs = ["src/index.ts", "src/util.ts"],
)
filegroup(
name = "files",
srcs = ["pile"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
data = ["files"],
entry_point = "$(location src/index.js)",
)
Note the entry_point
is set to "$(location src/index.js)"
- this locates the output file by relative path, relative to the BUILD file, that the files
filegroup has collected.