2023-12-07 23:22:28 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2023-12-07 23:22:28 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-03-07 00:00:55 +00:00
|
|
|
import type {ɵFrameworkAgnosticGlobalUtils as GlobalUtils} from '@angular/core';
|
2023-12-07 23:22:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a handle to window.ng APIs (global angular debugging).
|
|
|
|
|
*
|
|
|
|
|
* @returns window.ng
|
|
|
|
|
*/
|
2025-03-07 00:00:55 +00:00
|
|
|
export const ngDebugClient = () => (window as any).ng as Partial<GlobalUtils>;
|
2023-12-07 23:22:28 +00:00
|
|
|
|
|
|
|
|
/**
|
2025-03-05 23:31:05 +00:00
|
|
|
* Type guard that checks whether a given debug API is supported within window.ng
|
2023-12-07 23:22:28 +00:00
|
|
|
*
|
2025-03-05 23:31:05 +00:00
|
|
|
* @returns whether the ng object includes the given debug API
|
2023-12-07 23:22:28 +00:00
|
|
|
*/
|
2025-03-07 00:00:55 +00:00
|
|
|
export function ngDebugApiIsSupported<T extends Partial<GlobalUtils>, K extends keyof T>(
|
|
|
|
|
ng: T,
|
|
|
|
|
api: K,
|
|
|
|
|
): ng is T & Record<K, NonNullable<T[K]>> {
|
2023-12-07 23:22:28 +00:00
|
|
|
return typeof ng[api] === 'function';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether Dependency Injection debug API is supported within window.ng
|
|
|
|
|
*
|
|
|
|
|
* @returns boolean
|
|
|
|
|
*/
|
|
|
|
|
export function ngDebugDependencyInjectionApiIsSupported(): boolean {
|
2025-03-05 23:31:05 +00:00
|
|
|
const ng = ngDebugClient();
|
|
|
|
|
if (!ngDebugApiIsSupported(ng, 'getInjector')) {
|
2025-03-04 22:49:53 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-05 23:31:05 +00:00
|
|
|
if (!ngDebugApiIsSupported(ng, 'ɵgetInjectorResolutionPath')) {
|
2023-12-07 23:22:28 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-05 23:31:05 +00:00
|
|
|
if (!ngDebugApiIsSupported(ng, 'ɵgetDependenciesFromInjectable')) {
|
2023-12-07 23:22:28 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-05 23:31:05 +00:00
|
|
|
if (!ngDebugApiIsSupported(ng, 'ɵgetInjectorProviders')) {
|
2023-12-07 23:22:28 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-05 23:31:05 +00:00
|
|
|
if (!ngDebugApiIsSupported(ng, 'ɵgetInjectorMetadata')) {
|
2023-12-07 23:22:28 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|