jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.3k stars 5.53k forks source link

Underscore fetched with bower stopped working #2923

Closed kopernic-pl closed 3 years ago

kopernic-pl commented 3 years ago

There is a difference in how 1.13.0 fetches using NPM and bower.

npm package contains backward-compatibility underscore.js file (underscore-umd copy, as confirmed with diff)

C:\Temp\teststs\node_modules\underscore (underscore@1.13.0) λ ls -l underscore*.js -rw-r--r-- 1 user 1049089 68420 Oct 26 1985 underscore.js -rw-r--r-- 1 user 1049089 65946 Oct 26 1985 underscore-esm.js -rw-r--r-- 1 user 1049089 25711 Oct 26 1985 underscore-esm-min.js -rw-r--r-- 1 user 1049089 19530 Oct 26 1985 underscore-min.js -rw-r--r-- 1 user 1049089 68420 Oct 26 1985 underscore-umd.js -rw-r--r-- 1 user 1049089 19530 Oct 26 1985 underscore-umd-min.js

bower, fetching directly from github, does not contain underscore.js file, which genreally breaks a lot.

bower underscore# new version for https://github.com/jashkenas/underscore.git# bower underscore# resolve https://github.com/jashkenas/underscore.git# bower underscore#* download https://github.com/jashkenas/underscore/archive/1.13.0.tar.gz 1.13.0.tar.gz does not contain underscore.js

Is it expected behavior?

jgonggrijp commented 3 years ago

No that was not expected and not intended. Thanks for reporting, @kopernic-pl!

I don't know much about Bower, to be honest; the bower.json file was already there when I took over maintenance and I never touched it. I'll look into it, but if you have any tips on how to solve the issue, please let me know.

jgonggrijp commented 3 years ago

@kopernic-pl I took a look at the bower.json, and it seems I actually updated it to use underscore-umd.js as the main entry instead of underscore.js. From what you're writing, I presume that Bower does not abstract away the main entry file name like Node.js does. The little documentation I could find about how to configure bower.json doesn't seem to give much room for specifying alternatives, aliases etcetera.

Seems like the only way to address this is to commit the duplicate underscore.js to git as well. If you can think of a more elegant solution, please let me know.

kopernic-pl commented 3 years ago

No opinion on this one on my side - I'm just upkeeping some legacy project ;)

It's ok for me to use undescore-umd.js but I'm afraid that it will still break something somewhere, in some other projects. If someone expects 'underscore.js' to be there and rely on this behavior/state, it's going to be rough.

Btw, symbolic links are no-go, so eventual copy seems to be only solution. Maybe name the file in the repo 'undescore.js' and automate renaming/creating copy to 'underscore-umd.js' when NPM package is created?

kopernic-pl commented 3 years ago

Btw, the 'main' in bower.json just states which files from repository should be pulled to your lockal packages when doing bower init., as per bower spec

It does not do nothing with files renaming. Bower is prehistoric nowadays 👴

7ochem commented 3 years ago

I just ended up here because my build of a legacy project failed when uglifyjs reported it could not find bower_components/underscore/underscore.js while trying to build a vendors.min.js.

I'll point my uglifyjs config to underscore-umd.js for now (at least that's my take away from this thread here. I didn't know if I would need esm, node or umd 😄 🙈 )

jgonggrijp commented 3 years ago

@kopernic-pl I won't change the official name of the UMD build back to underscore.js; ESM is the future. However, I figured it wouldn't hurt to just commit a copy with the old name. Git works with a hash-based filesystem, so there shouldn't be a significant cost. Expect 1.13.1 in an hour or so.

@7ochem Thanks for chiming in. Your legacy project almost certainly needs the UMD build. I guess I should add some clarification about that to the documentation. If you have any suggestions for questions that you'd like to see answered with regard to that, please feel free to let me know.

kopernic-pl commented 3 years ago

I've just pointed my code to umd package from 1.13.0 and it works very well (with require.js as a loader). So for me it is solved, for others @jgonggrijp copy shall be more than OK for next few years :)

jgonggrijp commented 3 years ago

@kopernic-pl @7ochem 1.13.1 is up.

7ochem commented 3 years ago

Thank you for the fast response and the ultra fast fix! 🙏🏻

jgonggrijp commented 3 years ago

Welcome!