Skip to content

Commit 27b6033

Browse files
committed
feat: generate angular-ngc sass_binary targets with aspect configure plugin
1 parent bd7ca5c commit 27b6033

File tree

7 files changed

+59
-8
lines changed

7 files changed

+59
-8
lines changed

angular-ngc/.aspect/cli/config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
configure:
2+
languages:
3+
javascript: true
4+
plugins:
5+
- .aspect/cli/postcss.star

angular-ngc/.aspect/cli/postcss.star

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
aspect.register_rule_kind("sass_binary", {
2+
"From": "//tools:sass.bzl",
3+
"MergeableAttrs": ["srcs"],
4+
"ResolveAttrs": ["deps"],
5+
})
6+
7+
def declare_postcss(ctx):
8+
if len(ctx.sources) == 0:
9+
ctx.targets.remove("css")
10+
return
11+
12+
imports = []
13+
for file in ctx.sources:
14+
imports.extend([
15+
aspect.Import(
16+
id = i.captures["import"],
17+
provider = "js",
18+
src = file.path,
19+
)
20+
for i in file.query_results["imports"]
21+
])
22+
23+
ctx.targets.add(
24+
name = "css",
25+
kind = "sass_binary",
26+
attrs = {
27+
"srcs": [src.path for src in ctx.sources],
28+
"deps": imports,
29+
},
30+
)
31+
32+
aspect.register_configure_extension(
33+
id = "postcss",
34+
prepare = lambda _: aspect.PrepareResult(
35+
sources = [
36+
aspect.SourceExtensions(".scss"),
37+
],
38+
queries = {
39+
"imports": aspect.RegexQuery(
40+
filter = "**/*.scss",
41+
expression = """@use\\s+['"](?P<import>[^'"]+)['"]""",
42+
),
43+
},
44+
),
45+
declare = declare_postcss,
46+
)

angular-ngc/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
22
load("@npm//:defs.bzl", "npm_link_all_packages")
33

4+
# aspect:js disabled
5+
# aspect:generation_mode update
6+
47
# Link npm packages
58
npm_link_all_packages(name = "node_modules")
69

angular-ngc/applications/demo/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
21
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
2+
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
33
load("@npm//:defs.bzl", "npm_link_all_packages")
44
load("//:defs.bzl", "ng_application")
55

angular-ngc/applications/grpc/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
21
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
2+
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
33
load("@npm//:defs.bzl", "npm_link_all_packages")
44
load("//:defs.bzl", "ng_application")
55

angular-ngc/packages/connect/src/proto/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_proto//proto:defs.bzl", "proto_library")
21
load("@aspect_rules_ts//ts:proto.bzl", "ts_proto_library")
2+
load("@rules_proto//proto:defs.bzl", "proto_library")
33

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

angular-ngc/packages/lib-a/BUILD.bazel

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ npm_link_all_packages(name = "node_modules")
88

99
sass_binary(
1010
name = "css",
11-
srcs = glob(["src/**/*.scss"]),
12-
deps = [
13-
"//:node_modules/@angular/cdk",
14-
"//:node_modules/@angular/material",
15-
],
11+
srcs = ["src/lib/lib-a.component.scss"],
12+
deps = ["//:node_modules/@angular/material"],
1613
)
1714

1815
ng_pkg(

0 commit comments

Comments
 (0)