Skip to content

Commit

Permalink
feat: generate angular-ngc sass_binary targets with aspect configure …
Browse files Browse the repository at this point in the history
…plugin (#413)

* chore: upgrade aspect-cli to 2025.08.18

* feat: generate angular-ngc sass_binary targets with aspect configure plugin
  • Loading branch information
jbedard authored Mar 5, 2025
1 parent de67129 commit 6138308
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BAZELISK_BASE_URL=https://static.aspect.build/aspect
USE_BAZEL_VERSION=aspect/2024.51.11
USE_BAZEL_VERSION=aspect/2025.08.18

# Aspect CLI (aspect) is wrapper for Bazel, built on top of Bazelisk, that adds
# additional features and extensibility to the popular polyglot build system from Google.
Expand Down
5 changes: 5 additions & 0 deletions angular-ngc/.aspect/cli/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
configure:
languages:
javascript: true
plugins:
- .aspect/cli/postcss.star
46 changes: 46 additions & 0 deletions angular-ngc/.aspect/cli/postcss.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
aspect.register_rule_kind("sass_binary", {
"From": "//tools:sass.bzl",
"MergeableAttrs": ["srcs"],
"ResolveAttrs": ["deps"],
})

def declare_postcss(ctx):
if len(ctx.sources) == 0:
ctx.targets.remove("css")
return

imports = []
for file in ctx.sources:
imports.extend([
aspect.Import(
id = i.captures["import"],
provider = "js",
src = file.path,
)
for i in file.query_results["imports"]
])

ctx.targets.add(
name = "css",
kind = "sass_binary",
attrs = {
"srcs": [src.path for src in ctx.sources],
"deps": imports,
},
)

aspect.register_configure_extension(
id = "postcss",
prepare = lambda _: aspect.PrepareResult(
sources = [
aspect.SourceExtensions(".scss"),
],
queries = {
"imports": aspect.RegexQuery(
filter = "**/*.scss",
expression = """@use\\s+['"](?P<import>[^'"]+)['"]""",
),
},
),
declare = declare_postcss,
)
3 changes: 3 additions & 0 deletions angular-ngc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@npm//:defs.bzl", "npm_link_all_packages")

# aspect:js disabled
# aspect:generation_mode update

# Link npm packages
npm_link_all_packages(name = "node_modules")

Expand Down
2 changes: 1 addition & 1 deletion angular-ngc/applications/demo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//:defs.bzl", "ng_application")

Expand Down
2 changes: 1 addition & 1 deletion angular-ngc/applications/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//:defs.bzl", "ng_application")

Expand Down
2 changes: 1 addition & 1 deletion angular-ngc/packages/connect/src/proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@aspect_rules_ts//ts:proto.bzl", "ts_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

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

Expand Down
7 changes: 2 additions & 5 deletions angular-ngc/packages/lib-a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ npm_link_all_packages(name = "node_modules")

sass_binary(
name = "css",
srcs = glob(["src/**/*.scss"]),
deps = [
"//:node_modules/@angular/cdk",
"//:node_modules/@angular/material",
],
srcs = ["src/lib/lib-a.component.scss"],
deps = ["//:node_modules/@angular/material"],
)

ng_pkg(
Expand Down

0 comments on commit 6138308

Please sign in to comment.