Skip to content

Commit

Permalink
chore(core): remove no longer used isNode check (#12025)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF authored Sep 14, 2023
2 parents cb3da33 + bf5b5c9 commit 0e5556d
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 384 deletions.
44 changes: 0 additions & 44 deletions packages/auth/src/urlListener.native.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/auth/src/urlListener.ts

This file was deleted.

7 changes: 2 additions & 5 deletions packages/core/__tests__/JS-browser-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* jsdom (which is also the default) Since this is allowed per test file
* and not per test or describe, we have two tests, one for node and other for browser
*/
import { browserOrNode } from '../src/Util/JS';
import { isBrowser } from '../src/Util/JS';

describe('JS browserOrNode build test', () => {
// Prevent Jest test resolves Node.js version from the global `process` of the
Expand All @@ -23,9 +23,6 @@ describe('JS browserOrNode build test', () => {
});

test('when its browser ', () => {
expect(browserOrNode()).toStrictEqual({
isBrowser: true,
isNode: false,
});
expect(isBrowser()).toBe(true);
});
});
18 changes: 0 additions & 18 deletions packages/core/__tests__/JS-node-runtime.test.ts

This file was deleted.

83 changes: 0 additions & 83 deletions packages/core/src/OAuthHelper/FacebookOAuth.ts

This file was deleted.

97 changes: 0 additions & 97 deletions packages/core/src/OAuthHelper/GoogleOAuth.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core/src/OAuthHelper/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/core/src/RNComponents/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { browserOrNode } from '../Util/JS';
import { isBrowser } from '../Util/JS';
import { StorageHelper } from '../StorageHelper';

export const Linking = {};
export const AppState = {
addEventListener: (action: any, handler: any) => undefined,
currentState: 'active'
currentState: 'active',
};

// if not in react native, just use local storage
export const AsyncStorage = browserOrNode().isBrowser
export const AsyncStorage = isBrowser()
? new StorageHelper().getStorage()
: undefined;
4 changes: 2 additions & 2 deletions packages/core/src/ServiceWorker/ServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* and limitations under the License.
*/
import { ConsoleLogger as Logger } from '../Logger';
import { browserOrNode } from '../Util/JS';
import { isBrowser } from '../Util/JS';
import { Amplify } from '../Amplify';
import { asserts } from '../Util/errors/AssertError';
import { AmplifyError } from '../Util/Errors';
Expand Down Expand Up @@ -136,7 +136,7 @@ export class ServiceWorkerClass {
});
this._publicKey = publicKey;
return new Promise((resolve, reject) => {
if (browserOrNode().isBrowser) {
if (isBrowser()) {
asserts(this._registration !== undefined, {
name: SERVICE_WORKER_EXCEPTION,
message: 'Service Worker registration is undefined',
Expand Down
15 changes: 2 additions & 13 deletions packages/core/src/Util/JS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,8 @@ export const isWebWorker = () => {
);
};

export const browserOrNode = () => {
const isBrowser =
typeof window !== 'undefined' && typeof window.document !== 'undefined';
const isNode =
typeof process !== 'undefined' &&
process.versions != null &&
process.versions.node != null;

return {
isBrowser,
isNode,
};
};
export const isBrowser = () =>
typeof window !== 'undefined' && typeof window.document !== 'undefined';

/**
* transfer the first letter of the keys to lowercase
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/Util/Reachability.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import Observable, { ZenObservable } from 'zen-observable-ts';
import { browserOrNode, isWebWorker } from './JS';
import { isWebWorker } from './JS';

type NetworkStatus = {
online: boolean;
Expand All @@ -13,10 +13,6 @@ export default class ReachabilityNavigator implements Reachability {
> = [];

networkMonitor(netInfo?: any): Observable<NetworkStatus> {
if (browserOrNode().isNode) {
return Observable.from([{ online: true }]);
}

const globalObj = isWebWorker() ? self : window;

return new Observable(observer => {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/libraryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ utils for use throughout the library.
*/
// JS utilities
export {
browserOrNode,
isBrowser,
filenameToContentType,
generateRandomString,
isEmpty,
Expand Down Expand Up @@ -96,7 +96,6 @@ export {
AmplifyError,
AmplifyErrorString,
} from './Util/Errors';
export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
export { AppState, AsyncStorage, Linking } from './RNComponents';
export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
export {
Expand Down
Loading

0 comments on commit 0e5556d

Please sign in to comment.