Skip to content

Commit 499e303

Browse files
IgorMinarAndrewKushnir
authored andcommitted
test(ivy): add global utils to the public_api_guard test (angular#27008)
This API is part of our public api surface and needs to be monitored by the public_api_guard. I also had to go back and mark all of the exported functions with @publicapi jsdoc tag. PR Close angular#27008
1 parent e618032 commit 499e303

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

packages/core/src/render3/discovery_utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import {NodeInjector} from './view_engine_compatibility';
3333
* the component instance is exists in a template.
3434
* If a directive instance is used then it will return the
3535
* component that contains that directive in it's template.
36+
*
37+
* @publicApi
3638
*/
3739
export function getComponent<T = {}>(target: {}): T|null {
3840
const context = loadContext(target) !;
@@ -60,6 +62,8 @@ export function getComponent<T = {}>(target: {}): T|null {
6062
*
6163
* This will only return a component instance of the DOM node
6264
* contains an instance of a component on it.
65+
*
66+
* @publicApi
6367
*/
6468
export function getHostComponent<T = {}>(target: {}): T|null {
6569
const context = loadContext(target);
@@ -74,6 +78,8 @@ export function getHostComponent<T = {}>(target: {}): T|null {
7478
/**
7579
* Returns the `RootContext` instance that is associated with
7680
* the application where the target is situated.
81+
*
82+
* @publicApi
7783
*/
7884
export function getRootContext(target: LViewData | {}): RootContext {
7985
const lViewData = Array.isArray(target) ? target : loadContext(target) !.lViewData;
@@ -84,6 +90,8 @@ export function getRootContext(target: LViewData | {}): RootContext {
8490
/**
8591
* Returns a list of all the components in the application
8692
* that are have been bootstrapped.
93+
*
94+
* @publicApi
8795
*/
8896
export function getRootComponents(target: {}): any[] {
8997
return [...getRootContext(target).components];
@@ -92,6 +100,8 @@ export function getRootComponents(target: {}): any[] {
92100
/**
93101
* Returns the injector instance that is associated with
94102
* the element, component or directive.
103+
*
104+
* @publicApi
95105
*/
96106
export function getInjector(target: {}): Injector {
97107
const context = loadContext(target);
@@ -103,6 +113,8 @@ export function getInjector(target: {}): Injector {
103113
/**
104114
* Returns a list of all the directives that are associated
105115
* with the underlying target element.
116+
*
117+
* @publicApi
106118
*/
107119
export function getDirectives(target: {}): Array<{}> {
108120
const context = loadContext(target) !;
@@ -117,6 +129,8 @@ export function getDirectives(target: {}): Array<{}> {
117129
/**
118130
* Returns LContext associated with a target passed as an argument.
119131
* Throws if a given target doesn't have associated LContext.
132+
*
133+
* @publicApi
120134
*/
121135
export function loadContext(target: {}): LContext {
122136
const context = getContext(target);
@@ -133,6 +147,8 @@ export function loadContext(target: {}): LContext {
133147
* reaching the root `LViewData`.
134148
*
135149
* @param componentOrView any component or view
150+
*
151+
* @publicApi
136152
*/
137153
export function getRootView(componentOrView: LViewData | {}): LViewData {
138154
let lViewData: LViewData;
@@ -151,6 +167,8 @@ export function getRootView(componentOrView: LViewData | {}): LViewData {
151167

152168
/**
153169
* Retrieve map of local references (local reference name => element or directive instance).
170+
*
171+
* @publicApi
154172
*/
155173
export function getLocalRefs(target: {}): {[key: string]: any} {
156174
const context = loadContext(target) !;

packages/core/src/render3/global_utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {global} from '../util';
9-
import {getComponent, getDirectives, getHostComponent, getInjector, getRootComponents} from './discovery_utils';
10-
import {getPlayers} from './players';
9+
import {getComponent, getDirectives, getHostComponent, getInjector, getPlayers, getRootComponents} from './global_utils_api';
1110

1211
/**
1312
* This file introduces series of globally accessible debug tools
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/**
10+
* @fileoverview
11+
* This file is the index file collecting all of the symbols published on the global.ng namespace.
12+
*
13+
* The reason why this file/module is separate global_utils.ts file is that we use this file
14+
* to generate a d.ts file containing all the published symbols that is then compared to the golden
15+
* file in the public_api_guard test.
16+
*/
17+
18+
export {getComponent, getDirectives, getHostComponent, getInjector, getRootComponents} from './discovery_utils';
19+
export {getPlayers} from './players';

packages/core/src/render3/players.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export function addPlayer(
5050
* This function will only return players that have been added to the ref instance using
5151
* `addPlayer` or any players that are active through any template styling bindings
5252
* (`[style]`, `[style.prop]`, `[class]` and `[class.name]`).
53+
*
54+
* @publicApi
5355
*/
5456
export function getPlayers(ref: ComponentInstance | DirectiveInstance | HTMLElement): Player[] {
5557
const context = getContext(ref);

packages/core/test/render3/global_utils_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
import {getComponent, getDirectives, getHostComponent, getInjector, getRootComponents} from '../../src/render3/discovery_utils';
99
import {GLOBAL_PUBLISH_EXPANDO_KEY, GlobalDevModeContainer, publishDefaultGlobalUtils, publishGlobalUtil} from '../../src/render3/global_utils';
10-
import {global} from '../../src/util';
1110
import {getPlayers} from '../../src/render3/players';
11+
import {global} from '../../src/util';
1212

1313
describe('global utils', () => {
1414
describe('publishGlobalUtil', () => {

tools/public_api_guard/BUILD.bazel

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
load("//tools/ts-api-guardian:index.bzl", "ts_api_guardian_test")
12
load(":public_api_guard.bzl", "generate_targets")
23

3-
generate_targets(glob(["**/*.d.ts"]))
4+
generate_targets(glob(["*/**/*.d.ts"]))
5+
6+
ts_api_guardian_test(
7+
name = "ng_global_utils_api",
8+
actual = "angular/packages/core/src/render3/global_utils_api.d.ts",
9+
data = [
10+
":global_utils.d.ts",
11+
"//packages/core",
12+
],
13+
golden = "angular/tools/public_api_guard/global_utils.d.ts",
14+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export declare function getComponent<T = {}>(target: {}): T | null;
2+
3+
export declare function getDirectives(target: {}): Array<{}>;
4+
5+
export declare function getHostComponent<T = {}>(target: {}): T | null;
6+
7+
export declare function getInjector(target: {}): Injector;
8+
9+
export declare function getPlayers(ref: ComponentInstance | DirectiveInstance | HTMLElement): Player[];
10+
11+
export declare function getRootComponents(target: {}): any[];

0 commit comments

Comments
 (0)