Skip to content

Commit

Permalink
Introduce an npm_package for rules_nodejs distro
Browse files Browse the repository at this point in the history
    This allows us to start authoring in TypeScript but still distribute JS.
    Also users won't need to fetch our whole repo anymore, so we can check in larger files, like a vendored node for example
  • Loading branch information
alexeagle committed Feb 6, 2019
1 parent f1301e7 commit 97c0f66
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 2 deletions.
39 changes: 39 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")

package(default_visibility = ["//visibility:public"])

exports_files(["tsconfig.json"])
Expand All @@ -9,3 +11,40 @@ filegroup(
name = "node_modules_none",
srcs = [],
)

# The entire content of the real WORKSPACE file in this directory is only meant for local development.
# So we generate a trivial one for the distribution.
genrule(
name = "generated_WORKSPACE",
srcs = [],
outs = ["WORKSPACE"],
cmd = "echo \"workspace(name = \\\"build_bazel_rules_nodejs\\\")\" > $@",
)

npm_package(
name = "rules_nodejs_package",
srcs = [
"BUILD.bazel",
"LICENSE",
"defs.bzl",
"package.bzl",
"//third_party/github.com/gjtorikian/isBinaryFile:LICENSE",
],
deps = [
":generated_WORKSPACE",
"//third_party/github.com/bazelbuild/bazel-skylib:package_contents",
"//third_party/github.com/buffer-from:package_contents",
"//third_party/github.com/gjtorikian/isBinaryFile",
"//third_party/github.com/source-map:package_contents",
"//third_party/github.com/source-map-support:package_contents",
"//internal/common:package_contents",
"//internal/history-server:package_contents",
"//internal/http-server:package_contents",
"//internal/jasmine_node_test:package_contents",
# TODO(alexeagle): distribute separately as @bazel/rollup
"//internal/rollup:package_contents",
"//internal/node:package_contents",
"//internal/npm_install:package_contents",
"//internal/npm_package:package_contents",
],
)
8 changes: 8 additions & 0 deletions internal/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ py_test(
srcs = ["check_version_test.py"],
data = [":check_version.bzl"],
)

filegroup(
name = "package_contents",
srcs = glob(["*.bzl"]) + [
"BUILD.bazel",
],
visibility = ["//:__pkg__"],
)
9 changes: 9 additions & 0 deletions internal/history-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ exports_files([
# Exported to be consumed for generating skydoc.
"history_server.bzl",
])

filegroup(
name = "package_contents",
srcs = [
"BUILD.bazel",
"history_server.bzl",
],
visibility = ["//:__pkg__"],
)
9 changes: 9 additions & 0 deletions internal/http-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ exports_files([
# Exported to be consumed for generating skydoc.
"http_server.bzl",
])

filegroup(
name = "package_contents",
srcs = [
"BUILD.bazel",
"http_server.bzl",
],
visibility = ["//:__pkg__"],
)
6 changes: 6 additions & 0 deletions internal/jasmine_node_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ exports_files([
# Exported to be consumed for generating skydoc.
"jasmine_node_test.bzl",
])

filegroup(
name = "package_contents",
srcs = glob(["*"]),
visibility = ["//:__pkg__"],
)
10 changes: 10 additions & 0 deletions internal/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ exports_files([
"node_launcher.sh",
"node_loader.js",
])

filegroup(
name = "package_contents",
srcs = glob([
"*.bzl",
"*.js",
"*.sh",
]) + ["BUILD.bazel"],
visibility = ["//:__pkg__"],
)
2 changes: 1 addition & 1 deletion internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ See https://docs.bazel.build/versions/master/skylark/repository_rules.html
load("//internal/common:check_bazel_version.bzl", "check_bazel_version")
load("//internal/common:os_name.bzl", "os_name")
load("//internal/npm_install:npm_install.bzl", "yarn_install")
load("//third_party/github.com/bazelbuild/bazel-skylib/lib:paths.bzl", "paths")
load("//third_party/github.com/bazelbuild/bazel-skylib:lib/paths.bzl", "paths")
load(":node_labels.bzl", "get_yarn_node_repositories_label")

# Callers that don't specify a particular version will get these.
Expand Down
6 changes: 6 additions & 0 deletions internal/npm_install/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ filegroup(
srcs = ["generate_build_file.js"],
visibility = ["//internal:__subpackages__"],
)

filegroup(
name = "package_contents",
srcs = glob(["*"]),
visibility = ["//:__pkg__"],
)
6 changes: 6 additions & 0 deletions internal/npm_package/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ nodejs_binary(
node_modules = "@build_bazel_rules_nodejs_npm_install_deps//:node_modules",
visibility = ["//visibility:public"],
)

filegroup(
name = "package_contents",
srcs = glob(["*"]),
visibility = ["//:__pkg__"],
)
12 changes: 12 additions & 0 deletions internal/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ jasmine_node_test(
),
node_modules = "//internal/test:node_modules",
)

filegroup(
name = "package_contents",
srcs = glob(
[
"*.js",
"*.bzl",
],
exclude = ["*.spec.js"],
) + ["BUILD.bazel"],
visibility = ["//:__pkg__"],
)
7 changes: 7 additions & 0 deletions third_party/github.com/bazelbuild/bazel-skylib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
licenses(["notice"])

filegroup(
name = "package_contents",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)
1 change: 0 additions & 1 deletion third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD

This file was deleted.

6 changes: 6 additions & 0 deletions third_party/github.com/buffer-from/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ filegroup(
name = "contents",
srcs = _CONTENT,
)

filegroup(
name = "package_contents",
srcs = glob(["*"]),
visibility = ["//:__pkg__"],
)
1 change: 1 addition & 0 deletions third_party/github.com/gjtorikian/isBinaryFile/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library")
# TODO(alexeagle): support authoring rules_nodejs sources in TypeScript
# We can only do this after all users switch to using a distribution package.
# load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])
Expand Down
6 changes: 6 additions & 0 deletions third_party/github.com/source-map-support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ filegroup(
name = "contents",
srcs = _CONTENT,
)

filegroup(
name = "package_contents",
srcs = glob(["*"]),
visibility = ["//:__pkg__"],
)
6 changes: 6 additions & 0 deletions third_party/github.com/source-map/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ filegroup(
name = "contents",
srcs = _CONTENT,
)

filegroup(
name = "package_contents",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)

0 comments on commit 97c0f66

Please sign in to comment.