Skip to content

Commit

Permalink
feat(bazel): add an ng_package rule (angular#22221)
Browse files Browse the repository at this point in the history
This produces a directory following the Angular Package layout spec.

Includes integration test coverage by making a minimal ng_package in integration/bazel.
Unit tests verify the content of the @angular/core and @angular/common packages.

This doesn't totally match our current output, but is good enough to unblock some
early adopters.

It re-uses logic from the rollup_bundle rule in rules_nodejs. It should also
eventually have the .pack and .publish secondary targets like npm_package rule.

PR Close angular#22221
  • Loading branch information
alexeagle authored and leo6104 committed Mar 25, 2018
1 parent fd556e6 commit 6b2c597
Show file tree
Hide file tree
Showing 23 changed files with 1,101 additions and 61 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
@@ -1,14 +1,14 @@
workspace(name = "angular")

# Using a pre-release snapshot to pick up a commit that makes all nodejs_binary
# programs produce source-mapped stack traces.
RULES_NODEJS_VERSION = "926349cea4cd360afcd5647ccdd09d2d2fb471aa"
# programs produce source-mapped stack traces and uglify sourcemaps.
RULES_NODEJS_VERSION = "4303cbef12e5e252ad66cc35cff1123e3a44ee83"

http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/%s.zip" % RULES_NODEJS_VERSION,
strip_prefix = "rules_nodejs-%s" % RULES_NODEJS_VERSION,
sha256 = "5ba3c8c209078c2e3f0c6aa4abd01a1a561f92a5bfda04e25604af5f4734d69d",
sha256 = "fccb9a7122f339d89c9994dc0fea33c737dd76e66281d0da0cb841da5f1edec7",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
Expand Down
32 changes: 11 additions & 21 deletions integration/bazel/BUILD.bazel
Expand Up @@ -2,25 +2,15 @@ package(default_visibility = ["//visibility:public"])

filegroup(
name = "node_modules",
# Workaround https://github.com/bazelbuild/bazel/issues/4242
# Can't just glob(["node_modules/**/*.{js,d.ts,json}"])
srcs = glob(["/".join([
"node_modules",
pkg,
"**",
ext,
]) for pkg in [
"@angular",
"@types",
"bytebuffer",
"protobufjs",
"reflect-metadata",
"tsickle",
"typescript",
"zone.js",
] for ext in [
"*.js",
"*.json",
"*.d.ts",
]]),
srcs = glob(
["node_modules/**/*"],
# Exclude directories that commonly contain filenames which are
# illegal bazel labels
exclude = [
# e.g. node_modules/adm-zip/test/assets/attributes_test/New folder/hidden.txt
"node_modules/**/test/**",
# e.g. node_modules/xpath/docs/function resolvers.md
"node_modules/**/docs/**",
],
),
)
10 changes: 7 additions & 3 deletions integration/bazel/WORKSPACE
@@ -1,10 +1,14 @@
workspace(name = "bazel_integration_test")

# Using a pre-release snapshot to pick up a commit that makes all nodejs_binary
# programs produce source-mapped stack traces and uglify sourcemaps.
RULES_NODEJS_VERSION = "4303cbef12e5e252ad66cc35cff1123e3a44ee83"

http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.4.1.zip",
strip_prefix = "rules_nodejs-0.4.1",
sha256 = "e9bc013417272b17f302dc169ad597f05561bb277451f010043f4da493417607",
url = "https://github.com/bazelbuild/rules_nodejs/archive/%s.zip" % RULES_NODEJS_VERSION,
strip_prefix = "rules_nodejs-%s" % RULES_NODEJS_VERSION,
sha256 = "fccb9a7122f339d89c9994dc0fea33c737dd76e66281d0da0cb841da5f1edec7",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
Expand Down
8 changes: 7 additions & 1 deletion integration/bazel/src/hello-world/BUILD.bazel
@@ -1,6 +1,6 @@
package(default_visibility = ["//visibility:public"])

load("@angular//:index.bzl", "ng_module")
load("@angular//:index.bzl", "ng_module", "ng_package")
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary")

sass_binary(
Expand All @@ -17,3 +17,9 @@ ng_module(
# npm distro of angular there is no ts_library rule to propagate the dep.
deps = ["@rxjs"],
)

ng_package(
name = "npm_package",
entry_point = "src/hello-world/index.js",
deps = [":hello-world"],
)
2 changes: 2 additions & 0 deletions integration/bazel/src/hello-world/index.ts
@@ -0,0 +1,2 @@
export * from './hello-world.component';
export * from './hello-world.module';

0 comments on commit 6b2c597

Please sign in to comment.