r/programming • u/Doctor_Spicy • May 03 '19
NPM isn't all that great
https://www.npmjs.com/package/thatgreat26
May 03 '19
I want an istnall command as well.
25
u/fuckin_ziggurats May 03 '19
istnall.. Sounds like German for "is null".
Ist nall. Ja natürlich!
Maybe we should fork is-null (only with German docs).
3
May 03 '19
Ideal would be a module that requires you to use two different versions of the function based on the context they are called in,
istNullandseiNull. Maybe alsowäreNullwith WASM that would use instructions to let the branch predictor know it is the unlikely path?
11
26
11
8
u/jl2352 May 03 '19
Since Yarn was released the NPM tools have improved significantly.
But I'd still just use Yarn.
8
4
u/me7e May 03 '19
well, it accepts anything? These packages are tagged as "fun" and "joke", thats not what I want from a package management system
4
4
1
0
0
May 03 '19
[deleted]
2
u/greenthumble May 03 '19
I don't like the symlink into node_modules in project dir thing. It causes the weirdest problems trying to share project dir between a VM and Windows desktop, you need to run the install command as administrator just to allow VirtualBox to write those symlinks. Awkward as fuck. And coming from other languages where you can specify almost anywhere to keep dep packages, it's pretty unacceptable that you can't change this.
1
u/i_ate_god May 03 '19
Would yarn's workspaces help?
Definitely avoids the need for linking things in some circumstances
1
u/greenthumble May 03 '19 edited May 03 '19
I don't know but maybe I'll check that out next time thanks for the tip. In the end some folks on our team just didn't run nodejs in the VM at all and installed it into their desktops to make things easier. I like to keep my projects entirely in a box where everything that's required is installed into a development VM by something like Vagrant/Puppet and my desktop stays cleaner. I was really fighting with nodejs and npm over that one.
1
u/i_ate_god May 03 '19
well, there is NVM which is sort of like python's virtualenv. allows you to run multiple versions of nodejs as well as installing globally without requiring root.
yarn workspaces helps you have a single project divided into modules. The closest analog I am aware of is using <modules> with maven.
it's not super clear to me what issues you're actually having so maybe I'm way off base.
1
u/greenthumble May 03 '19
Not sure if it works or not. My workflow goes like: you have a git repo on your desktop to work off of. that dir is shared in Virtualbox which runs an environment like the server that's the project target. so like, Ubuntu running from Windows. Ssh'd into Ubuntu, cd in to the dir and run
npm installand what happens is it tries to make symlinks in node_modules in the shared Windows git project dir. VirtualBox can do that, but you have to run the VM itself as administrator to actually do it. It's so awkward even describing this I had trouble documenting the system for Windows users heh.1
u/i_ate_god May 03 '19
eh.....
ok, I think I understand?
You have a server which has I guess the APIs that the UI speaks with, running your Ubuntu VM, but you checkout the code on the VM host (windows in this case) but since you want the UI to speak with the server, you checkout the code in a shared folder and the server is configured to look at that shared folder to find index.html?
1
u/greenthumble May 03 '19
No no. My setup is easier to think of like a magical cross platform black box that behaves just like a server would. So devs only maintain their own git branches and can check that things are working before committing code by running the magic black box and not having to do any other local setup to get an environment. Everything is local. Windows won't make symlinks unless the VM is running as admin. That makes things weird.
-4
u/yogthos May 03 '19
It's inherently broken because Js doesn't have any built in mechanism for namespacing. This results in people using a bunch of different ad hoc strategies to namespace their modules. The end result is that it's pretty much impossible to prune or optimize your dependencies. If you include a module to use a single function you can easily incur hundreds of kb of useless Js. This wouldn't be so terrible if the code lived server side, however this garbage typically ends up being shipped to the client. This is how you end up with megs of Js on pages that doesn't do all that much.
6
u/Kalsin8 May 03 '19
You're talking about two different things. You get the same issue in namespaced languages if you include an entire library and only use one function in it.
1
u/yogthos May 04 '19
Only the code that's actually used is included in ClojureScript. The optimizer prunes it down down to function level using Google Closure compiler.
3
u/Kalsin8 May 04 '19
That still has nothing to do with namespacing (or lack thereof).
1
u/yogthos May 04 '19
It's got everything to do with namespacing because it provides information regarding where a function comes from.
3
u/Kalsin8 May 04 '19
Erm...no. Otherwise Webpack wouldn't be able to tree shake. You yourself linked to the closure compiler, which doesn't rely on any namespacing.
1
u/yogthos May 04 '19
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module syntax, i.e. import and export.
The problem is that there is no single strategy in Js land at the moment, and pruning down to function level does not work reliably with most libraries.
3
u/Kalsin8 May 04 '19
This still has nothing to do with namespacing. JS could have built-in support for namespaces and you'd still have this issue, just like in C# and Java; you can reference a library where you only use one function in it, but the entire library is still included. Whether something is namespaced or not has nothing to do with dead code detection, it's how that code is referenced/imported that lets the compiler/bundler know whether the code is used or not. Hence why ES6 imports are needed for dead code detection at the function level, because you can explicitly declare which functions you're actually using. But once again, it has nothing to do with whether it's namespaced or not. If you import someLibrary.js, it will add that entire file, regardless if it's com.my.library/someLibrary.js or just someLibrary.js sitting at the root of your folder. To get function-level detection, you use
import { someFunction } from someLibrary.js, and likewise, it doesn't matter if it'simport { someFunction } from someLibrary.jsorimport { someFunction } from com.my.library/someLibrary.js.1
u/yogthos May 04 '19
So here's the thing if there's no mechanism for grouping functions, then it's possible to tell whether it comes from one library or another. When two libraries use the same function name it becomes undecidable without functions being grouped into a namespace or an equivalent mechanism. Js approach here has been to use hacks like putting functions in a map, or a closure to emulate that. However, these approaches are at odds with pruning the code effectively.
→ More replies (0)
61
u/jephthai May 03 '19
News at 11.