Skip to content
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

feat(stylus): add initial stylus rule #908

Merged
merged 7 commits into from
Jul 24, 2019
Merged

Conversation

alexeagle
Copy link
Collaborator

Thanks for suggesting this in angular/angular#19058 @glebmachine

@alexeagle
Copy link
Collaborator Author

I live-coded this, here's a recording:
https://drive.google.com/drive/folders/1I71w8JSGcZk1nUX2oXvT8NLT47Onb1t0

I'll post it more widely too

Copy link
Collaborator

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

😎

packages/stylus/index.bzl Outdated Show resolved Hide resolved
packages/stylus/BUILD.bazel Outdated Show resolved Hide resolved
@gregmagolan
Copy link
Collaborator

gregmagolan commented Jul 15, 2019

Also add stylus to .bazelignore to fix circle test job & buildkite

outputs = [css_output, map_output],
inputs = [src] + ctx.files.deps,
executable = ctx.executable._compiler,
arguments = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably we should enable compress and resolve-url.

Also, we should probably a way to pass the include

More info: http://stylus-lang.com/docs/executable.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adding a test for resolve-url shows an interesting consequence, TAL. Same problem as sourcemaps...

How would users want to use include? seems like that should just come from the path of the deps?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking more something similar to the sass_binary and how they handle Sass include paths.

They have an additional attribute for this, I also think that with this approach it might be might be more performant since imports resolutions will be limited to the fine grained include paths installed of the entire deps.

https://github.com/bazelbuild/rules_sass#implicit-output-targets

In future also, we might want to make compress and sourcemap configurable by the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Asked Jeremy, he says this attribute only exists on sass_binary for legacy reasons and it would be better not to include it for new code.

Added user-config for compress and sourcemap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the new alternative/suggested way without include paths?

As if users want to import let's say bootstrap in their scss file. They will need to do a full import without include paths?

@import '../../node_modules/bootstrap/scss/functions'

Some context angular/angular#31619 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would expect that to be written @import 'bootstrap/scss/functions' - meaning the node_modules should always be in the sass include path. I didn't check if that actually works though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Afaik preprocess include paths are empty by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah so I think we should add a test for this, and hard-code correct paths. I'm not sure users should have control over something that affects paths

Copy link
Collaborator

@alan-agius4 alan-agius4 Aug 14, 2019

Choose a reason for hiding this comment

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

Yeah some tests here are mandatory. I mean we can start with hard coded paths and evaluate the option to add paths publicly if needs be. It’s easier to add than remove.

console.error('Expected the css file to be transformed');
process.exitCode = 1;
}
if (content.match(/\r|\n/)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small nit: .test should be faster since you want a boolean check

Add the `@bazel/stylus` npm package to your `devDependencies` in `package.json`.

Your `WORKSPACE` should declare a `yarn_install` or `npm_install` rule named `npm`.
It should then install the rules found in the npm packages using the `install_bazel_dependencies' function.
Copy link
Collaborator

@alan-agius4 alan-agius4 Jul 17, 2019

Choose a reason for hiding this comment

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

There an apostrophe instead of a backtick after install_bazel_dependencies

@alexeagle
Copy link
Collaborator Author

rebased on new layout scheme for packages, PTAL

Add compress and sourcemap as user-controlled options
Address some code review comments

bzl_library(
name = "bzl",
testonly = True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: not necessary unless depending on rules_webtesting:web bzl_library target

"rootPath": "."
}
},
"scripts": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

"scripts" no longer necessary in this package.json after packages refactor

Copy link
Collaborator

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

Should have at least one nested /e2e or /examples workspace test the rule via the @bazel/stylus npm package so verify npm package works.

This ensures we'll load the version of stylus we requested, not something else the user installed
@alexeagle alexeagle merged commit e08d2b3 into bazelbuild:master Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants