Skip to content

Commit

Permalink
Move npm rules to separate packages (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmos authored Mar 5, 2020
1 parent c9d9e34 commit 2797858
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 60 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_depen

buildifier_dependencies()

# We don't use any nodejs but this includes a rule for publishing releases to npm
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "b6670f9f43faa66e3009488bbd909bc7bc46a5a9661a33f6bc578068d1837f37",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.3.0/rules_nodejs-1.3.0.tar.gz"],
)

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")

node_repositories()
28 changes: 3 additions & 25 deletions buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_binary(
Expand Down Expand Up @@ -77,30 +75,10 @@ exports_files(
visibility = ["//visibility:public"],
)

genrule(
name = "launcher",
srcs = ["//:launcher.js"],
outs = ["buildifier.js"],
cmd = "sed s/_TOOL_/buildifier/ $< > $@",
)

copy_file(
name = "copy_LICENSE",
src = "//:LICENSE",
out = "LICENSE",
)

pkg_npm(
name = "npm_package",
srcs = [
exports_files(
[
"README.md",
"package.json",
],
deps = [
"LICENSE",
"buildifier.js",
":buildifier-darwin",
":buildifier-linux",
":buildifier-windows",
],
visibility = ["//buildifier/npm:__pkg__"],
)
7 changes: 0 additions & 7 deletions buildifier/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ def buildifier_dependencies():
url = "https://github.com/bazelbuild/bazel-skylib/archive/c00ef493869e2966d47508e8625aae723a4a3054.tar.gz", # 2018-12-06
)

_maybe(
http_archive,
name = "build_bazel_rules_nodejs",
sha256 = "b6670f9f43faa66e3009488bbd909bc7bc46a5a9661a33f6bc578068d1837f37",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.3.0/rules_nodejs-1.3.0.tar.gz"],
)

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
30 changes: 30 additions & 0 deletions buildifier/npm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")

copy_file(
name = "copy_LICENSE",
src = "//:LICENSE",
out = "LICENSE",
)

genrule(
name = "buildifier_launcher",
srcs = ["//:launcher.js"],
outs = ["buildifier.js"],
cmd = "sed s/_TOOL_/buildifier/ $< > $@",
)

pkg_npm(
name = "buildifier",
srcs = [
"package.json",
],
deps = [
"LICENSE",
"buildifier.js",
"//buildifier:README.md",
"//buildifier:buildifier-darwin",
"//buildifier:buildifier-linux",
"//buildifier:buildifier-windows",
],
)
File renamed without changes.
28 changes: 3 additions & 25 deletions buildozer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
Expand Down Expand Up @@ -68,30 +66,10 @@ go_binary(
visibility = ["//visibility:public"],
)

genrule(
name = "launcher",
srcs = ["//:launcher.js"],
outs = ["buildozer.js"],
cmd = "sed s/_TOOL_/buildozer/ $< > $@",
)

copy_file(
name = "copy_LICENSE",
src = "//:LICENSE",
out = "LICENSE",
)

pkg_npm(
name = "npm_package",
srcs = [
exports_files(
[
"README.md",
"package.json",
],
deps = [
"LICENSE",
"buildozer.js",
":buildozer-darwin",
":buildozer-linux",
":buildozer-windows",
],
visibility = ["//buildozer/npm:__pkg__"],
)
30 changes: 30 additions & 0 deletions buildozer/npm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")

copy_file(
name = "copy_LICENSE",
src = "//:LICENSE",
out = "LICENSE",
)

genrule(
name = "buildozer_launcher",
srcs = ["//:launcher.js"],
outs = ["buildozer.js"],
cmd = "sed s/_TOOL_/buildozer/ $< > $@",
)

pkg_npm(
name = "buildozer",
srcs = [
"package.json",
],
deps = [
"LICENSE",
"buildozer.js",
"//buildozer:README.md",
"//buildozer:buildozer-darwin",
"//buildozer:buildozer-linux",
"//buildozer:buildozer-windows",
],
)
File renamed without changes.
6 changes: 3 additions & 3 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -u -e -o pipefail
set -u -e -o pipefail

# TODO(vladmos): add bits for publishing go binaries to github

Expand All @@ -17,5 +17,5 @@ readonly NPM_ARGS=(
# "--dry-run"
)
for pkg in buildifier buildozer; do
bazel run --config=release //$pkg:npm_package.publish -- ${NPM_ARGS[@]}
done
bazel run --config=release //$pkg/npm:$pkg.publish -- ${NPM_ARGS[@]}
done

0 comments on commit 2797858

Please sign in to comment.