build: refactor ambient node & jasmine types so they are only included where needed (#25491)
PR Close #25491
This commit is contained in:
parent
9ee6702fa9
commit
9605456b66
|
@ -2,6 +2,7 @@ package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
exports_files([
|
exports_files([
|
||||||
"tsconfig-build.json",
|
"tsconfig-build.json",
|
||||||
|
"tsconfig-test.json",
|
||||||
"tsconfig.json",
|
"tsconfig.json",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ import {AUTO_STYLE, AnimationEvent, AnimationPlayer, NoopAnimationPlayer, ɵAnim
|
||||||
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
|
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
|
||||||
import {AnimationDriver} from '../../src/render/animation_driver';
|
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() {
|
export function isBrowser() {
|
||||||
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
|
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ jasmine_node_test(
|
||||||
|
|
||||||
ts_library(
|
ts_library(
|
||||||
name = "example_spec_lib",
|
name = "example_spec_lib",
|
||||||
|
testonly = True,
|
||||||
srcs = ["example_package.spec.ts"],
|
srcs = ["example_package.spec.ts"],
|
||||||
deps = ["//packages:types"],
|
deps = ["//packages:types"],
|
||||||
)
|
)
|
||||||
|
@ -55,6 +56,7 @@ jasmine_node_test(
|
||||||
|
|
||||||
nodejs_binary(
|
nodejs_binary(
|
||||||
name = "example_package.accept",
|
name = "example_package.accept",
|
||||||
|
testonly = True,
|
||||||
data = [
|
data = [
|
||||||
"example_package.golden",
|
"example_package.golden",
|
||||||
":example_spec_lib",
|
":example_spec_lib",
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
// Must be imported first, because Angular decorators throw on load.
|
// Must be imported first, because Angular decorators throw on load.
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
export {ResourceLoader} from './src/api';
|
export {ResourceLoader} from './src/api';
|
||||||
export {BaseDefDecoratorHandler} from './src/base_def';
|
export {BaseDefDecoratorHandler} from './src/base_def';
|
||||||
export {ComponentDecoratorHandler} from './src/component';
|
export {ComponentDecoratorHandler} from './src/component';
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
export {FactoryGenerator} from './src/generator';
|
export {FactoryGenerator} from './src/generator';
|
||||||
export {GeneratedFactoryHostWrapper} from './src/host';
|
export {GeneratedFactoryHostWrapper} from './src/host';
|
||||||
export {FactoryInfo, generatedFactoryTransform} from './src/transform';
|
export {FactoryInfo, generatedFactoryTransform} from './src/transform';
|
||||||
|
|
|
@ -6,5 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
export {TypeScriptReflectionHost, filterToMembersWithDecorator, findMember, reflectObjectLiteral, reflectTypeEntityToDeclaration} from './src/reflector';
|
export {TypeScriptReflectionHost, filterToMembersWithDecorator, findMember, reflectObjectLiteral, reflectTypeEntityToDeclaration} from './src/reflector';
|
||||||
export {AbsoluteReference, ImportMode, Reference, ResolvedReference, ResolvedValue, isDynamicValue, staticallyResolve} from './src/resolver';
|
export {AbsoluteReference, ImportMode, Reference, ResolvedReference, ResolvedValue, isDynamicValue, staticallyResolve} from './src/resolver';
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const TS_DTS_EXTENSION = /(\.d)?\.ts$/;
|
const TS_DTS_EXTENSION = /(\.d)?\.ts$/;
|
||||||
|
|
|
@ -13,6 +13,7 @@ UTILS = [
|
||||||
|
|
||||||
ts_library(
|
ts_library(
|
||||||
name = "test_utils",
|
name = "test_utils",
|
||||||
|
testonly = True,
|
||||||
srcs = UTILS,
|
srcs = UTILS,
|
||||||
visibility = [
|
visibility = [
|
||||||
"//packages/compiler-cli/test:__subpackages__",
|
"//packages/compiler-cli/test:__subpackages__",
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module
|
* @module
|
||||||
* @description
|
* @description
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="jasmine" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module
|
* @module
|
||||||
* @description
|
* @description
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module
|
* @module
|
||||||
* @description
|
* @description
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="jasmine" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module
|
* @module
|
||||||
* @description
|
* @description
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module
|
* @module
|
||||||
* @description
|
* @description
|
||||||
|
|
|
@ -6,6 +6,7 @@ load("//tools:defaults.bzl", "ng_module")
|
||||||
|
|
||||||
ng_module(
|
ng_module(
|
||||||
name = "testing",
|
name = "testing",
|
||||||
|
testonly = True,
|
||||||
srcs = glob(
|
srcs = glob(
|
||||||
["**/*.ts"],
|
["**/*.ts"],
|
||||||
),
|
),
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Root tsconfig file for use in all tests.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig-build.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": ["node", "jasmine"],
|
||||||
|
},
|
||||||
|
}
|
|
@ -9,13 +9,18 @@
|
||||||
// This file contains all ambient imports needed to compile the packages/ source code
|
// This file contains all ambient imports needed to compile the packages/ source code
|
||||||
|
|
||||||
/// <reference types="hammerjs" />
|
/// <reference types="hammerjs" />
|
||||||
/// <reference types="jasmine" />
|
|
||||||
/// <reference types="node" />
|
|
||||||
/// <reference types="zone.js" />
|
/// <reference types="zone.js" />
|
||||||
/// <reference path="./es6-subset.d.ts" />
|
/// <reference path="./es6-subset.d.ts" />
|
||||||
/// <reference path="./goog.d.ts" />
|
/// <reference path="./goog.d.ts" />
|
||||||
/// <reference path="./system.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 isNode: boolean;
|
||||||
declare let isBrowser: boolean;
|
declare let isBrowser: boolean;
|
||||||
|
|
||||||
|
|
|
@ -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: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")
|
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"
|
DEFAULT_NODE_MODULES = "@angular_deps//:node_modules"
|
||||||
|
|
||||||
# Packages which are versioned together on npm
|
# Packages which are versioned together on npm
|
||||||
|
@ -39,27 +40,36 @@ PKG_GROUP_REPLACEMENTS = {
|
||||||
]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES]),
|
]""" % ",\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:
|
if not tsconfig:
|
||||||
tsconfig = DEFAULT_TSCONFIG
|
if testonly:
|
||||||
_ts_library(tsconfig = tsconfig, node_modules = node_modules, **kwargs)
|
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:
|
if not tsconfig:
|
||||||
tsconfig = DEFAULT_TSCONFIG
|
if testonly:
|
||||||
|
tsconfig = DEFAULT_TSCONFIG_TEST
|
||||||
|
else:
|
||||||
|
tsconfig = DEFAULT_TSCONFIG_BUILD
|
||||||
if not entry_point:
|
if not entry_point:
|
||||||
entry_point = "public_api.ts"
|
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
|
# 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.
|
# analysis but produces Ivy outputs. Under other compile modes, it behaves as ng_module.
|
||||||
# TODO(alxhub): remove when ngtsc supports the same use cases.
|
# 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:
|
if not tsconfig:
|
||||||
tsconfig = DEFAULT_TSCONFIG
|
if testonly:
|
||||||
|
tsconfig = DEFAULT_TSCONFIG_TEST
|
||||||
|
else:
|
||||||
|
tsconfig = DEFAULT_TSCONFIG_BUILD
|
||||||
if not entry_point:
|
if not entry_point:
|
||||||
entry_point = "public_api.ts"
|
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):
|
def ng_package(name, readme_md = None, license_banner = None, **kwargs):
|
||||||
if not readme_md:
|
if not readme_md:
|
||||||
|
|
|
@ -5,6 +5,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
|
||||||
|
|
||||||
ts_library(
|
ts_library(
|
||||||
name = "lib",
|
name = "lib",
|
||||||
|
testonly = True,
|
||||||
srcs = glob(
|
srcs = glob(
|
||||||
["**/*.ts"],
|
["**/*.ts"],
|
||||||
exclude = [
|
exclude = [
|
||||||
|
|
|
@ -28,6 +28,7 @@ def js_expected_symbol_test(name, src, golden, **kwargs):
|
||||||
|
|
||||||
nodejs_binary(
|
nodejs_binary(
|
||||||
name = name + ".accept",
|
name = name + ".accept",
|
||||||
|
testonly = True,
|
||||||
data = all_data,
|
data = all_data,
|
||||||
entry_point = entry_point,
|
entry_point = entry_point,
|
||||||
templated_args = ["$(location %s)" % src, "$(location %s)" % golden, "--accept"],
|
templated_args = ["$(location %s)" % src, "$(location %s)" % golden, "--accept"],
|
||||||
|
|
|
@ -50,6 +50,7 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
|
||||||
|
|
||||||
nodejs_binary(
|
nodejs_binary(
|
||||||
name = name + ".accept",
|
name = name + ".accept",
|
||||||
|
testonly = True,
|
||||||
data = data,
|
data = data,
|
||||||
node_modules = "@ts-api-guardian_runtime_deps//:node_modules",
|
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",
|
||||||
|
|
Loading…
Reference in New Issue