-
-
Notifications
You must be signed in to change notification settings - Fork 237
Check for existence of process object (fix for v3)
#414
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
Conversation
next-tick-browser.js
Outdated
| setTimeout(function () { | ||
| fn.apply(null, args); | ||
| }, 0); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is non-breaking for webpack users, right? But potentially breaking for browserify users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the browserify one, and more importantly this was designed to work with browserify first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| module.exports = nextTick; | |
| module.exports = process.nextTick; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it doesn't pass this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's basically a polyfilling of a process object which I suggested here: #413 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we were in agreement in there. I'll just not call it process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But how do you want it to be called? wrap? Why not just process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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