zertosh / invariant

invariant
MIT License
1.22k stars 70 forks source link

Support for react-native #11

Closed alex-mcleod closed 8 years ago

alex-mcleod commented 8 years ago

Setting the DEV var causes release builds to fail on react native. I discovered this while using the react-intl library, which has a dependency on this library. So, I've removed usage of DEV to make this library compatible with react-native.

zertosh commented 8 years ago

The main point of this lib is to cache the value of process.env.NODE_ENV. See https://github.com/zertosh/invariant#node. Is the problem with the name __DEV__? How can I repro?

ms88privat commented 8 years ago

I want to start using this package with react-native too. I did not test it in production mode yet. But I know, that React-Native has a global __DEV__ variable by default and no process.env.NODE_EN I think.

zertosh commented 8 years ago

The react-native package already has an invariant haste module. Isn't it reachable from user code?

alex-mcleod commented 8 years ago

@zertosh it is the naming of the __DEV__ variable which is causing the issue, so perhaps the best solution in retrospect would be to just change the name of that variable to __DEVELOPMENT__. React native does have it's own invariant module, however this version of invariant is a dependency for the react-intl package which I wished to use with react-native.

zertosh commented 8 years ago

How about this then?

var NODE_ENV = process.env.NODE_ENV;

var invariant = function(condition, format, a, b, c, d, e, f) {
  if (NODE_ENV !== 'production') {
    if (format === undefined) {
      throw new Error('invariant requires an error message argument');
    }
  }

If that works, then please squash the commits and don't include a version bump.

alex-mcleod commented 8 years ago

That works. Have updated and squashed the commits.

zertosh commented 8 years ago

thanks! published as invariant@2.2.1