xpl / ololog

A better console.log for the log-driven debugging junkies
https://www.npmjs.com/package/ololog
The Unlicense
215 stars 8 forks source link

React native support? #31

Open evelant opened 2 years ago

evelant commented 2 years ago

It would be nice to use Ololog in react-native. Right now it seems it primary doesn't work because the browser check is incorrect so react-native is detected as a browser and undefined properties are read.

is_browser = (typeof window !== 'undefined') && (window.window === window) && window.navigator

should be

is_browser = (typeof window !== 'undefined' && typeof document !== 'undefined') && (window.window === window) && window.navigator

in ololog and all of it's dependencies, otherwise react-native gets detected as a browser environment and crashes accessing undefined APIs.

You can also test for react-native directly with

isReactNative  = (typeof navigator != 'undefined' && navigator.product == 'ReactNative'),

It also seems that stacktracey is incompatible with react-native, primarily because of:

  1. react-native does not support synchronous XMLHttpRequests
  2. get-source assumes some node APIs exist that don't on react-native, namely process.cwd is undefined.

How feasible do you think it is to make ololog support react-native out of the box? If the browser checks are fixed it seems to be mostly working except for source mapping. When I tried to async load the source map from metro (react-native's bundler) it just hangs because the source map is enormous. I'm not really familiar with how source mapping works and editing non typescript JS written by somebody else is challenging so I'm not sure if I'm able to figure it out right now.

GollyJer commented 1 year ago

react-native support would be awesome!

@evelant did you find any other solution?

evelant commented 1 year ago

@GollyJer I manually patched it with pnpm's patchedPackages feature. Since then I've given up on this since it's unmaintained and the code is really inscrutable. Instead now I emit all my logs as JSON and use https://github.com/brocode/fblog to pretty print the json in the terminal.