Check for existence of process object (fix for v3)#414
Check for existence of process object (fix for v3)#414th0r wants to merge 4 commits intonodejs:mainfrom
process object (fix for v3)#414Conversation
next-tick-browser.js
Outdated
| setTimeout(function () { | ||
| fn.apply(null, args); | ||
| }, 0); | ||
| } |
There was a problem hiding this comment.
This is non-breaking for webpack users, right? But potentially breaking for browserify users.
There was a problem hiding this comment.
This is non-breaking for webpack users, right?
Yes, it's a slightly modified version of the webpack's polyfill.
But potentially breaking for
browserifyusers.
Well, potentially yes, but I don't think they will face any bugs. The only difference between these implementations is that the browserify's version drains queue synchronously on subsequent calls to nextTick.
There was a problem hiding this comment.
have you got a link to Browserify impl? I think Browserify version might be slightly faster and provide a better experience for users overall.
There was a problem hiding this comment.
There was a problem hiding this comment.
I prefer the browserify one, and more importantly this was designed to work with browserify first.
There was a problem hiding this comment.
test/browser/test-stream2-unpipe-drain.js fails if I use browserify's version of nextTick.
I think it happens because test runner uses it's own version of process.nextTick polyfill (which comes from browserify) and readable-stream uses our own version so we end up with two different queues of async events.
webpack's version doesn't have this problem.
There was a problem hiding this comment.
I've pushed a version with browserify's nextTick. If you want, you can try to fix this test - I don't have any more time which I can spend on it.
next-tick.js
Outdated
| @@ -0,0 +1,5 @@ | |||
| module.exports = nextTick; | |||
There was a problem hiding this comment.
| module.exports = nextTick; | |
| module.exports = process.nextTick; |
There was a problem hiding this comment.
the best approach is to use module.exports.nextTick = process.nextTick pattern instead. Adding a wrapper is going to slow things down.
There was a problem hiding this comment.
As I told you above it won't pass this test if I use your approach.
It happens because in this case readable-stream will still use original process.nextTick even after it will be replaced with the "fake" version.
There was a problem hiding this comment.
Oh, I understand now. You can do the following on the node side:
module.exports = processWhile on the browser side:
module.exports = { nextTick }Then, in code:
var wrap = require('./nextTick')
wrap.nextTick(function () {
// this will work via lolex
})There was a problem hiding this comment.
Well, it's basically a polyfilling of a process object which I suggested here: #413 (comment)
There was a problem hiding this comment.
I think we were in agreement in there. I'll just not call it process.
There was a problem hiding this comment.
But how do you want it to be called? wrap? Why not just process?
There was a problem hiding this comment.
We should not expect to be a full process object. In the browser, it won't be. It's an object with a nextTick property. we can call how we want "lightProcess" "fakeProcess" "nextTickWrap". This should enable that lolex support.
next-tick-browser.js
Outdated
| setTimeout(function () { | ||
| fn.apply(null, args); | ||
| }, 0); | ||
| } |
There was a problem hiding this comment.
have you got a link to Browserify impl? I think Browserify version might be slightly faster and provide a better experience for users overall.
|
Can you please enable me to push on this PR? I have the test fixed. |
|
@mcollina I've added you as collaborator to the forked repo if this is what you are asking for. |
|
@mcollina any updates? |
|
I'm -1 on the
|
Fixes #412 for v3
Notes:
./build/build.js 10.15.3