diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel
index 2a5869794c..1abc5b53fa 100644
--- a/packages/BUILD.bazel
+++ b/packages/BUILD.bazel
@@ -2,6 +2,7 @@ package(default_visibility = ["//visibility:public"])
exports_files([
"tsconfig-build.json",
+ "tsconfig-test.json",
"tsconfig.json",
])
diff --git a/packages/animations/browser/src/render/shared.ts b/packages/animations/browser/src/render/shared.ts
index 7027805b46..9d769e0b2f 100644
--- a/packages/animations/browser/src/render/shared.ts
+++ b/packages/animations/browser/src/render/shared.ts
@@ -10,6 +10,11 @@ import {AUTO_STYLE, AnimationEvent, AnimationPlayer, NoopAnimationPlayer, ɵAnim
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
import {AnimationDriver} from '../../src/render/animation_driver';
+// We don't include ambient node types here since @angular/animations/browser
+// is meant to target the browser so technically it should not depend on node
+// types. `process` is just declared locally here as a result.
+declare const process: any;
+
export function isBrowser() {
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
}
diff --git a/packages/bazel/test/ng_package/BUILD.bazel b/packages/bazel/test/ng_package/BUILD.bazel
index e21acdabd0..675b9d96e7 100644
--- a/packages/bazel/test/ng_package/BUILD.bazel
+++ b/packages/bazel/test/ng_package/BUILD.bazel
@@ -37,6 +37,7 @@ jasmine_node_test(
ts_library(
name = "example_spec_lib",
+ testonly = True,
srcs = ["example_package.spec.ts"],
deps = ["//packages:types"],
)
@@ -55,6 +56,7 @@ jasmine_node_test(
nodejs_binary(
name = "example_package.accept",
+ testonly = True,
data = [
"example_package.golden",
":example_spec_lib",
diff --git a/packages/benchpress/index.ts b/packages/benchpress/index.ts
index 1b11272642..716714669c 100644
--- a/packages/benchpress/index.ts
+++ b/packages/benchpress/index.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
// Must be imported first, because Angular decorators throw on load.
import 'reflect-metadata';
diff --git a/packages/compiler-cli/src/ngtsc/annotations/index.ts b/packages/compiler-cli/src/ngtsc/annotations/index.ts
index 77a4860842..8902f606e8 100644
--- a/packages/compiler-cli/src/ngtsc/annotations/index.ts
+++ b/packages/compiler-cli/src/ngtsc/annotations/index.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
export {ResourceLoader} from './src/api';
export {BaseDefDecoratorHandler} from './src/base_def';
export {ComponentDecoratorHandler} from './src/component';
diff --git a/packages/compiler-cli/src/ngtsc/factories/index.ts b/packages/compiler-cli/src/ngtsc/factories/index.ts
index b444770ea5..06052c6aa3 100644
--- a/packages/compiler-cli/src/ngtsc/factories/index.ts
+++ b/packages/compiler-cli/src/ngtsc/factories/index.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
export {FactoryGenerator} from './src/generator';
export {GeneratedFactoryHostWrapper} from './src/host';
export {FactoryInfo, generatedFactoryTransform} from './src/transform';
diff --git a/packages/compiler-cli/src/ngtsc/metadata/index.ts b/packages/compiler-cli/src/ngtsc/metadata/index.ts
index b15062c49d..083955dad7 100644
--- a/packages/compiler-cli/src/ngtsc/metadata/index.ts
+++ b/packages/compiler-cli/src/ngtsc/metadata/index.ts
@@ -6,5 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
export {TypeScriptReflectionHost, filterToMembersWithDecorator, findMember, reflectObjectLiteral, reflectTypeEntityToDeclaration} from './src/reflector';
export {AbsoluteReference, ImportMode, Reference, ResolvedReference, ResolvedValue, isDynamicValue, staticallyResolve} from './src/resolver';
diff --git a/packages/compiler-cli/src/ngtsc/util/src/path.ts b/packages/compiler-cli/src/ngtsc/util/src/path.ts
index 8410083396..954eba6777 100644
--- a/packages/compiler-cli/src/ngtsc/util/src/path.ts
+++ b/packages/compiler-cli/src/ngtsc/util/src/path.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
import * as path from 'path';
const TS_DTS_EXTENSION = /(\.d)?\.ts$/;
diff --git a/packages/compiler/test/BUILD.bazel b/packages/compiler/test/BUILD.bazel
index fb32cbad43..93f48479e9 100644
--- a/packages/compiler/test/BUILD.bazel
+++ b/packages/compiler/test/BUILD.bazel
@@ -13,6 +13,7 @@ UTILS = [
ts_library(
name = "test_utils",
+ testonly = True,
srcs = UTILS,
visibility = [
"//packages/compiler-cli/test:__subpackages__",
diff --git a/packages/compiler/testing/public_api.ts b/packages/compiler/testing/public_api.ts
index e95d9f8ef0..ee3657614d 100644
--- a/packages/compiler/testing/public_api.ts
+++ b/packages/compiler/testing/public_api.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
/**
* @module
* @description
diff --git a/packages/core/testing/public_api.ts b/packages/core/testing/public_api.ts
index e95d9f8ef0..3f9af0fc8b 100644
--- a/packages/core/testing/public_api.ts
+++ b/packages/core/testing/public_api.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
/**
* @module
* @description
diff --git a/packages/language-service/language-service.ts b/packages/language-service/language-service.ts
index 4e0fc2b3be..1fa65563fc 100644
--- a/packages/language-service/language-service.ts
+++ b/packages/language-service/language-service.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
/**
* @module
* @description
diff --git a/packages/platform-browser/testing/public_api.ts b/packages/platform-browser/testing/public_api.ts
index fcc511dc6e..4de37c10f5 100644
--- a/packages/platform-browser/testing/public_api.ts
+++ b/packages/platform-browser/testing/public_api.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
/**
* @module
* @description
diff --git a/packages/platform-server/public_api.ts b/packages/platform-server/public_api.ts
index 13238d82bd..9d83cb049e 100644
--- a/packages/platform-server/public_api.ts
+++ b/packages/platform-server/public_api.ts
@@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
+///
+
/**
* @module
* @description
diff --git a/packages/private/testing/BUILD.bazel b/packages/private/testing/BUILD.bazel
index 6383269e2d..df3ccca178 100644
--- a/packages/private/testing/BUILD.bazel
+++ b/packages/private/testing/BUILD.bazel
@@ -6,6 +6,7 @@ load("//tools:defaults.bzl", "ng_module")
ng_module(
name = "testing",
+ testonly = True,
srcs = glob(
["**/*.ts"],
),
diff --git a/packages/tsconfig-test.json b/packages/tsconfig-test.json
new file mode 100644
index 0000000000..da8860bf92
--- /dev/null
+++ b/packages/tsconfig-test.json
@@ -0,0 +1,9 @@
+/**
+ * Root tsconfig file for use in all tests.
+ */
+{
+ "extends": "./tsconfig-build.json",
+ "compilerOptions": {
+ "types": ["node", "jasmine"],
+ },
+}
diff --git a/packages/types.d.ts b/packages/types.d.ts
index 530beb389c..16e7e07562 100644
--- a/packages/types.d.ts
+++ b/packages/types.d.ts
@@ -9,13 +9,18 @@
// This file contains all ambient imports needed to compile the packages/ source code
///
-///
-///
///
///
///
///
+// Do not included "node" and "jasmine" types here as we don't
+// want these ambient types to be included everywhere.
+// Tests will bring in ambient node & jasmine types with
+// /packages/tsconfig-test.json when `testonly = True` is set
+// and packages such as platform-server that need these types should
+// use `/// ` in their main entry points
+
declare let isNode: boolean;
declare let isBrowser: boolean;
diff --git a/tools/defaults.bzl b/tools/defaults.bzl
index 19cfa66d52..5bf3c3b1aa 100644
--- a/tools/defaults.bzl
+++ b/tools/defaults.bzl
@@ -5,7 +5,8 @@ load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library", _ts
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
load("//packages/bazel/src:ng_module.bzl", _internal_global_ng_module = "internal_global_ng_module")
-DEFAULT_TSCONFIG = "//packages:tsconfig-build.json"
+DEFAULT_TSCONFIG_BUILD = "//packages:tsconfig-build.json"
+DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test.json"
DEFAULT_NODE_MODULES = "@angular_deps//:node_modules"
# Packages which are versioned together on npm
@@ -39,27 +40,36 @@ PKG_GROUP_REPLACEMENTS = {
]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES]),
}
-def ts_library(tsconfig = None, node_modules = DEFAULT_NODE_MODULES, **kwargs):
+def ts_library(tsconfig = None, node_modules = DEFAULT_NODE_MODULES, testonly = False, **kwargs):
if not tsconfig:
- tsconfig = DEFAULT_TSCONFIG
- _ts_library(tsconfig = tsconfig, node_modules = node_modules, **kwargs)
+ if testonly:
+ tsconfig = DEFAULT_TSCONFIG_TEST
+ else:
+ tsconfig = DEFAULT_TSCONFIG_BUILD
+ _ts_library(tsconfig = tsconfig, node_modules = node_modules, testonly = testonly, **kwargs)
-def ng_module(name, tsconfig = None, entry_point = None, node_modules = DEFAULT_NODE_MODULES, **kwargs):
+def ng_module(name, tsconfig = None, entry_point = None, node_modules = DEFAULT_NODE_MODULES, testonly = False, **kwargs):
if not tsconfig:
- tsconfig = DEFAULT_TSCONFIG
+ if testonly:
+ tsconfig = DEFAULT_TSCONFIG_TEST
+ else:
+ tsconfig = DEFAULT_TSCONFIG_BUILD
if not entry_point:
entry_point = "public_api.ts"
- _ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, node_modules = node_modules, **kwargs)
+ _ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, node_modules = node_modules, testonly = testonly, **kwargs)
# ivy_ng_module behaves like ng_module, and under --define=compile=legacy it runs ngc with global
# analysis but produces Ivy outputs. Under other compile modes, it behaves as ng_module.
# TODO(alxhub): remove when ngtsc supports the same use cases.
-def ivy_ng_module(name, tsconfig = None, entry_point = None, **kwargs):
+def ivy_ng_module(name, tsconfig = None, entry_point = None, testonly = False, **kwargs):
if not tsconfig:
- tsconfig = DEFAULT_TSCONFIG
+ if testonly:
+ tsconfig = DEFAULT_TSCONFIG_TEST
+ else:
+ tsconfig = DEFAULT_TSCONFIG_BUILD
if not entry_point:
entry_point = "public_api.ts"
- _internal_global_ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, **kwargs)
+ _internal_global_ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, testonly = testonly, **kwargs)
def ng_package(name, readme_md = None, license_banner = None, **kwargs):
if not readme_md:
diff --git a/tools/symbol-extractor/BUILD.bazel b/tools/symbol-extractor/BUILD.bazel
index fbdd5b7c53..4716f25f9c 100644
--- a/tools/symbol-extractor/BUILD.bazel
+++ b/tools/symbol-extractor/BUILD.bazel
@@ -5,6 +5,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "lib",
+ testonly = True,
srcs = glob(
["**/*.ts"],
exclude = [
diff --git a/tools/symbol-extractor/index.bzl b/tools/symbol-extractor/index.bzl
index 1e64b4da6c..de5583f760 100644
--- a/tools/symbol-extractor/index.bzl
+++ b/tools/symbol-extractor/index.bzl
@@ -28,6 +28,7 @@ def js_expected_symbol_test(name, src, golden, **kwargs):
nodejs_binary(
name = name + ".accept",
+ testonly = True,
data = all_data,
entry_point = entry_point,
templated_args = ["$(location %s)" % src, "$(location %s)" % golden, "--accept"],
diff --git a/tools/ts-api-guardian/index.bzl b/tools/ts-api-guardian/index.bzl
index e982c0550c..f5a170b3c5 100644
--- a/tools/ts-api-guardian/index.bzl
+++ b/tools/ts-api-guardian/index.bzl
@@ -50,6 +50,7 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
nodejs_binary(
name = name + ".accept",
+ testonly = True,
data = data,
node_modules = "@ts-api-guardian_runtime_deps//:node_modules",
entry_point = "angular/tools/ts-api-guardian/bin/ts-api-guardian",