-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Make process
requireable
#157
Comments
+1 |
I don't see any downsides to this, but not any particular upsides either: browserify is likely going to have to check for implicit globals like process for a long time. I'm +0 on a PR for this -- if one is submitted, and no other TC member has strong feelings about this, I'd be happy to shepherd it. |
+1 |
Cool |
This would render a few npm packages incompatible. But those could easily and automatically be updated with a PR-bot. I really like this idea. Globals always felt wrong for me. What about standard primitives tho? |
@buschtoens FWIW the lint rules we use in uber/lint-trap only allow four globals (which I mentioned in my post at the top of this page) whether you are on nodejs or in the browser with browserify. For the browser stuff, we recommend that people use https://github.com/Raynos/global The great thing about making everything requireable is that it makes it easy for people to mock out fakes when testing since all references in a file point to a closured var that can be overwritten just like substack does with Besides process and global, I think all the other standard primitives are already requireable. For all the timers, you have the timers module. For buffers, the buffer module, etc. I'm not in favor of implementing this in a way that breaks backwards compatibility (i.e. you should still be able to refer to process as a global, but you can also require it in instead if you prefer). Keeping the standard primitives from being called as a global really is the responsibility of your linter. |
@chrisdickinson I've never committed to nodejs or iojs, but I'm open to forking and creating a PR for this if you can just give me a few sentences explaining what parts of the source I should look into to figure out how to go about adding this feature. Just knowing where to start helps a lot. |
I have to disagree with a change such as this. In my opinion, it inherently goes against the idea of a module system and a system process. The built-in modules (such as The only reason functions like |
We would not remove the global. Process will always be global. You can just require it as a primary interface. However it has to be global, we cant break back compat. |
@Raynos yes, but I still disagree on the basis of it being categorized with the rest of the modules. |
Why not just make Just like
|
+1 |
Can someone explain why this is a good idea? As in, a real-world scenario that would benefit from this? |
There are a couple of benefits: (1) establishes a pointer reference more deeply in the scope chain. when There was another benefit I thought about this morning, but I can't remember it right now. |
@malandrew a good place to start looking is the merged PR that reintroduced the v8 module -- it should serve as a good example of where to poke at to add a new builtin module. If you need any help, I'm pretty much always available on freenode IRC in #io.js. |
As someone who has worked on the node-process module and been involved with the global detection in browserify I am very much +1 for this and making buffer requirable. A v1.0.0 release is a perfect time to remove the buffer global at the very least. It was a mistake to introduce it and not deprecate the global use for this long. Globals themselves are not somehow evil, but core should try to minimize what it leaks into the global scope and lets downstream consumers handle any magic globals they want to inject (if they so desire). |
@Raynos even the smallest changes always have a way of breaking backwards compatibility. Saying "we can't break backwards compat" isn't that helpful. Everyone has different understanding of what "compat" is going to mean. And stoping forward progress is the name of "compat" is arguably one of the reasons this repo exists today. |
@defunctzombie Buffer is different from process. Buffer does not need to be global. It's just a javascript library. process is a global thing defined in node.cc and is "special", that being said, I'm ok with it not being global. Also note being able to require process is more important then removing globals. |
+1 for deprecating global Buffer (but that's an topic for another github issue). Agree that process is different in the sense that it is a singleton object. It's a singleton that definitely should be available via the module system (hence why I opened this ticket). Whether or not it's use as a global should be deprecated, that is a topic for a different issue after a PR resolving this issue has been submitted and merged. I'll try to get this PR done over the christmas holiday. |
The scope doesn't go beyond the file so I'm not sure what you mean. What's a "pointer reference"? Can you give an example?
That only works if the module explicitly uses
The nextTick in node-process is basically just
They can always do
Buffer is such a ubiquitous thing that it deserves to be global. Removing it would break a lot of code for literally zero gain. |
No, it really isn't. If it was a module from day 1 you would not think twice about it. I think it is a reasonable policy to avoid introducing more globals than what is already part of the language spec. |
If I'm not completely mistaken,
That's a non-sequitur. We cannot change the past, and since
There's a difference between not adding more globals vs. removing one. I agree with the first but am hesitant with the second. Though adding more globals than defined in the spec is not an issue per se and practiced every day within the DOM – we can discuss whether the way they do it is sensible, but this is out of scope of this bug (as well as making |
@fbender You're wrong. process.something = 10;
console.log(something); // undefined or ReferenceError: something is not defined
global.something2 = 20;
console.log(something2); // 20 But, in my opinion module is something that is not dependent on current execution script. For example when you So my humble opinion:
|
I think that, if browserify or libraries like that want |
From my limited understanding, This isn't about removing It should merely re-exported to be require()able to adhere to convention (and make linting easier). Even in the case of |
well plus oneing this issue now is getting weird because it is saying
echoing some of @lxe, i think it sounds like a cool idea but all of my code will break if I dont go var process = require('process') at the top. Process is different, I have to agree with @brendanashworth's first remark. Process is to ios.js as the window object is to the browser. 👍 making it a require. 👎 making it not a global. |
Closing as #206 was landed. |
Ideally (IMHO) there would be no globals besides the 4 node keywords required for the module system to function:
require
,module
,__dirname
and__filename
.For many of the other modules that are typically globals, you can require them out of the box, such as
One of the few standard parts of node that cannot be loaded via
require()
isprocess
.The popularity of this npm module: https://www.npmjs.com/package/process , with almost a million downloads in the last month shows that a lot of people would benefit from having
process
be requireable. By making it requireable, browserify can then treat it as one of the special compatibility modules and list it here: https://github.com/substack/node-browserify#compatibilityThe text was updated successfully, but these errors were encountered: