Skip to content
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

Auto-sort bower.json dependencies alphabetically, fixes #1373 #1381

Conversation

insanehong
Copy link
Contributor

This patch fixed #1373.

I like how, as of late, npm install --save automatically re-writes package.json so that dependencies are listed in alphabetical order. Makes it easier to visually parse the file, and ensures some consistency across different Node.js projects. That said, I'm sure some folks prefer to have dependencies listed in order of when they were saved, but that's what version control (e.g. git blame) is for IMO.

Would be nice to have this feature when doing bower install --save. Thoughts?

@sheerun
Copy link
Contributor

sheerun commented Jul 2, 2014

Maybe some helper function to avoid duplication?

@sheerun
Copy link
Contributor

sheerun commented Jul 2, 2014

And make testing easier.

@insanehong
Copy link
Contributor Author

@sheerun yes i know. but i don't have idea where in function. may i make helper function in Project.js

@satazor
Copy link
Member

satazor commented Jul 2, 2014

Why not use deep-sort-object? Its works recursively but it doesnt really matter. If you use it, you have duplication solved and bower codebase stays the same.

@insanehong
Copy link
Contributor Author

@satazor what's mean bower codebase?

@insanehong
Copy link
Contributor Author

@sheerun
Copy link
Contributor

sheerun commented Jul 2, 2014

That's what he means :)

@insanehong
Copy link
Contributor Author

@satazor @sheerun ok. got it. :)

@insanehong
Copy link
Contributor Author

I changed code that use deep-sort-object module for sorting. how about this?

@satazor
Copy link
Member

satazor commented Jul 2, 2014

much nicer now :)

@sheerun sheerun added this to the 1.4.x milestone Jul 2, 2014
@insanehong
Copy link
Contributor Author

Thanks ^^ Do i something? @satazor @sheerun

@sheerun
Copy link
Contributor

sheerun commented Jul 2, 2014

Nope. I'm scheduling on 1.4.x

@insanehong insanehong force-pushed the fix/Auto-sort-dependencies-alphabetically branch from 1aa0cf2 to 0acfe55 Compare December 16, 2014 23:54
@insanehong insanehong force-pushed the fix/Auto-sort-dependencies-alphabetically branch from 0acfe55 to f62aaa5 Compare January 8, 2015 07:53
@insanehong insanehong force-pushed the fix/Auto-sort-dependencies-alphabetically branch from f62aaa5 to 252e915 Compare February 17, 2015 01:07
@insanehong insanehong force-pushed the fix/Auto-sort-dependencies-alphabetically branch from 252e915 to 6db5df9 Compare February 25, 2015 01:24
@insanehong insanehong force-pushed the fix/Auto-sort-dependencies-alphabetically branch from 6db5df9 to 78c49c2 Compare March 6, 2015 02:52
@insanehong insanehong force-pushed the fix/Auto-sort-dependencies-alphabetically branch from 78c49c2 to 91bc64c Compare March 6, 2015 02:53
@JaKXz
Copy link

JaKXz commented Apr 13, 2015

This looks great! Scheduled for 1.4.2? 🎱

@sheerun
Copy link
Contributor

sheerun commented Apr 13, 2015

Yes. Thanks for reminding.

@sheerun sheerun mentioned this pull request Apr 13, 2015
3 tasks
@michgeek
Copy link

Just find out that this new behavior is messing up the dependencies order. Sometimes the order matter. I am using bower with gulp in order to inject my dependencies into my app.
For example, I declared jquery before angular, because that's the correct order for angular to use jquery.
Now that everything is sorted alphabetically automatically, I got angular before jquery.
Is there any option to preserve the declaration order ?

@sheerun
Copy link
Contributor

sheerun commented Aug 26, 2015

The order of declaration shouldn't matter.. Maybe we can provide a flag

@michgeek
Copy link

Why shouldn't it matter ? It's sometime normal to have a specific loading order betweens libs. What if for example I'm using Colorbox which is a jQuery plugin and I load it before jQuery. It doesn't work. The best place to control order is to keep that order in the declaration array. Can you please provide a solution to that ? Until that this 1.5 update is a compatibility breaker. Thanks.

@deonclem
Copy link

I agree with @michgeek, order also matters in my app and I think disabling the auto sorting should be an option, even if by default the dependencies are ordered.

@faceleg
Copy link
Member

faceleg commented Nov 14, 2015

@deonclem @michgeek JavaScript objects do not guarantee consistent key order. See http://stackoverflow.com/a/5525820/187954

@faceleg
Copy link
Member

faceleg commented Nov 14, 2015

@insanehong could you please update your PR with the latest from master?

@faceleg faceleg self-assigned this Nov 14, 2015
@sheerun
Copy link
Contributor

sheerun commented Nov 14, 2015

We've already deployed this feature in past, and reverted it because users complained.

We need to put it behind a feature flag first..

@faceleg
Copy link
Member

faceleg commented Nov 15, 2015

@insanehong as per @sheerun's request, to be merged and deployed, this PR must:

  • Be updated with master commits
  • Provide a new flag that triggers this behaviour if desired

@insanehong
Copy link
Contributor Author

@faceleg ok. I try make to new option for Auto-sort dependencies alphabetically

@faceleg
Copy link
Member

faceleg commented Nov 18, 2015

Thanks for sticking with it @insanehong!

@TimvdLippe
Copy link

Would be nice to have an option for this @insanehong :)

@fearphage
Copy link

We've already deployed this feature in past, and reverted it because users complained.

Can you point me to those issues and complaints? I'm trying to understand why people would be against things being easier to read/parse.

@sheerun
Copy link
Contributor

sheerun commented Jul 27, 2016

@fearphage Because they generated index.html with scripts in the same order as in bower.json

@fearphage
Copy link

Because they generated index.html with scripts in the same order as in bower.json

This seems like a bad practice. At a minimum, it's suboptimal to tie your implementation to representation of data that you have no control over. If you want something to be in a certain order, you sort it. That's why we have methods for that. Ideally we shouldn't be coding based on the state we hope things are in.

Is contract-less/wishful coding the only thing holding this back?

Wouldn't a major version bump insulate bower from breaking anything that doesn't have */latest in package.json without the need of a command-line option?

@sheerun
Copy link
Contributor

sheerun commented Jul 27, 2016

It's more popular than you think.

We can break it in major bump or a flag (even generic one, like --next).

@sheerun
Copy link
Contributor

sheerun commented Mar 28, 2018

Bower is deprecated and we don't want to release breaking changes now

@sheerun sheerun closed this Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Auto-sort bower.json dependencies alphabetically?
9 participants