Skip to content

Commit b40fa40

Browse files
devversionalan-agius4
authored andcommitted
build: migrate ts_json_schema rule to rules_js
Migrates to `rules_js` and simplifies! the `ts_json_schema` rule
1 parent ef70b77 commit b40fa40

File tree

2 files changed

+12
-60
lines changed

2 files changed

+12
-60
lines changed

tools/BUILD.bazel

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
load("@aspect_bazel_lib//lib/private:tar_toolchain.bzl", "tar_toolchain")
2-
load("@aspect_rules_js//js:defs.bzl", "js_binary")
32
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
4-
5-
# Copyright Google Inc. All Rights Reserved.
6-
#
7-
# Use of this source code is governed by an MIT-style license that can be
8-
# found in the LICENSE file at https://angular.dev/license
9-
# @external_begin
10-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
3+
load("//tools:defaults2.bzl", "js_binary")
114

125
package(default_visibility = ["//visibility:public"])
136

147
exports_files([
158
"package_json_release_filter.jq",
169
])
1710

18-
nodejs_binary(
11+
js_binary(
1912
name = "ng_cli_schema",
2013
data = [
2114
"ng_cli_schema_generator.js",
2215
],
2316
entry_point = "ng_cli_schema_generator.js",
2417
)
2518

26-
nodejs_binary(
19+
js_binary(
2720
name = "quicktype_runner",
2821
data = [
2922
"quicktype_runner.js",
30-
"@npm//quicktype-core",
23+
"//:node_modules/quicktype-core",
3124
],
3225
entry_point = "quicktype_runner.js",
33-
templated_args = ["--bazel_patch_module_resolver"],
3426
)
3527

3628
tar_toolchain(
@@ -62,4 +54,3 @@ js_binary(
6254
entry_point = ":copy_worker_js",
6355
fixed_args = ["--vanilla-ts"],
6456
)
65-
# @external_end

tools/ts_json_schema.bzl

+8-47
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,4 @@
1-
# Copyright Google Inc. All Rights Reserved.
2-
#
3-
# Use of this source code is governed by an MIT-style license that can be
4-
# found in the LICENSE file at https://angular.dev/license
5-
6-
def _ts_json_schema_interface_impl(ctx):
7-
args = [
8-
ctx.files.src[0].path,
9-
ctx.outputs.ts.path,
10-
]
11-
12-
ctx.actions.run(
13-
inputs = ctx.files.src + ctx.files.data,
14-
executable = ctx.executable._binary,
15-
outputs = [ctx.outputs.ts],
16-
arguments = args,
17-
)
18-
19-
return [DefaultInfo()]
20-
21-
_ts_json_schema_interface = rule(
22-
_ts_json_schema_interface_impl,
23-
attrs = {
24-
"src": attr.label(
25-
allow_files = [".json"],
26-
mandatory = True,
27-
),
28-
"out": attr.string(
29-
mandatory = True,
30-
),
31-
"data": attr.label_list(
32-
allow_files = [".json"],
33-
),
34-
"_binary": attr.label(
35-
default = Label("//tools:quicktype_runner"),
36-
executable = True,
37-
cfg = "exec",
38-
),
39-
},
40-
outputs = {
41-
"ts": "%{out}",
42-
},
43-
)
1+
load("@aspect_rules_js//js:defs.bzl", "js_run_binary")
442

453
# Generates a TS file that contains the interface for a JSON Schema file. Takes a single `src`
464
# argument as input, an optional data field for reference files, and produces a
@@ -50,9 +8,12 @@ _ts_json_schema_interface = rule(
508
def ts_json_schema(name, src, data = []):
519
out = src.replace(".json", ".ts")
5210

53-
_ts_json_schema_interface(
11+
js_run_binary(
5412
name = name + ".interface",
55-
src = src,
56-
out = out,
57-
data = data,
13+
outs = [out],
14+
srcs = [src] + data,
15+
tool = "//tools:quicktype_runner",
16+
progress_message = "Generating TS interface for %s" % src,
17+
mnemonic = "TsJsonSchema",
18+
args = ["$(rootpath %s)" % src, "$(rootpath %s)" % out],
5819
)

0 commit comments

Comments
 (0)