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

Add npm_package_bin rule #1139

Merged
merged 1 commit into from
Sep 19, 2019
Merged

Add npm_package_bin rule #1139

merged 1 commit into from
Sep 19, 2019

Conversation

alexeagle
Copy link
Collaborator

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@buildsize
Copy link

buildsize bot commented Sep 16, 2019

File name Previous Size New Size Change
release.tar.gz 1.03 MB 1.03 MB 1.39 KB (0%)

@alexeagle alexeagle force-pushed the npm_bin branch 4 times, most recently from aae863c to ee158b9 Compare September 19, 2019 01:49
@alexeagle alexeagle marked this pull request as ready for review September 19, 2019 01:51
@alexeagle alexeagle changed the title Npm bin Add npm_package_bin rule Sep 19, 2019
"test.styl",
"--out",
# Output paths must use $(location) since Bazel puts them in a platform-dependent output directory
"$(location test.css)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a user, can I use a relative path here such as ../test.css? Not that it makes sense in this example but in general is that possible?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You linked the docs which answers the question :) https://docs.bazel.build/versions/master/be/general.html#genrule.srcs

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, this will be tough for users I think, because if you just write "test.css" it will write to the input folder. if you're lucky you get an error about that folder being readonly in the sandbox, more likely it writes it and you get an error that bazel says the declared output wasn't produced.
But this is standard genrule behavior so not strictly our job to improve that?

fail("You must supply either the tool or package attribute")
if not package_bin:
package_bin = package
tool = "@npm//%s/bin:%s" % (package, package_bin)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like this could allow a bit more flexibility by allow user to override the @npm workspace without specifying the whole tool? But maybe having the tool override is sufficient

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm, we could easily have another attribute for the package workspace. but that does make the API surface of this rule bigger just to preserve some syntax sugar, which seems probably wrong to me.


# Generated helper macro to call ${name}
def ${name}(**kwargs):
npm_package_bin(package = "${pkg._dir}", package_bin = "${name}", **kwargs)
Copy link
Collaborator

@gregmagolan gregmagolan Sep 19, 2019

Choose a reason for hiding this comment

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

I think set the specific tool here instead of package and package_bin as the @npm workspace may not be @npm for this npm_install/yarn_install

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes good call

@@ -33,6 +33,8 @@ npm_package(
srcs = [
"@npm_bazel_less//:package_contents",
],
# less package is deprecated
tags = ["do-not-publish"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update release script to key off of this tag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it already does, that's how we avoided publishing @bazel/rollup and @bazel/terser to this point.

@gregmagolan
Copy link
Collaborator

gregmagolan commented Sep 19, 2019

This is really nice and clean. Nice work! Naming makes sense to me.

I think another PR we can have inform npm_install & yarn_install via the @bazel/typescript package.json how to add a ts_library macro to index.bzl with the appropriate @npm_wrksp override as discussed here: #1149 (comment). Ultimately it would be really nice if users can load all npm delivered bazel rules from @npm//@bazel/bar:index.bzl or @npm//fum:index.bzl.

This is a genrule-like rule that runs any npm bin
We generate one of these in the @npm workspace

illustrate its usage by replacing stylus and less rules

Those rules are now deprecated, will be deprecated on npm, and their
sources deleted soon.

Design doc: https://hackmd.angular.io/f8OBi9KMTNKButSWsh1gCA?view
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.

🎉

@alexeagle alexeagle merged commit 2fd80cf into bazel-contrib:master Sep 19, 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.

3 participants