build(service-worker): properly build npm_package with Bazel (#23090)

PR Close #23090
This commit is contained in:
Alex Rickabaugh 2018-03-30 09:45:42 -07:00
parent 32a41bc738
commit f48e215305
4 changed files with 59 additions and 5 deletions

View File

@ -19,16 +19,35 @@ ng_module(
],
)
genrule(
name = "ngsw_config_binary",
srcs = ["//packages/service-worker/cli:ngsw_config.js"],
outs = ["ngsw-config.js"],
cmd = "echo '#!/usr/bin/env node' > $@ && cat $< >> $@",
)
genrule(
name = "ngsw_worker_renamed",
srcs = ["//packages/service-worker/worker:ngsw_worker.es6.js"],
outs = ["ngsw-worker.js"],
cmd = "cp $< $@",
)
ng_package(
name = "npm_package",
srcs = [
"package.json",
"safety-worker.js",
"//packages/service-worker/config:package.json",
],
data = [
":ngsw_config_binary",
":ngsw_worker_renamed",
"//packages/service-worker/config",
],
entry_point = "packages/service-worker/index.js",
tags = [
# TODO(alxhub): enable release after landing #23090
# "release-with-framework",
"release-with-framework",
],
deps = [
":service-worker",

View File

@ -0,0 +1,25 @@
package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ts_library", "npm_package")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
ts_library(
name = "cli",
srcs = glob(
[
"*.ts",
],
),
tsconfig = ":tsconfig.json",
deps = [
"//packages/service-worker/config",
],
)
ng_rollup_bundle(
name = "ngsw_config",
entry_point = "packages/service-worker/cli/main.js",
deps = [
":cli",
],
)

View File

@ -1,6 +1,7 @@
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
ts_library(
name = "worker",
@ -17,5 +18,14 @@ ts_library(
ts_library(
name = "main",
srcs = ["main.ts"],
tsconfig = ":tsconfig.json",
deps = [":worker"],
)
ng_rollup_bundle(
name = "ngsw_worker",
entry_point = "packages/service-worker/worker/main.js",
deps = [
":main",
],
)

View File

@ -3,11 +3,11 @@
set -u -e -o pipefail
# Use for BETA and RC releases
# Publish all packages in `dist/packages-dist` to npm (as next)
# Query Bazel for npm_package and ng_package rules with tags=["release-with-framework"]
# Publish them to npm (tagged next)
for p in $(bazel query --output=label 'attr("tags", "\[.*release-with-framework.*\]", //...) intersect kind(".*_package", //...) except //dist/...'); do
bazel run -- $p.publish --access public --tag next
done
(cd dist/packages-dist; for p in language-service service-worker; do npm publish --access public --tag next $p; done)
# TODO(alexeagle): publish everything from bazel and remove this
(cd dist/packages-dist; for p in language-service; do npm publish --access public --tag next $p; done)