Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ use_repo(playwright, "playwright_browsers")
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "22.11.0") # LTS 'Jod'

# Pin pnpm v9 to match the lockfile format (rules_js 2.9.2 defaults to pnpm v8
# which cannot read lockfileVersion 9 and triggers a non-hermetic regeneration).
pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm", dev_dependency = True)
pnpm.pnpm(
pnpm_version = "9.15.9",
pnpm_version_integrity = "sha512-aARhQYk8ZvrQHAeSMRKOmvuJ74fiaR1p5NQO7iKJiClf1GghgbrlW1hBjDolO95lpQXsfF+UA+zlzDzTfc8lMQ==",
)
use_repo(pnpm, "pnpm")

# Workspace-level npm packages (pnpm workspace)
# All JS/TS projects share a single lockfile and node_modules
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
Expand Down Expand Up @@ -207,6 +216,7 @@ npm.npm_translate_lock(
},
# Auto-regenerate pnpm-lock.yaml when package.json changes
update_pnpm_lock = True,
use_pnpm = "@pnpm//:package/bin/pnpm.cjs",
)
use_repo(npm, "npm_ducktape")

Expand Down
8 changes: 0 additions & 8 deletions props/backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ py_binary(
deps = [":export_schema"],
)

genrule(
name = "openapi_schema",
outs = ["openapi.json"],
cmd = "$(location :export_schema_bin) > $@",
tools = [":export_schema_bin"],
visibility = ["//props/frontend:__pkg__"],
)

# =============================================================================
# Linting
# =============================================================================
Expand Down
23 changes: 0 additions & 23 deletions props/frontend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,6 @@ js_binary(
no_copy_to_bin = ["//props/backend:backend_cli"],
)

# ============================================================
# OpenAPI TypeScript schema generation (binary + input only;
# the js_run_binary lives in //props/frontend/src/lib)
# ============================================================

js_binary(
name = "generate_schema_bin",
data = [
"generate-schema.mjs",
":node_modules",
],
entry_point = "generate-schema.mjs",
visibility = ["//props/frontend/src/lib:__pkg__"],
)

genrule(
name = "openapi_schema_local",
srcs = ["//props/backend:openapi_schema"],
outs = ["openapi.json"],
cmd = "cp $< $@",
visibility = ["//props/frontend/src/lib:__pkg__"],
)

# ============================================================
# Production bundle
# ============================================================
Expand Down
37 changes: 0 additions & 37 deletions props/frontend/generate-schema.mjs

This file was deleted.

21 changes: 4 additions & 17 deletions props/frontend/src/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
load("@aspect_rules_js//js:defs.bzl", "js_library", "js_run_binary")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("//tools/js:openapi.bzl", "js_openapi_schema")

package(default_visibility = [
"//props/frontend:__pkg__",
"//props/frontend:__subpackages__",
])

# OpenAPI TypeScript schema generation
js_run_binary(
name = "_generate_schema_run",
srcs = ["//props/frontend:openapi_schema_local"],
outs = ["api/schema.d.ts"],
args = [
"openapi.json",
"src/lib/api/schema.d.ts",
],
chdir = "props/frontend",
tool = "//props/frontend:generate_schema_bin",
)

js_library(
js_openapi_schema(
name = "schema",
srcs = [":_generate_schema_run"],
tags = ["no-lint"],
generator = "//props/backend:export_schema_bin",
)

# Standalone utilities (no local deps)
Expand Down
1 change: 1 addition & 0 deletions tools/js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Shared JavaScript/TypeScript Bazel macros.
60 changes: 60 additions & 0 deletions tools/js/openapi.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Macro: js_openapi_schema — generate TypeScript types from an OpenAPI-emitting binary."""

load("@aspect_rules_js//js:defs.bzl", "js_library", "js_run_binary")
load("@npm_ducktape//:openapi-typescript/package_json.bzl", openapi_ts_bin = "bin")

def js_openapi_schema(name, generator, out = "api/schema.d.ts", visibility = None):
"""Generate a js_library with TypeScript type definitions from an OpenAPI schema.

Runs *generator* (a binary that prints an OpenAPI JSON schema to stdout),
then pipes the result through openapi-typescript to produce a ``.d.ts``
file, and wraps that in a ``js_library`` target.

Private intermediate targets are prefixed with ``_<name>_`` to avoid
collisions when the macro is called more than once in a package.

Args:
name: Name of the output ``js_library`` target.
generator: Label of the executable that writes OpenAPI JSON to stdout.
out: Package-relative path for the generated ``.d.ts`` file.
Defaults to ``api/schema.d.ts``.
visibility: Visibility of the output ``js_library``.

Example:
js_openapi_schema(
name = "schema",
generator = "//my/backend:export_schema_bin",
)
"""
json_out = "_" + name + "_openapi.json"

openapi_ts_bin.openapi_typescript_binary(
name = "_" + name + "_openapi_ts_bin",
)

native.genrule(
name = "_" + name + "_openapi_json",
outs = [json_out],
cmd = "$(location {}) > $@".format(generator),
tools = [generator],
)

js_run_binary(
name = "_" + name + "_generate",
srcs = [":_" + name + "_openapi_json"],
outs = [out],
args = [
json_out,
"-o",
out,
],
chdir = native.package_name(),
tool = ":_" + name + "_openapi_ts_bin",
)

js_library(
name = name,
srcs = [":_" + name + "_generate"],
tags = ["no-lint"],
visibility = visibility,
)
Loading