Skip to content

Commit 1d77a3b

Browse files
committed
feat: show a sass import
Works around sass/dart-sass#1765 so that the npmjs.com/sass package can run under hoist=false.
1 parent 4a1489e commit 1d77a3b

File tree

9 files changed

+1455
-618
lines changed

9 files changed

+1455
-618
lines changed

angular-ngc/WORKSPACE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ nodejs_register_toolchains(
3636
)
3737

3838
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
39+
load("//tools:sass_workaround.bzl", "SASS_DEPS")
3940

4041
npm_translate_lock(
4142
name = "npm",
@@ -47,6 +48,9 @@ npm_translate_lock(
4748
custom_postinstalls = {
4849
"ng2-dragula": "ngcc --source .",
4950
},
51+
# Workaround https://github.com/sass/dart-sass/issues/1765
52+
# See comments in sass_workaround.bzl
53+
public_hoist_packages = {p: ["packages/lib-a"] for p in SASS_DEPS},
5054
npmrc = "//:.npmrc",
5155
pnpm_lock = "//:pnpm-lock.yaml",
5256
verify_node_modules_ignored = "//:.bazelignore",

angular-ngc/defs.bzl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ load("@npm//:html-insert-assets/package_json.bzl", html_insert_assets_bin = "bin
77
load("@npm//:karma/package_json.bzl", _karma_bin = "bin")
88
load("//tools:ng.bzl", "ng_esbuild", "ng_project")
99
load("//tools:ts.bzl", "ts_project")
10-
load("//tools:sass.bzl", "sass")
1110
load("//tools:karma.bzl", "generate_karma_config", "generate_test_bootstrap", "generate_test_setup")
1211

1312
# Common dependencies of Angular applications
@@ -224,7 +223,7 @@ def _pkg_web(name, entry_point, entry_deps, html_assets, assets, production, vis
224223
visibility = visibility,
225224
)
226225

227-
def ng_pkg(name, deps = [], test_deps = [], visibility = ["//visibility:public"]):
226+
def ng_pkg(name, srcs, deps = [], test_deps = [], visibility = ["//visibility:public"]):
228227
"""
229228
Bazel macro for compiling an npm-like Angular package project. Creates '{name}' and 'test' targets.
230229
@@ -239,27 +238,14 @@ def ng_pkg(name, deps = [], test_deps = [], visibility = ["//visibility:public"]
239238
240239
Args:
241240
name: the rule name
241+
srcs: source files
242242
deps: package dependencies
243243
test_deps: additional dependencies for tests
244244
visibility: visibility of the primary targets ('{name}', 'test')
245245
"""
246246

247247
test_spec_srcs = native.glob(["src/**/*.spec.ts"])
248248

249-
srcs = native.glob(
250-
["src/**/*.ts", "src/**/*.css", "src/**/*.html"],
251-
exclude = test_spec_srcs,
252-
)
253-
254-
sass_srcs = native.glob(["src/**/*.scss"])
255-
if len(sass_srcs) > 0:
256-
sass(
257-
name = "_sass",
258-
srcs = sass_srcs,
259-
visibility = ["//visibility:private"],
260-
)
261-
srcs = srcs + [":_sass"]
262-
263249
# An index file to allow direct imports of the directory similar to a package.json "main"
264250
write_file(
265251
name = "_index",

angular-ngc/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"type": "module",
66
"dependencies": {
77
"@angular/animations": "15.0.1",
8+
"@angular/cdk": "15.0.1",
89
"@angular/common": "15.0.1",
910
"@angular/core": "15.0.1",
1011
"@angular/forms": "15.0.1",
12+
"@angular/material": "15.0.1",
1113
"@angular/platform-browser": "15.0.1",
1214
"@angular/platform-browser-dynamic": "15.0.1",
1315
"@angular/router": "15.0.1",

angular-ngc/packages/common/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ npm_link_all_packages(name = "node_modules")
77

88
ng_pkg(
99
name = "common",
10+
srcs = [
11+
"src/lib/common.component.ts",
12+
"src/lib/common.module.ts",
13+
"src/public-api.ts",
14+
],
1015
)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
load("@npm//:defs.bzl", "npm_link_all_packages")
22
load("//:defs.bzl", "ng_pkg")
3+
load("//tools:sass.bzl", "sass_binary")
34

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

67
npm_link_all_packages(name = "node_modules")
78

9+
sass_binary(
10+
name = "css",
11+
srcs = glob(["src/**/*.scss"]),
12+
deps = [
13+
"//:node_modules/@angular/cdk",
14+
"//:node_modules/@angular/material",
15+
],
16+
)
17+
818
ng_pkg(
919
name = "lib-a",
20+
srcs = [
21+
"src/lib/lib-a.component.css",
22+
"src/lib/lib-a.component.ts",
23+
"src/lib/lib-a.module.ts",
24+
"src/public-api.ts",
25+
],
1026
deps = [
1127
":node_modules/@ngc-example/common",
1228
"//packages/lib-a/src/lib/strings",

angular-ngc/packages/lib-a/src/lib/lib-a.component.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Unused import, just to test that sass can correctly resolve it.
2+
@use '@angular/material' as mat;
3+
14
$color: red;
25

36
:host {

0 commit comments

Comments
 (0)