build: ts-api-guardian reuses root node_modules (#22894)

This avoids the need to run bazel run :install instead of yarn install.
We merge the devDependencies of ts-api-guardian into the root package.json file.

PR Close #22894
This commit is contained in:
Alex Eagle 2018-03-20 13:13:06 -07:00 committed by Matias Niemelä
parent 8ca26a9ebb
commit 34981063ec
8 changed files with 57 additions and 2266 deletions

View File

@ -1,5 +1,7 @@
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_nodejs//:defs.bzl", "node_modules_filegroup")
exports_files([ exports_files([
"tsconfig.json", "tsconfig.json",
"LICENSE", "LICENSE",
@ -12,41 +14,24 @@ alias(
actual = "@yarn//:yarn", actual = "@yarn//:yarn",
) )
# This rule belongs in node_modules/BUILD node_modules_filegroup(
# It's here as a workaround for
# https://github.com/bazelbuild/bazel/issues/374#issuecomment-296217940
filegroup(
name = "node_modules", name = "node_modules",
# Performance workaround: list individual files packages = [
# Reduces the number of files as inputs to nodejs_binary:
# bazel query "deps(:node_modules)" | wc -l
# This won't scale in the general case.
# TODO(alexeagle): figure out what to do
srcs = glob(["/".join([
"node_modules",
pkg,
"**",
ext,
]) for pkg in [
"jasmine",
"typescript",
"zone.js",
"tsutils",
"@types",
"tsickle",
"hammerjs",
"protobufjs",
"bytebuffer", "bytebuffer",
"hammerjs",
"jasmine",
"minimist",
"protobufjs",
"reflect-metadata", "reflect-metadata",
"source-map-support", "source-map-support",
"minimist", "tsickle",
"@webcomponents/custom-elements",
"tslib", "tslib",
] for ext in [ "tsutils",
"*.js", "typescript",
"*.json", "zone.js",
"*.d.ts", "@types",
]]), "@webcomponents/custom-elements",
],
) )
filegroup( filegroup(

View File

@ -7,13 +7,16 @@ http_archive(
sha256 = "11c0d73bdcb4b2608abbe5967be5a910bdaebf848eb13e4e7f8413bbdeb940b8", sha256 = "11c0d73bdcb4b2608abbe5967be5a910bdaebf848eb13e4e7f8413bbdeb940b8",
) )
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories") load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
check_bazel_version("0.9.0") check_bazel_version("0.9.0")
node_repositories(package_json = [ node_repositories(package_json = ["//:package.json"])
"//:package.json",
"//tools/ts-api-guardian:package.json", yarn_install(
]) name = "ts-api-guardian_runtime_deps",
package_json = "//tools/ts-api-guardian:package.json",
yarn_lock = "//tools/ts-api-guardian:yarn.lock",
)
http_archive( http_archive(
name = "build_bazel_rules_typescript", name = "build_bazel_rules_typescript",

View File

@ -39,11 +39,13 @@
"@bazel/ibazel": "^0.1.1", "@bazel/ibazel": "^0.1.1",
"@types/angularjs": "1.5.14-alpha", "@types/angularjs": "1.5.14-alpha",
"@types/base64-js": "1.2.5", "@types/base64-js": "1.2.5",
"@types/chai": "^4.1.2",
"@types/chokidar": "1.7.3", "@types/chokidar": "1.7.3",
"@types/diff": "^3.2.2", "@types/diff": "^3.2.2",
"@types/fs-extra": "4.0.2", "@types/fs-extra": "4.0.2",
"@types/hammerjs": "2.0.35", "@types/hammerjs": "2.0.35",
"@types/jasmine": "2.2.22-alpha", "@types/jasmine": "2.2.22-alpha",
"@types/minimist": "^1.2.0",
"@types/node": "6.0.88", "@types/node": "6.0.88",
"@types/selenium-webdriver": "3.0.7", "@types/selenium-webdriver": "3.0.7",
"@types/shelljs": "^0.7.8", "@types/shelljs": "^0.7.8",

View File

@ -9,34 +9,14 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
exports_files(["bin/ts-api-guardian"]) exports_files(["bin/ts-api-guardian"])
node_modules_filegroup(
name = "compile_time_deps",
packages = [
"chalk",
"typescript",
"@types",
],
)
ts_library( ts_library(
name = "lib", name = "lib",
srcs = glob(["lib/*.ts"]), srcs = glob(["lib/*.ts"]),
module_name = "ts-api-guardian", module_name = "ts-api-guardian",
node_modules = ":compile_time_deps",
tsconfig = "//tools:tsconfig.json", tsconfig = "//tools:tsconfig.json",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
node_modules_filegroup(
name = "runtime_deps",
packages = [
"chai",
"chalk",
"jasmine",
],
visibility = ["//visibility:public"],
)
# Copy Angular's license to govern ts-api-guardian as well. # Copy Angular's license to govern ts-api-guardian as well.
# We use a genrule to put it in this package, so it will be in the right root directory. # We use a genrule to put it in this package, so it will be in the right root directory.
genrule( genrule(
@ -66,7 +46,6 @@ ts_library(
name = "test_lib", name = "test_lib",
testonly = True, testonly = True,
srcs = glob(["test/*.ts"]), srcs = glob(["test/*.ts"]),
node_modules = ":compile_time_deps",
deps = [":lib"], deps = [":lib"],
) )
@ -80,5 +59,5 @@ jasmine_node_test(
]) + [ ]) + [
":ts-api-guardian", ":ts-api-guardian",
], ],
node_modules = ":runtime_deps", node_modules = "@ts-api-guardian_runtime_deps//:node_modules",
) )

View File

@ -27,6 +27,9 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
] ]
args = [ args = [
# Needed so that node doesn't walk back to the source directory.
# From there, the relative imports would point to .ts files.
"--node_options=--preserve-symlinks",
"--stripExportPattern", "^\(__\\)", "--stripExportPattern", "^\(__\\)",
"--onStabilityMissing", "error", "--onStabilityMissing", "error",
] ]
@ -36,7 +39,7 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
nodejs_test( nodejs_test(
name = name, name = name,
data = data, data = data,
node_modules = "//tools/ts-api-guardian:runtime_deps", node_modules = "@ts-api-guardian_runtime_deps//:node_modules",
entry_point = "angular/tools/ts-api-guardian/bin/ts-api-guardian", entry_point = "angular/tools/ts-api-guardian/bin/ts-api-guardian",
templated_args = args + ["--verify", golden, actual], templated_args = args + ["--verify", golden, actual],
testonly = 1, testonly = 1,
@ -46,7 +49,7 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
nodejs_binary( nodejs_binary(
name = name + ".accept", name = name + ".accept",
data = data, data = data,
node_modules = "//tools/ts-api-guardian:runtime_deps", node_modules = "@ts-api-guardian_runtime_deps//:node_modules",
entry_point = "angular/tools/ts-api-guardian/bin/ts-api-guardian", entry_point = "angular/tools/ts-api-guardian/bin/ts-api-guardian",
templated_args = args + ["--out", golden, actual], templated_args = args + ["--out", golden, actual],
**kwargs **kwargs

View File

@ -19,23 +19,8 @@
"minimist": "^1.2.0" "minimist": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.1.2",
"@types/diff": "^3.2.2",
"@types/minimist": "^1.2.0",
"@types/mocha": "^2.2.48",
"@types/node": "^0.12.15",
"chai": "^4.1.2", "chai": "^4.1.2",
"clang-format": "^1.0.25",
"gulp": "^3.8.11",
"gulp-clang-format": "^1.0.25",
"gulp-mocha": "^5.0.0",
"gulp-sourcemaps": "^2.6.4",
"gulp-typescript": "^4.0.1",
"gulp-util": "^3.0.8",
"merge2": "^1.2.1",
"jasmine": "^3.1.0", "jasmine": "^3.1.0",
"source-map": "^0.7.1",
"source-map-support": "^0.5.3",
"typescript": "~2.6.2" "typescript": "~2.6.2"
}, },
"repository": {}, "repository": {},

File diff suppressed because it is too large Load Diff

View File

@ -85,6 +85,10 @@
version "1.2.5" version "1.2.5"
resolved "https://registry.yarnpkg.com/@types/base64-js/-/base64-js-1.2.5.tgz#582b2476169a6cba460a214d476c744441d873d5" resolved "https://registry.yarnpkg.com/@types/base64-js/-/base64-js-1.2.5.tgz#582b2476169a6cba460a214d476c744441d873d5"
"@types/chai@^4.1.2":
version "4.1.2"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.2.tgz#f1af664769cfb50af805431c407425ed619daa21"
"@types/chokidar@1.7.3": "@types/chokidar@1.7.3":
version "1.7.3" version "1.7.3"
resolved "https://registry.yarnpkg.com/@types/chokidar/-/chokidar-1.7.3.tgz#ca87a53aa596c01eb93237ab4055edf71dcb9ca6" resolved "https://registry.yarnpkg.com/@types/chokidar/-/chokidar-1.7.3.tgz#ca87a53aa596c01eb93237ab4055edf71dcb9ca6"
@ -125,6 +129,10 @@
version "3.0.3" version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
"@types/minimist@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
"@types/node@*": "@types/node@*":
version "8.0.28" version "8.0.28"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.28.tgz#86206716f8d9251cf41692e384264cbd7058ad60" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.28.tgz#86206716f8d9251cf41692e384264cbd7058ad60"