Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use process.browser instead of checking for window #311

Closed
wants to merge 1 commit into from

Conversation

jeremyruppel
Copy link

The browserify version of process sets process.browser = true that we can use instead of checking for the existence of window. This plays nice with transforms like bpb that replace process.browser with a constant which enables unreachable code branches to be removed during bundling. I don't have first-hand experience with nw.js but the project says it has complete support for all Node.js APIs so this should also fix #301 /cc @amoussard @fleg @adam-lynch.

@adam-lynch
Copy link

Just tested and this works for my use case. I'm a little confused by it, like why browserify comes into it at all... like does this cover all use cases? E.g. with webpack, just plain browser, etc.

@jeremyruppel
Copy link
Author

As far as I can tell, bunyan currently doesn't bundle with webpack or work in the browser straight up anyways. The README only mentions browserify compatibility.

@adam-lynch
Copy link

Yeah, I'm not sure what it supports myself. @trentm?

@jaxer
Copy link

jaxer commented Dec 17, 2015

+1 for this change. that would make bunyan usable in electron for instance

@trentm
Copy link
Owner

trentm commented Feb 12, 2016

@jeremyruppel @adam-lynch @jaxer @fleg Sorry for the delays, all. (#335 for some details on project maint.)

I'm looking at the current Bunyan browser-related issues. This one (#311) suggests if (!process.browser) {, #302 suggests if (typeof (process) !== 'undefined') {, and #310 suggests if (typeof (global) === 'object') {.

I'm guessing that attempting to process.browser would throw in NW (where process is undefined?).

global seems a little inspecific and possibly brittle -- could some other JS code in a bundle not set 'global'?

I suppose the same could be true of some other JS code in a bundle setting process. Perhaps we could be more specific about an "is this node" check by looking for process.versions.node:

> process.versions
{ http_parser: '1.1',
  node: '0.10.42',
  v8: '3.14.5.9',
  ares: '1.9.0-DEV',
...

If I put a potential change in a branch, would any of you be able to test: nw, electron, browserify, others?


Question 2: The else-part of the if block has this:

    var os = {
        hostname: function () {
            return window.location.host;
        }
    };

Will that work with NW? IOW, does nw.js define window at all?


As to my intentions for bunyan: I'm happy to have it work with NW, browserify and other environments. I just don't use those envs so I'm ignorant about what works there.

Any testing or ... ownership of that functionality in node-bunyan by others (any of you interested?) would be a great help.


Question 4: Do any of you have suggestions for ways to do automated testing of Bunyan working in any of these environments?

@adam-lynch
Copy link

I'm guessing that attempting to process.browser would throw in NW (where process is undefined?).

process is defined. It's a little different but don't think you need to worry about that.

global seems a little inspecific and possibly brittle -- could some other JS code in a bundle not set 'global'?

It's used very commonly for this kind of thing as far as I know.

If I put a potential change in a branch, would any of you be able to test: nw, electron, browserify, others?

Yes, NW.js.

Will that work with NW? IOW, does nw.js define window at all?

Not sure what IOW stands for but window in NW.js is just like the window in the browser.

Question 4: Do any of you have suggestions for ways to do automated testing of Bunyan working in any of these environments?

Hmm, tricky. I guess you could run an NW.js that uses bunyan, kill it after a timeout and check if the log file exists?

trentm added a commit that referenced this pull request Feb 21, 2016
Contributions by Adam Lynch (#310), Jeremy Ruppel (#311),
and Aleksey Timchenko (#302).
@trentm
Copy link
Owner

trentm commented Feb 21, 2016

@adam-lynch Thanks for the comments, that helped clarify for me. I would appreciate a sanity check from you or other NW.js users with cd7dc6a#diff-07b7b7054e46821313709b956b86ec21 (the latest commit in #master).

Let me know if you need a published npm release to test it.

If others are able to test in a browser env (browserify or webpack or other), that would be helpful.

This will be in [email protected], assuming it works. Thanks and sorry for the extreme delays.

@fleg
Copy link

fleg commented Feb 21, 2016

Tested on [email protected], it's working like a charm.

Question 4: Do any of you have suggestions for ways to do automated testing of Bunyan working in any of these environments?

Maybe run all tests under nw.
I'm not sure about nodeunit, but it looks like we can run mocha under nw.

@trentm trentm mentioned this pull request Feb 22, 2016
@trentm
Copy link
Owner

trentm commented Feb 22, 2016

@fleg Thanks!

@trentm
Copy link
Owner

trentm commented Feb 22, 2016

published version 1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bunyan and Node-Webkit
5 participants