Readit News logoReadit News
quantummkv · 8 years ago
The real problem with npm and JavaScript is not the package manager, it is the lack of a standard library bundled with the runtime that has such basic functions. To someone coming to JavaScript from a Java/C# world, the fact that a package like isArray actually exists, nevermind the ridiculous number of downloads it has, is mind boggling. Using a dependency like this on a Java project will get you crucified in any sane team.

If you want to get out of this dependency hell, bundle these small, essential functions into the runtime.

banjomonster · 8 years ago
Array.isArray is available in the runtime, but it was a later addition so folks may be downloading it for compatibility. There is a LOT of that in the javascript ecosystem.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

pavlov · 8 years ago
I agree with your general sentiment, but Array.isArray() has been standard since about 2010. It’s even in IE9. Anyone using an npm package for this feature deserves the beating.

IMO the problem with npm is that it makes no distinction between snippets, libraries, frameworks and scripted command line tools. An npm package can be any of these. I feel there perhaps should be separate namespaces and package managers for all four — e.g. an inlining minimal “node snippet manager”, a standardized framework installer for things like create-react-app, and so on.

styfle · 8 years ago
Some packages ship with both importable module as well as a global CLI. So it’s hard to categorize packages on into a single category.
TAForObvReasons · 8 years ago
The flipside is that the standard library from Java / C# are huge, large enough that there's basically one complete and proper implementation.

In JS land, you have multiple different implementations with different feature sets and behaviors. Code written for V8/chrome/node may behave differently in safari/jscore or IE/edge/chakra or firefox/spidermonkey.

quantummkv · 8 years ago
This can be the case for big or difficult to implement functionality like async/await. But for smaller functions like isArray, isObject and leftpad this should not be the case.

C++ has a lot of different standards, compilers and implementations. There are differences in vc++ and gcc that can prevent compilation without flags or custom implementations. But I am sure that simple functions like printf or strcpy behave same across implementations.

Even in Java you have Oracle JVM and android's custom dalvik/ART. But the standard Java functions still work the same. Same with .net/mono.

ssalazar · 8 years ago
By flipside are you suggesting that managing multiple feature sets/behaviors across implementations is a good thing?
dguo · 8 years ago
Keeping the Node standard library small seems to be a deliberate approach. See this post for some elaboration: https://medium.com/the-node-js-collection/keeping-the-node-j...
woogley · 8 years ago
Depends on the team. I would not approve anything other than using a runtime library or importing 'core-js/fn/array/is-array' from the wonderfully modular core-js: https://github.com/zloirock/core-js

Although for this particular strawman I think `foo.constructor === Array` is probably enough.

alaaibrahim · 8 years ago
What if foo is `null` or `undefined` ?

Deleted Comment

styfle · 8 years ago
They are bundled, it’s called ES6/ES2015. But for backwards compatibility, the userland packages are still used regularly.
slig · 8 years ago
> They are bundled, it’s called ES6/ES2015

I wish. See the `Set` implementation [1], for instance. It's lacking very basic stuff like union and intersection, forcing the user to copy/paste code or add another dependency.

Does someone know why they do that? Looking from the outside it seems that the committee in charge of this doesn't know what they're doing.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

koolba · 8 years ago
If you were planning on writing modern Java and targeting JDK 1.3 you'd have just as many libraries.
vlunkr · 8 years ago
I think perhaps the biggest problem is the lack of a flat dependency system. So not only does your project depend on isArray, it may depend on 5 different versions of it. The sheer number of deps a seemingly normal React app has is crazy. Especially with webpack, babel, etc.
lugrugzo · 8 years ago
Npm3 has flat dependency system.
Kamshak · 8 years ago
It's what was there with bower but that has a lot of problems as well. So many in fact that everyone has moved to npm

Deleted Comment

sixdimensional · 8 years ago
Perhaps WebAssembly will help with this, we could make a standard library in WebAssembly which is highly performant, and can be called from regular Javascript code.
chr1 · 8 years ago
Not likely. Calling from javascript to webassembly is slow, webassembly can't create js objects, and usually it is not much smaller than the equivalent js code, due to lower level of abstraction.
TAForObvReasons · 8 years ago
> This thing lets you understand the performance cost of npm install ing a new npm package before actually adding it to your bundle.

Unless you are specifically concerned about the `npm install` performance in node, in which case the npm package size is relevant, you never include the whole NPM package in your bundle. Most universal packages include separate dist files and separate entry points for node usage, so most of the content is actually not included.

