Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
[Technical Debt] top level console override (replacement for 2532) (#…
Browse files Browse the repository at this point in the history
…2537)

* top level console override

* use proxy and force // types
  • Loading branch information
W3stside authored Mar 16, 2022
1 parent fe71f05 commit c01d30a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ import flatMap from 'array.prototype.flatmap'

flat.shim()
flatMap.shim()

const originalConsole = window.console
// define a new console
const proxiedConsole = new Proxy(window.console, {
get(obj, prop: keyof Console) {
if (process.env.NODE_ENV !== 'production') {
return obj[prop]
} else {
return () => undefined
}
},
})

window.console = Object.assign({}, proxiedConsole, { force: originalConsole })
console = window.console
5 changes: 5 additions & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module '@metamask/jazzicon' {
declare module 'fortmatic'

interface Window {
console: Console & { force: Console }
walletLinkExtension?: any
ethereum?: {
isMetaMask?: true
Expand All @@ -19,6 +20,10 @@ interface Window {
web3?: Record<string, unknown>
}

interface Console extends Node.Console {
force: Node.Console
}

declare module 'content-hash' {
declare function decode(x: string): string
declare function getCodec(x: string): string
Expand Down

0 comments on commit c01d30a

Please sign in to comment.