Skip to content

Commit

Permalink
build: Turn tsec checks into bazel tests. (#43108)
Browse files Browse the repository at this point in the history
Introduce two new bazel rules: tsec_test and tsec_config, for
describing the tsec checks and the tsconfig file needed for such
checks, respectively. Currently, tsec_test only checks the srcs
of a ts_library or ng_module. It does not check direct or transitive
dependencies. Also, tsconfig files need to be manually maintained
to make sure tsec can read all necessary input (including global
symbols).

PR Close #43108
  • Loading branch information
uraj authored and AndrewKushnir committed Sep 13, 2021
1 parent 509031c commit d12d068
Show file tree
Hide file tree
Showing 36 changed files with 376 additions and 168 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,3 @@ baseline.json

# Husky
.husky/_

# tsec
.tsec
4 changes: 2 additions & 2 deletions .pullapprove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,10 @@ groups:
'packages/core/test/linker/security_integration_spec.ts',
'packages/compiler/src/schema/**',
'packages/platform-browser/src/security/**',
'packages/tsconfig-tsec.json',
'packages/tsconfig-tsec-base.json',
'packages/**/tsconfig-tsec.json',
'packages/tsec-exemption.json'
'packages/tsec-exemption.json',
'tools/tsec.bzl',
'aio/content/guide/security.md',
'aio/content/examples/security/**',
'aio/content/images/guide/security/**',
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prepare": "husky install",
"test-ivy-aot": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot",
"test-non-ivy": "bazelisk test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only",
"test-tsec": "bazelisk test //... --build_tag_filters=tsec --test_tag_filters=tsec",
"test-fixme-ivy-aot": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot --test_tag_filters=-no-ivy-aot",
"list-fixme-ivy-targets": "bazelisk query --output=label 'attr(\"tags\", \"\\[.*fixme-ivy.*\\]\", //...) except kind(\"sh_binary\", //...) except kind(\"devmode_js_sources\", //...)' | sort",
"lint": "yarn -s tslint && yarn -s ng-dev format changed --check",
Expand All @@ -36,8 +37,7 @@
"symbol-extractor:update": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js accept",
"ts-circular-deps:check": "yarn -s ng-dev ts-circular-deps check --config ./packages/circular-deps-test.conf.js",
"ts-circular-deps:approve": "yarn -s ng-dev ts-circular-deps approve --config ./packages/circular-deps-test.conf.js",
"check-tooling-setup": "yarn tsc --project .ng-dev/tsconfig.json",
"tsec:packages": "yarn tsec -b packages/tsconfig-tsec.json"
"check-tooling-setup": "yarn tsc --project .ng-dev/tsconfig.json"
},
"// 1": "dependencies are used locally and by bazel",
"dependencies": {
Expand Down Expand Up @@ -181,7 +181,7 @@
"sauce-connect": "https://saucelabs.com/downloads/sc-4.6.2-linux.tar.gz",
"semver": "^7.3.5",
"ts-node": "^10.0.0",
"tsec": "0.1.7",
"tsec": "0.1.8",
"tslint-eslint-rules": "5.4.0",
"tslint-no-toplevel-property-access": "0.0.2",
"typed-graphqlify": "^3.1.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ts_config", "ts_library")
load("//tools:tsec.bzl", "tsec_config")

package(default_visibility = ["//visibility:public"])

Expand All @@ -22,6 +23,13 @@ ts_config(
deps = [":tsconfig-build.json"],
)

tsec_config(
name = "tsec_config",
src = "tsconfig-tsec-base.json",
exemption = ":tsec-exemption.json",
deps = [":tsconfig-build.json"],
)

exports_files([
"license-banner.txt",
"README.md",
Expand Down
20 changes: 0 additions & 20 deletions packages/animations/browser/tsconfig-tsec.json

This file was deleted.

18 changes: 0 additions & 18 deletions packages/animations/tsconfig-tsec.json

This file was deleted.

20 changes: 0 additions & 20 deletions packages/common/http/tsconfig-tsec.json

This file was deleted.

18 changes: 0 additions & 18 deletions packages/common/tsconfig-tsec.json

This file was deleted.

13 changes: 13 additions & 0 deletions packages/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ng_package", "ts_library")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")

package(default_visibility = ["//visibility:public"])

Expand All @@ -12,6 +13,18 @@ ts_library(
),
)

tsec_config(
name = "tsec_config",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "compiler",
tsconfig = "tsec_config",
)