If you are truly interested in bloat, let your bundler give you a summary at the end. Webpack can give you detailed information about what files were included, how much each file costs, and why the costs were incurred.

mercer · 8 years ago
Lodash is a good example of this. The whole package is pretty big, and includes a functional programming variant (which I suppose is mostly wrappers around the other stuff, but it still adds weight).

So in practice you'll pretty much never be using the full package on account of 1) going for either require('lodash') or require('lodash/fp'), but not both, and 2) requiring specific functions through require('lodash/each') or whatnot.

The only way to get an accurate picture is to analyse the bundled package, or I suppose as part of the pipeline of whatever packaging solution you use.

pastelsky · 8 years ago
Author here. I made this because finding package sizes of front end libraries was a pain, especially after modular javascript caught on.

You can also see size results now when browsing a package on yarnpkg.com (look for "Size in browser") or as a sheild on some repos (WIP).

Suggestions welcome.

tytytytytytytyt · 8 years ago
Can you fix this?

    MissingDependencyError
    This package (or this version) uses `./lib-cov/http`, but does not specify them
    either as a dependency or a peer dependency
For input chai-http

sixdimensional · 8 years ago
Sorry, I think I broke it because I didn't understand it. I was really curious to see what angular-cli came in with in your tool, because my feeling is that it's very costly in terms of dependencies. The result never came back.. stuck at "Calculating File Sizes" was I not supposed to look at such types of packages?
mintblue · 8 years ago
Really cool site, material breaks it though. Can't find dependency "button" :)

Thanks for building!

Yokohiii · 8 years ago
Wouldn't it make more sense to optinally add all dependencies?
pastelsky · 8 years ago
If you're the author of `react-button`, it wouldn't make sense to add `react` + `react-dom` to account for it's size. In most cases, peer dependencies are already present in the user's projects.
fleetfox · 8 years ago
Where are you from that 3G is "emerging"? I think we have like 90% LTE coverage for major providers, just a question of hardware supporting that.
nathancahill · 8 years ago
Oh boy. Guys, should we tell him?
mhaehnel · 8 years ago
It's about emerging markets.
nulagrithom · 8 years ago
Suggestion: also show the number of dependencies and sub-dependencies.

That's usually where I run in to bundle-phobia mentality (whether its warranted or not is another discussion).

brootstrap · 8 years ago
good call, i'm a python guy who usually does science/infrastructure stuff but occasionally look at what is goin on with our front end libaries. Whenever i read thru our dep-chain i'm like holy shit guys, isArray is in here 4 times with 4 different versions.

All in all though cool project, looks great, works fast, provides good info. thanks and congrats

oboopfmlrmnmn · 8 years ago
I don’t understand if you are the author or just use a suggestive writing style.
dentemple · 8 years ago
Wouldn't using something like Yarn resolve this issue?
cJ0th · 8 years ago
> isArray is in here 4 times with 4 different versions.

just ... wow :D

mStreamTeam · 8 years ago
I've used this NPM graph tool in the past to determine the cost of adding a dependency: http://npm.anvaka.com/#/
warent · 8 years ago
Love this tool. BundlePhobia should just merge its abilities into this thing (or vice-versa) they'd be way powerful together
ianjsikes · 8 years ago
Here's a great VS Code extension that shows package size inline next to your import/require statements:

https://marketplace.visualstudio.com/items?itemName=wix.vsco...

Shoothe · 8 years ago
Leftpad: https://bundlephobia.com/result?p=leftpad@0.0.1 looks good, let's use it!

But seriously great service, I was thinking about a CLI tool like this to estimate dependency impact before using it.

mnx · 8 years ago
left-pad only adds 7ms on edge, seems worth it. On the other hand, Jquery adds almost a second. And you hardly ever see pages that don't use it. (Unless they use some other heavy js library). But it's just soo convenient.
maccard · 8 years ago
7ms is an eternity. You can do half of this [0] in 7ms or you can download one line of code. I’d be out of a job if I introduced 1/10 of that time for text padding.

[0] http://www.adriancourreges.com/blog/2017/12/15/mgs-v-graphic...

ssalazar · 8 years ago
Its completely meaningless to compare the render time of a single frame of a AAA video game with the load time of web page over a network.
busterarm · 8 years ago
I often find that most of the people who make the Jquery argument are the same people pushing Angular or React, both of which are bigger libraries...