Dmitrii Filippov | 047240b | 2020-01-14 20:33:05 +0100 | [diff] [blame] | 1 | load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") |
David Ostrovsky | f2c9a3d | 2022-02-12 14:53:31 +0100 | [diff] [blame] | 2 | load("@npm//@bazel/concatjs:index.bzl", "ts_library") |
David Ostrovsky | 6b6dfcb | 2020-06-27 10:27:25 +0200 | [diff] [blame] | 3 | load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") |
Dmitrii Filippov | 047240b | 2020-01-14 20:33:05 +0100 | [diff] [blame] | 4 | |
| 5 | package(default_visibility = ["//visibility:public"]) |
| 6 | |
David Ostrovsky | f2c9a3d | 2022-02-12 14:53:31 +0100 | [diff] [blame] | 7 | # TODO: Would be nice to use `ts_project` from @bazel/typescript instead. |
| 8 | # We would prefer to not depend on @bazel/concatjs ... |
Dmitrii Filippov | 047240b | 2020-01-14 20:33:05 +0100 | [diff] [blame] | 9 | ts_library( |
| 10 | name = "licenses-map", |
| 11 | srcs = glob(["*.ts"]), |
| 12 | compiler = "//tools/node_tools:tsc_wrapped-bin", |
Dmitrii Filippov | 047240b | 2020-01-14 20:33:05 +0100 | [diff] [blame] | 13 | tsconfig = "tsconfig.json", |
| 14 | deps = [ |
David Ostrovsky | f2c9a3d | 2022-02-12 14:53:31 +0100 | [diff] [blame] | 15 | "@tools_npm//:node_modules", |
Dmitrii Filippov | 047240b | 2020-01-14 20:33:05 +0100 | [diff] [blame] | 16 | ], |
| 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. |
| 25 | rollup_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 Waitz | f047bbd | 2021-12-16 21:39:14 +0100 | [diff] [blame] | 31 | silent = True, |
Dmitrii Filippov | 047240b | 2020-01-14 20:33:05 +0100 | [diff] [blame] | 32 | deps = [ |
| 33 | ":licenses-map", |
| 34 | "@tools_npm//rollup", |
| 35 | "@tools_npm//rollup-plugin-node-resolve", |
| 36 | ], |
| 37 | ) |
| 38 | |
| 39 | nodejs_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. |
| 58 | genrule( |
| 59 | name = "tsconfig_editor", |
| 60 | srcs = ["tsconfig.json"], |
| 61 | outs = ["tsconfig_editor.json"], |
| 62 | cmd = "cp $< $@", |
| 63 | ) |