ng_package(
name = "npm_package",
srcs = [
Expand Down
14 changes: 13 additions & 1 deletion packages/core/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("//tools:defaults.bzl", "api_golden_test", "api_golden_test_npm_package", "ng_module", "ng_package")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")
load("//packages/common/locales:index.bzl", "generate_base_locale_file")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -34,12 +35,23 @@ ng_module(
"//packages/core/src/interface",
"//packages/core/src/reflection",
"//packages/core/src/util",
"//packages/localize",
"//packages/zone.js/lib:zone_d_ts",
"@npm//rxjs",
],
)

tsec_config(
name = "tsconfig-tsec",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "core",
tsconfig = "tsconfig-tsec",
)

ng_package(
name = "npm_package",
srcs = [
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ts_library")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")

package(default_visibility = [
"//packages/compiler/test:__pkg__",
Expand All @@ -17,3 +18,15 @@ ts_library(
"//packages/core/src/util",
],
)

tsec_config(
name = "tsec_config",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "compiler",
tsconfig = "tsec_config",
)
8 changes: 8 additions & 0 deletions packages/core/src/compiler/tsconfig-tsec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** For building //packages/core/src/compiler. */
{
"extends": "../../../tsconfig-tsec-base.json",
"include": [
"**/*.ts",
"../util/ng_dev_mode.d.ts"
]
}
13 changes: 13 additions & 0 deletions packages/core/src/di/interface/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ts_library")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")

package(default_visibility = [
"//packages/core:__subpackages__",
Expand All @@ -18,3 +19,15 @@ ts_library(
"@npm//rxjs",
],
)

tsec_config(
name = "tsec_config",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "interface",
tsconfig = "tsec_config",
)
7 changes: 7 additions & 0 deletions packages/core/src/di/interface/tsconfig-tsec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** For building //packages/core/src/di/interface. */
{
"extends": "../../../../tsconfig-tsec-base.json",
"include": [
"**/*.ts"
]
}
13 changes: 13 additions & 0 deletions packages/core/src/interface/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ts_library")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")

package(default_visibility = [
"//packages/core:__subpackages__",
Expand All @@ -13,3 +14,15 @@ ts_library(
],
),
)

tsec_config(
name = "tsec_config",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "interface",
tsconfig = "tsec_config",
)
7 changes: 7 additions & 0 deletions packages/core/src/interface/tsconfig-tsec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** For building //packages/core/src/inteface. */
{
"extends": "../../../tsconfig-tsec-base.json",
"include": [
"*.ts"
]
}
13 changes: 13 additions & 0 deletions packages/core/src/reflection/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ts_library")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")

package(default_visibility = [
"//packages/core:__subpackages__",
Expand All @@ -17,3 +18,15 @@ ts_library(
"//packages/core/src/util",
],
)

tsec_config(
name = "tsec_config",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "reflection",
tsconfig = "tsec_config",
)
7 changes: 7 additions & 0 deletions packages/core/src/reflection/tsconfig-tsec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** For building //packages/core/src/reflection. */
{
"extends": "../../../tsconfig-tsec-base.json",
"include": [
"**/*.ts"
]
}
14 changes: 14 additions & 0 deletions packages/core/src/util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//tools:defaults.bzl", "ts_library")
load("//tools:tsec.bzl", "tsec_config", "tsec_test")

package(default_visibility = [
"//packages/core:__subpackages__",
Expand All @@ -15,6 +16,19 @@ ts_library(
deps = [
"//packages:types",
"//packages/core/src/interface",
"//packages/zone.js/lib:zone_d_ts",
"@npm//rxjs",
],
)

tsec_config(
name = "tsec_config",
src = ":tsconfig-tsec.json",
deps = ["//packages:tsec_config"],
)

tsec_test(
name = "tsec_test",
target = "util",
tsconfig = "tsec_config",
)
9 changes: 9 additions & 0 deletions packages/core/src/util/tsconfig-tsec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** For building //packages/core/src/util. */
{
"extends": "../../../tsconfig-tsec-base.json",
"include": [
"**/*.ts",
"../../../*.d.ts",
"../../../zone.js/lib/zone.d.ts"
]
}
9 changes: 2 additions & 7 deletions packages/core/tsconfig-tsec.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/** For building //packages/core. */
{
"extends": "../tsconfig-tsec-base.json",
"compilerOptions": {
"outDir": ".tsec"
},
"include": [
"*.ts",
"src/**/*.ts",
"../*.d.ts"
],
"references": [
{"path": "../zone.js/lib/tsconfig-tsec.json"}
"../*.d.ts",
"../zone.js/lib/zone.d.ts"
]
}
Loading

0 comments on commit d12d068

Please sign in to comment.