Skip to content

Commit

Permalink
fix(core): Angular web detection and other minor changes (aws-amplify…
Browse files Browse the repository at this point in the history
  • Loading branch information
stocaaro authored Jun 14, 2023
1 parent a52ab28 commit c0cb9b9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/Platform/detection/Angular.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { processExists, windowExists } from './helpers';
import { documentExists, processExists, windowExists } from './helpers';

// Tested with @angular/core 16.0.0

export function angularWebDetect() {
return windowExists() && typeof window['ng'] !== 'undefined';
const angularVersionSetInDocument = Boolean(
documentExists() && document.querySelector('[ng-version]')
);
const angularContentSetInWindow = Boolean(
// @ts-ignore
windowExists() && typeof window['ng'] !== 'undefined'
);
return angularVersionSetInDocument || angularContentSetInWindow;
}

export function angularSSRDetect() {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Platform/detection/Expo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import { globalExists } from './helpers';
// Tested with expo 48 / react-native 0.71.3

export function expoDetect() {
// @ts-ignore
return globalExists() && typeof global['expo'] !== 'undefined';
}
1 change: 1 addition & 0 deletions packages/core/src/Platform/detection/Next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { globalExists, keyPrefixMatch, windowExists } from './helpers';
// Tested with next 13.4 / react 18.2

export function nextWebDetect() {
// @ts-ignore
return windowExists() && window['next'] && typeof window['next'] === 'object';
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Platform/detection/Nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { globalExists, windowExists } from './helpers';
export function nuxtWebDetect() {
return (
windowExists() &&
// @ts-ignore
(window['__NUXT__'] !== undefined || window['$nuxt'] !== undefined)
);
}

export function nuxtSSRDetect() {
// @ts-ignore
return globalExists() && typeof global['__NUXT_PATHS__'] !== 'undefined';
}
8 changes: 4 additions & 4 deletions packages/core/src/Platform/detection/React.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { documentExists, processExists, windowExists } from './helpers';
// Tested with react 18.2 - built using Vite

export function reactWebDetect() {
const elementKeyPrefixedWithReact = k => {
return k.startsWith('_react') || k.startsWith('__react');
const elementKeyPrefixedWithReact = key => {
return key.startsWith('_react') || key.startsWith('__react');
};
const elementIsReactEnabled = e => {
return Object.keys(e).find(elementKeyPrefixedWithReact);
const elementIsReactEnabled = element => {
return Object.keys(element).find(elementKeyPrefixedWithReact);
};
const allElementsWithId = () => Array.from(document.querySelectorAll('[id]'));

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Platform/detection/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export const processExists = () => {
return typeof process !== 'undefined';
};

export const keyPrefixMatch = (object, prefix) => {
export const keyPrefixMatch = (object: object, prefix: string) => {
return !!Object.keys(object).find(key => key.startsWith(prefix));
};

0 comments on commit c0cb9b9

Please sign in to comment.