Skip to content

Commit

Permalink
Wire the "--embed-sources" flag through Sass Bazel rules. (#80)
Browse files Browse the repository at this point in the history
This makes it possible to embed source file contents in source maps generated by sass_binary.
  • Loading branch information
luciemdx authored and nex3 committed Mar 12, 2019
1 parent da85749 commit 78b2de2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .bazelci/presubmit.yml
Expand Up @@ -29,4 +29,6 @@ platforms:
- "//..."
# file_test is broken on Windows, see
# https://github.com/bazelbuild/bazel/issues/6122
- "-//sass/test:hello_world_file_test"
- "-//sass/test:sourcemap_embed_sources_file_test"
- "-//sass/test:no_sourcemap_file_test"
10 changes: 10 additions & 0 deletions examples/hello_world/BUILD
Expand Up @@ -11,6 +11,16 @@ sass_binary(
],
)

sass_binary(
name = "hello_world_sourcemap_embed_sources",
src = "main.scss",
output_name = "main-sourcemap-embed-sources.css",
sourcemap_embed_sources = True,
deps = [
"//examples/shared",
],
)

sass_binary(
name = "hello_world_no_sourcemap",
src = "main.scss",
Expand Down
8 changes: 7 additions & 1 deletion sass/sass.bzl
Expand Up @@ -81,6 +81,8 @@ def _run_sass(ctx, input, css_output, map_output = None):

if not ctx.attr.sourcemap:
args.add("--no-source-map")
elif ctx.attr.sourcemap_embed_sources:
args.add("--embed-sources")

# Sources for compilation may exist in the source tree, in bazel-bin, or bazel-genfiles.
for prefix in [".", ctx.var["BINDIR"], ctx.var["GENDIR"]]:
Expand Down Expand Up @@ -177,7 +179,11 @@ _sass_binary_attrs = {
),
"sourcemap": attr.bool(
default = True,
doc = "Whether sourcemaps should be emitted.",
doc = "Whether source maps should be emitted.",
),
"sourcemap_embed_sources": attr.bool(
default = False,
doc = "Whether to embed source file contents in source maps.",
),
"include_paths": attr.string_list(
doc = "Additional directories to search when resolving imports",
Expand Down
23 changes: 23 additions & 0 deletions sass/test/sass_rule_test.bzl
Expand Up @@ -22,6 +22,29 @@ def _sass_binary_test(package):
rule = package + "/hello_world:hello_world",
)

file_test(
name = "hello_world_file_test",
file = package + "/hello_world:main.css.map",
regexp = "\"sourcesContent\":",
matches = 0,
)

rule_test(
name = "sourcemap_embed_sources_rule_test",
generates = [
"main-sourcemap-embed-sources.css",
"main-sourcemap-embed-sources.css.map",
],
rule = package + "/hello_world:hello_world_sourcemap_embed_sources",
)

file_test(
name = "sourcemap_embed_sources_file_test",
file = package + "/hello_world:main-sourcemap-embed-sources.css.map",
regexp = "\"sourcesContent\":",
matches = 1,
)

rule_test(
name = "no_sourcemap_rule_test",
generates = ["main-no-sourcemap.css"],
Expand Down

0 comments on commit 78b2de2

Please sign in to comment.