blob: 03e9c2b5eaa880b86701028c2377c2c2bdfc2cc8 [file] [log] [blame]
Dmitrii Filippov047240b2020-01-14 20:33:05 +01001load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
David Ostrovskyf2c9a3d2022-02-12 14:53:31 +01002load("@npm//@bazel/concatjs:index.bzl", "ts_library")
David Ostrovsky6b6dfcb2020-06-27 10:27:25 +02003load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
Dmitrii Filippov047240b2020-01-14 20:33:05 +01004
5package(default_visibility = ["//visibility:public"])
6
David Ostrovskyf2c9a3d2022-02-12 14:53:31 +01007# TODO: Would be nice to use `ts_project` from @bazel/typescript instead.
8# We would prefer to not depend on @bazel/concatjs ...
Dmitrii Filippov047240b2020-01-14 20:33:05 +01009ts_library(
10 name = "licenses-map",
11 srcs = glob(["*.ts"]),
12 compiler = "//tools/node_tools:tsc_wrapped-bin",
Dmitrii Filippov047240b2020-01-14 20:33:05 +010013 tsconfig = "tsconfig.json",
14 deps = [
David Ostrovskyf2c9a3d2022-02-12 14:53:31 +010015 "@tools_npm//:node_modules",
Dmitrii Filippov047240b2020-01-14 20:33:05 +010016 ],
17)
18
19# rollup_bundle - workaround for https://github.com/bazelbuild/rules_nodejs/issues/1522
20# The ts_library rule ("license-map") transpiles each .ts file to .js file.
21# The "license-map" rule includes multiple .ts files and produces multiple output files.
22# The nodejs_binary requires only one file as an entry_point. It is expected, that other
23# .js files from ts_library are also available, but because of the bug they are not available.
24# As a workaround we are using rollup_bundle to group all files together.
25rollup_bundle(
26 name = "license-map-generator-bundle",
27 config_file = "rollup.config.js",
28 entry_point = "license-map-generator.ts",
29 format = "cjs",
30 rollup_bin = "//tools/node_tools:rollup-bin",
Martin Waitzf047bbd2021-12-16 21:39:14 +010031 silent = True,
Dmitrii Filippov047240b2020-01-14 20:33:05 +010032 deps = [
33 ":licenses-map",
34 "@tools_npm//rollup",
35 "@tools_npm//rollup-plugin-node-resolve",
36 ],
37)
38
39nodejs_binary(
40 name = "license-map-generator-bin",
41 entry_point = "license-map-generator-bundle.js",
42)
43
44# (TODO)dmfilippov Find a better way to fix it (another workaround or submit a bug to
45# plugin's authors or to a ts_config rule author).
46# The following genrule is a workaround for a bazel intellij plugin's bug.
47# According to the documentation, the ts_config_rules section should be added
48# to a .bazelproject file if a project uses typescript
49# (https://ij.bazel.build/docs/dynamic-languages-typescript.html)
50# Unfortunately, this doesn't work. It seems, that the plugin expects some output from
51# the ts_config rule, but the rule doesn't produce any output.
52# To workaround the issue, the tsconfig_editor genrule was added. The genrule only copies
53# input file to the output file, but this is enough to make bazel plugins works.
54# So, if you have any problem a typescript editor (import errors, types not found, etc...) -
55# try to build this rule from the command line
56# (bazel build tools/node_tools/node_modules/licenses:tsconfig_editor) and then sync bazel project
57# in intellij.
58genrule(
59 name = "tsconfig_editor",
60 srcs = ["tsconfig.json"],
61 outs = ["tsconfig_editor.json"],
62 cmd = "cp $< $@",
63)