Skip to content

build: create sass_bundle bazel rule #10055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2018

Conversation

jelbourn
Copy link
Member

This defines a bazel rule to bundle sass partials into a single file
using the "sass-bundle" npm package. The rule definition is commented so
that it can serve as an example for creating other rules in the future.

I've also added the missing build file for badge so that its theme can
be included in the bundle.

I probably should have split this up into three PRs but, well, here we are.

cc fyi @devversion

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 21, 2018

sass_bundle(
name = "theming_bundle",
srcs = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introduce a constant in the top-level BUILD file?

ALL_LIBS=["autocomplete", "badge]
then here it's just
srcs = ["//src/lib/%s:%s_scss_partials" % l for l in ALL_LIBS]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a .bzl file at the top-level with a constant for this. I didn't think it was possible to import a constant from another BUILD file. Am I missing something?

@@ -21,6 +21,11 @@ ng_module(
tsconfig = ":tsconfig-build.json",
)

# TODO(jelbourn): replace this w/ sass_library when it supports acting like a filegroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could make a simple PR to rules_sass to get this process started, at least test the waters to see if anyone is maintaining it, if they offer to hand over the keys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it to my general "Making sass better" task list

@@ -0,0 +1,22 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to hook up skylint to tell you about unused imports and such

and buildifier too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tasks I have tracked in #8369

const parsedArgs: {srcs: string, output: string, entry: string} = minimist(args);
const inputFiles = parsedArgs.srcs.split(',');

return new Bundler().Bundle(join(workspaceRoot, parsedArgs.entry), inputFiles).then(result => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you determine if the CLI in scss-bundle is not suitable? if so, comment why in the fileoverview here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get the nodejs_binary to work with the package's existing CLI and it was less work to keep this. It's also easier to debug the calls from bazel this way. Added a comment.

@@ -0,0 +1,29 @@
import {dirname, join} from 'path';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you need license headers in this repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I knew we only needed license headers for code synced into google.

# rule (and will thus be available to the nodejs_binary in the sandbox).
"entry_point": attr.label(mandatory = True, allow_single_file = True),

# The executable (bundler) for this rule. The user will typically never
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you start with underscore, users won't be able to set it - I'd recommend keeping as much API private as possible until you understand why someone wants to set this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. (I didn't know you could do that)

@@ -0,0 +1,8 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sadness, why another tsconfig file? the editor won't know about these settings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default bazel one doesn't have types: node and lib: es2015. I removed the other two options.

@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should give you a warning (if your rules_typescript is recent)
--module is controlled by Bazel

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@jelbourn jelbourn mentioned this pull request Feb 21, 2018
17 tasks
@@ -22,6 +17,17 @@ ng_module(
tsconfig = ":tsconfig-build.json",
)

# TODO(jelbourn): remove this when sass_library acts like a filegroup
filegroup(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we're in the business of making our own bazel rules, should we just replace these two rules with something like material_sass_library? or maybe go even further and extract all of the rules shared by every component into some sort of material_module rule?

material_module(
  name = "button",
  module_name = "@angular/material/button",
  srcs = [...],
  deps = [...],
  scss = [...],
  theme_scss = [...],
  templates = [...]
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning on putting some time into either fixing or replacing the open source sass rules so that they match the ones in Google. These don't change often, so it shouldn't hurt our productivity to leave it until we can get the ecosystem sorted out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we should try to make the primitives work instead of wrapping them in macros, which are leaky abstractions.

BUILD.bazel Outdated
@@ -46,6 +46,43 @@ ANGULAR_TESTING = [
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
]

MATERIAL_COMPONENTS = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove this copy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

This defines a bazel rule to bundle sass partials into a single file
using the "scss-bundle" npm package. The rule definition is commented so
that it can serve as an example for creating other rules in the future.

I've also added the missing build file for badge so that its theme can
be included in the bundle.
@jelbourn jelbourn force-pushed the bazel-sass-bundler branch from 3264ce9 to f06c51c Compare March 12, 2018 17:07
@jelbourn jelbourn force-pushed the bazel-sass-bundler branch from f06c51c to f20aa37 Compare March 12, 2018 17:11
@jelbourn jelbourn merged commit fcc0908 into angular:master Mar 12, 2018
@jelbourn jelbourn deleted the bazel-sass-bundler branch April 2, 2018 22:31
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants