Skip to content

Commit

Permalink
build: ts-api-guardian reuses root node_modules (angular#22894)
Browse files Browse the repository at this point in the history
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 angular#22894
  • Loading branch information
alexeagle authored and leo6104 committed Mar 25, 2018
1 parent b27a315 commit 56885aa
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 2,287 deletions.
43 changes: 14 additions & 29 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package(default_visibility = ["//visibility:public"])

load("@build_bazel_rules_nodejs//:defs.bzl", "node_modules_filegroup")

exports_files([
"tsconfig.json",
"LICENSE",
Expand All @@ -12,41 +14,24 @@ alias(
actual = "@yarn//:yarn",
)

# This rule belongs in node_modules/BUILD
# It's here as a workaround for
# https://github.com/bazelbuild/bazel/issues/374#issuecomment-296217940
filegroup(
node_modules_filegroup(
name = "node_modules",
# Performance workaround: list individual files
# 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",
packages = [
"bytebuffer",
"hammerjs",
"jasmine",
"minimist",
"protobufjs",
"bytebuffer",
"reflect-metadata",
"source-map-support",
"minimist",
"@webcomponents/custom-elements",
"tsickle",
"tslib",
] for ext in [
"*.js",
"*.json",
"*.d.ts",
]]),
"tsutils",
"typescript",
"zone.js",
"@types",
"@webcomponents/custom-elements",
],
)

filegroup(
Expand Down
13 changes: 8 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ http_archive(
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")
node_repositories(package_json = [
"//:package.json",
"//tools/ts-api-guardian:package.json",
])
node_repositories(package_json = ["//: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(
name = "build_bazel_rules_typescript",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
"@bazel/ibazel": "^0.1.1",
"@types/angularjs": "1.5.14-alpha",
"@types/base64-js": "1.2.5",
"@types/chai": "^4.1.2",
"@types/chokidar": "1.7.3",
"@types/diff": "^3.2.2",
"@types/fs-extra": "4.0.2",
"@types/hammerjs": "2.0.35",
"@types/jasmine": "2.2.22-alpha",
"@types/minimist": "^1.2.0",
"@types/node": "6.0.88",
"@types/selenium-webdriver": "3.0.7",
"@types/shelljs": "^0.7.8",
Expand Down
23 changes: 1 addition & 22 deletions tools/ts-api-guardian/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,14 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

exports_files(["bin/ts-api-guardian"])

node_modules_filegroup(
name = "compile_time_deps",
packages = [
"chalk",
"typescript",
"@types",
],
)

ts_library(
name = "lib",
srcs = glob(["lib/*.ts"]),
module_name = "ts-api-guardian",
node_modules = ":compile_time_deps",
tsconfig = "//tools:tsconfig.json",
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.
# We use a genrule to put it in this package, so it will be in the right root directory.
genrule(
Expand Down Expand Up @@ -66,7 +46,6 @@ ts_library(
name = "test_lib",
testonly = True,
srcs = glob(["test/*.ts"]),
node_modules = ":compile_time_deps",
deps = [":lib"],
)

Expand All @@ -80,5 +59,5 @@ jasmine_node_test(
]) + [
":ts-api-guardian",
],
node_modules = ":runtime_deps",
node_modules = "@ts-api-guardian_runtime_deps//:node_modules",
)
7 changes: 5 additions & 2 deletions tools/ts-api-guardian/index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
]

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", "^\(__\|ɵ\)",
"--onStabilityMissing", "error",
]
Expand All @@ -36,7 +39,7 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
nodejs_test(
name = name,
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",
templated_args = args + ["--verify", golden, actual],
testonly = 1,
Expand All @@ -46,7 +49,7 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
nodejs_binary(
name = name + ".accept",
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",
templated_args = args + ["--out", golden, actual],
**kwargs
Expand Down
15 changes: 0 additions & 15 deletions tools/ts-api-guardian/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,8 @@
"minimist": "^1.2.0"
},
"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",
"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",
"source-map": "^0.7.1",
"source-map-support": "^0.5.3",
"typescript": "~2.6.2"
},
"repository": {},
Expand Down

0 comments on commit 56885aa

Please sign in to comment.