build: refactor ambient node & jasmine types so they are only included where needed (#25491)

PR Close #25491
This commit is contained in:
Greg Magolan 2018-08-14 16:18:26 -07:00 committed by Jason Aden
parent 9ee6702fa9
commit 9605456b66
21 changed files with 69 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package(default_visibility = ["//visibility:public"])
exports_files([
"tsconfig-build.json",
"tsconfig-test.json",
"tsconfig.json",
])

View File

@ -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');
}

View File

@ -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",

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
// Must be imported first, because Angular decorators throw on load.
import 'reflect-metadata';

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
export {ResourceLoader} from './src/api';
export {BaseDefDecoratorHandler} from './src/base_def';
export {ComponentDecoratorHandler} from './src/component';

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
export {FactoryGenerator} from './src/generator';
export {GeneratedFactoryHostWrapper} from './src/host';
export {FactoryInfo, generatedFactoryTransform} from './src/transform';

View File

@ -6,5 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
export {TypeScriptReflectionHost, filterToMembersWithDecorator, findMember, reflectObjectLiteral, reflectTypeEntityToDeclaration} from './src/reflector';
export {AbsoluteReference, ImportMode, Reference, ResolvedReference, ResolvedValue, isDynamicValue, staticallyResolve} from './src/resolver';

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
import * as path from 'path';
const TS_DTS_EXTENSION = /(\.d)?\.ts$/;

View File

@ -13,6 +13,7 @@ UTILS = [
ts_library(
name = "test_utils",
testonly = True,
srcs = UTILS,
visibility = [
"//packages/compiler-cli/test:__subpackages__",

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
/**
* @module
* @description

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="jasmine" />
/**
* @module
* @description

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
/**
* @module
* @description

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="jasmine" />
/**
* @module
* @description

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/// <reference types="node" />
/**
* @module
* @description

View File

@ -6,6 +6,7 @@ load("//tools:defaults.bzl", "ng_module")
ng_module(
name = "testing",
testonly = True,
srcs = glob(
["**/*.ts"],
),

View File

@ -0,0 +1,9 @@
/**
* Root tsconfig file for use in all tests.
*/
{
"extends": "./tsconfig-build.json",
"compilerOptions": {
"types": ["node", "jasmine"],
},
}

9
packages/types.d.ts vendored
View File

@ -9,13 +9,18 @@
// This file contains all ambient imports needed to compile the packages/ source code
/// <reference types="hammerjs" />
/// <reference types="jasmine" />
/// <reference types="node" />
/// <reference types="zone.js" />
/// <reference path="./es6-subset.d.ts" />
/// <reference path="./goog.d.ts" />
/// <reference path="./system.d.ts" />
// 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 `/// <reference types="x">` in their main entry points
declare let isNode: boolean;
declare let isBrowser: boolean;

View File

@ -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:

View File

@ -5,6 +5,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "lib",
testonly = True,
srcs = glob(
["**/*.ts"],
exclude = [

View File

@ -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"],

View File

@ -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",