build: publish ts-api-guardian rule in the npm package (#29977)

With this change downstream users will no longer need to build ts-api-guardian from source as now the bazel rule is available in the npm package.

This can be used by installing ts-api-guardian as a devDependency and changing the load syntax from:
```
load("@angular//tools/ts-api-guardian:index.bzl", "ts_api_guardian_test")
```

to:
```
load("@npm_ts_api_guardian//:index.bzl", "ts_api_guardian_test")
```

**Note**: downstream users should also clean their `WORKSPACE` and remove the dependencies of angular workspace.

PR Close #29977
This commit is contained in:
Alan Agius 2019-04-19 08:37:01 +02:00 committed by Ben Lesh
parent 9b93bd625f
commit d7f7826363
3 changed files with 24 additions and 3 deletions

View File

@ -1,3 +1,4 @@
# BEGIN-INTERNAL
load( load(
"@build_bazel_rules_nodejs//:defs.bzl", "@build_bazel_rules_nodejs//:defs.bzl",
"jasmine_node_test", "jasmine_node_test",
@ -5,8 +6,6 @@ load(
) )
load("@npm_bazel_typescript//:index.bzl", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_library")
exports_files(["bin/ts-api-guardian"])
ts_library( ts_library(
name = "lib", name = "lib",
srcs = glob(["lib/*.ts"]), srcs = glob(["lib/*.ts"]),
@ -35,10 +34,16 @@ genrule(
npm_package( npm_package(
name = "ts-api-guardian", name = "ts-api-guardian",
srcs = [ srcs = [
"BUILD.bazel",
"README.md", "README.md",
"bin/ts-api-guardian", "bin/ts-api-guardian",
"index.bzl",
"package.json", "package.json",
], ],
replacements = {
"@angular//tools/ts-api-guardian": "@npm_ts_api_guardian//",
"angular/tools/ts-api-guardian/": "npm_ts_api_guardian/",
},
deps = [ deps = [
":lib", ":lib",
":license", ":license",
@ -79,3 +84,10 @@ jasmine_node_test(
], ],
tags = ["local"], tags = ["local"],
) )
# END-INTERNAL
filegroup(
name = "bin",
srcs = glob(["lib/*.js"]) + ["bin/ts-api-guardian"],
visibility = ["//visibility:public"],
)

View File

@ -33,8 +33,11 @@ def ts_api_guardian_test(
"""Runs ts_api_guardian """Runs ts_api_guardian
""" """
data += [ data += [
# BEGIN-INTERNAL
# Locally we need to add the TS build target
"@angular//tools/ts-api-guardian:lib", "@angular//tools/ts-api-guardian:lib",
"@angular//tools/ts-api-guardian:bin/ts-api-guardian", # END-INTERNAL
"@angular//tools/ts-api-guardian:bin",
] ]
args = [ args = [

View File

@ -4,6 +4,12 @@
"description": "Guards the API of TypeScript libraries!", "description": "Guards the API of TypeScript libraries!",
"main": "lib/main.js", "main": "lib/main.js",
"typings": "lib/main.d.ts", "typings": "lib/main.d.ts",
"bazelWorkspaces": {
"npm_ts_api_guardian": {
"version": "0.4.1",
"rootPath": "."
}
},
"bin": { "bin": {
"ts-api-guardian": "./bin/ts-api-guardian" "ts-api-guardian": "./bin/ts-api-guardian"
}, },