Skip to content

Commit

Permalink
bazel: generate css module typings
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide authored and jbedard committed Dec 15, 2022
1 parent 919d382 commit b3b4898
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/jetbrains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ js_library(
generate_graphql_operations(
name = "graphql_operations",
srcs = [
":graphql_operations_files",
"//client/jetbrains/webview:graphql_operations_files",
],
interface_name = "JetBrainsGraphQlOperations",
output = "src/graphql-operations.ts",
Expand Down
19 changes: 19 additions & 0 deletions client/jetbrains/webview/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//client/shared/dev:tools.bzl", "module_style_typings")
load("@aspect_rules_js//js:defs.bzl", "js_library")

module_style_typings(
name = "module_style_typings",
deps = ["//client/wildcard"],
)

js_library(
name = "graphql_operations_files",
# Keep in sync with glob in client/shared/dev/generateGraphQlOperations.js
srcs = glob(
[
"src/**/*.ts",
"src/**/*.tsx",
],
),
visibility = ["//client/jetbrains:__pkg__"],
)
6 changes: 6 additions & 0 deletions client/search-ui/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("//client/shared/dev:tools.bzl", "module_style_typings")

module_style_typings(
name = "module_style_typings",
deps = ["//client/wildcard"],
)
5 changes: 5 additions & 0 deletions client/shared/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
load("@aspect_rules_js//js:defs.bzl", "js_library", "js_run_binary")
load("//client/shared/dev:generate_schema.bzl", "generate_schema")
load("//client/shared/dev:generate_graphql_operations.bzl", "generate_graphql_operations")
load("//client/shared/dev:tools.bzl", "module_style_typings")

module_style_typings(
name = "module_style_typings",
)

generate_graphql_operations(
name = "graphql_operations",
Expand Down
43 changes: 43 additions & 0 deletions client/shared/dev/tools.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"Bazel macros for building frontend packages"

load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:typed-scss-modules/package_json.bzl", types_scss_modules_bin = "bin")

def module_style_typings(name, deps = []):
"""Generate TypeScript types for module.scss files.
Automatically globs all module.scss files in the Bazel package and
outputs equivalent .d.ts files next to the styles in the output
tree.
Args:
name: Name of the target
deps: Additional dependencies imported by any of the source style files.
These could be other .scss files or node_modules deps.
"""

srcs = native.glob([
"src/**/*.module.scss",
"webview/**/*.module.scss", # JetBrains client folder structure slightly different
])

outs = ["%s.d.ts" % src for src in srcs]

js_library(
name = "%s_sources" % name,
srcs = srcs,
)

types_scss_modules_bin.tsm(
name = name,
srcs = [":%s_sources" % name] + deps,
outs = outs,
args = [
"--logLevel",
"error",
"%s/**/*.module.scss" % native.package_name(),
"--includePaths",
"client",
"node_modules",
],
)
6 changes: 6 additions & 0 deletions client/web/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
load("//client/shared/dev:generate_graphql_operations.bzl", "generate_graphql_operations")
load("//client/shared/dev:tools.bzl", "module_style_typings")
load("@aspect_rules_js//js:defs.bzl", "js_library")

module_style_typings(
name = "module_style_typings",
deps = ["//client/wildcard"],
)

js_library(
name = "graphql_operations_files",
# Keep in sync with glob in client/shared/dev/generateGraphQlOperations.js
Expand Down
17 changes: 17 additions & 0 deletions client/wildcard/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("//client/shared/dev:tools.bzl", "module_style_typings")

module_style_typings(
name = "module_style_typings",
deps = [
":wildcard",
"//:node_modules/@reach/dialog",
"//:node_modules/@reach/tabs",
],
)

js_library(
name = "wildcard",
srcs = glob(["src/**/*.scss"]),
visibility = ["//client:__subpackages__"],
)

0 comments on commit b3b4898

Please sign in to comment.