Skip to content

Commit

Permalink
fix: add check for process global to exist (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunSHamilton authored Oct 30, 2023
1 parent 038b9b9 commit 695220e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .changeset/funny-jars-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@near-js/accounts": patch
"near-api-js": patch
"@near-js/providers": patch
"@near-js/utils": patch
---

add check for global 'process' object
2 changes: 1 addition & 1 deletion packages/accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class Account {
* @param beneficiaryId The NEAR account that will receive the remaining Ⓝ balance from the account being deleted
*/
async deleteAccount(beneficiaryId: string) {
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.log('Deleting an account does not automatically transfer NFTs and FTs to the beneficiary address. Ensure to transfer assets before deleting.');
}
return this.signAndSendTransaction({
Expand Down
2 changes: 1 addition & 1 deletion packages/near-api-js/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function connect(config: ConnectConfig): Promise<Near> {
keyPathStore,
config.keyStore || config.deps?.keyStore
], { writeKeyStoreIndex: 1 });
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.log(`Loaded master account ${accountKeyFile[0]} key from ${config.keyPath} with public key = ${keyPair.getPublicKey()}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src/fetch_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ConnectionInfo {
headers?: { [key: string]: string | number };
}

const logWarning = (...args) => !process.env['NEAR_NO_LOGS'] && console.warn(...args);
const logWarning = (...args) => !(typeof process === 'object' && process.env['NEAR_NO_LOGS']) && console.warn(...args);

export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, json?: string): Promise<any> {
let connectionInfo: ConnectionInfo = { url: null };
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class JsonRpcProvider extends Provider {
return response;
} catch (error) {
if (error.type === 'TimeoutError') {
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.warn(`Retrying request to ${method} as it has timed out`, params);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/errors/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function logWarning(...args: any[]): void {
if (!process.env['NEAR_NO_LOGS']){
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])){
console.warn(...args);
}
}
2 changes: 1 addition & 1 deletion packages/utils/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FinalExecutionOutcome } from '@near-js/types';

import { parseRpcError } from './errors';

const SUPPRESS_LOGGING = !!process.env.NEAR_NO_LOGS;
const SUPPRESS_LOGGING = !!(typeof process === 'object' && process.env.NEAR_NO_LOGS);

/**
* Parse and print details from a query execution response
Expand Down

0 comments on commit 695220e

Please sign in to comment.