-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix: stop sorting scripts #206
Conversation
2850afb
to
8935395
Compare
The fields option will override the values in the builtin fields array, allowing users to signify that a given key should not be sorted, or sorted in a particular way.
8935395
to
3d52049
Compare
Why not extend |
I started going down that route, but if you just specify something like This way you can influence sort of keys without affecting the ordering of those keys |
How about |
While that would work, it seems more confusing to me. What is the reasoning behind preferring re-using the |
what would be needed to move this forward? |
Could you please demonstrate a concrete use case for needing this? |
Sure. We use npm-run-all to run multiple scripts sequentially, based on their ordering within the scripts block. An example of this would be
Reordering the scripts block based on lexical ordering would functionally change the build script, in a breaking way. |
@jonathanmorley I would prefer to keep
|
👍 Additional we can also check |
npm-run-all has a third command ( Rather than add in checks for |
What if |
Why not just an option to (dis)allow ordering scripts, regardless of the reason, instead of check for a specific tool? What if I use another tool like npm-run-all but is called different? I need to create another patch for each specific tool that requires specific order on scripts? |
that was the original intent. The |
Yeah we can just unilaterally disable sorting of scripts. In my experience these tend to be more taken care of than the rest of the package.json, and the important part of this package is really to sort the main fields so you can predictably |
I use npm-run-all and prefer to sort the scripts. It would be a shame to stop sorting scripts just because some tools depend on the key order of the objects. It is an object, not an array. |
We could just sort |
I agree with having |
6d9501b
to
44ba8ff
Compare
I'm finding this diff really difficult to read now. Why does it change a bunch of seemingly unrelated lines? Do you have auto formatting on? |
} | ||
return name | ||
}) | ||
.sort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is the only LOC that should be in this diff now, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is prettier moving the .map
up a line since it no longer has a .sort
to align with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keithamus does this sufficiently explain the diff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why has the index.d.ts
changed so much? Is it just that the copy in the main branch is old?
🎉 This PR is included in version 1.49.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I'm a bit sad that this was merged, especially as a bug: having Would it be possible to revisit this to see if we could come up with a middleground for everyone? |
I agree with @G-Rath, this change was an unwelcome surprise. We've been using sort-package-json to standardize our package.json files for several years. We use a lot of scripts and keeping those in order was a huge help. After a recent round of updates, I thought something broke when the scripts weren't sorted back into the expected lexical+pre/post order. I see sort-package-json as a linting tool, and much as I've given formatting over to tools like Prettier, I'm fine with whatever opinionated choices the tool's maintainers decide to make. But removing script sorting is a major loss of functionality which I'll be looking to replace. For now, running |
I'd go so far as to call it a breaking change. We will use Edit: This edge case really wasn't very hard to solve and costs very little:
|
Totally agree, the ordering of scripts was very important for my projects to avoid unnecessary merges with git and improve the readability of the package.json, please reconsider this change. |
I just want to let you know that it also was a surprise that our scripts are not being sorted and I just noticed this... Guess it is me to blame because I didn't pin this package version and was just using the latest. But yeah, I agree with the guys above that this was a pretty important feature for me, prettier/linter for pacakge.json, in a way. And I'm sad to see this functionality gone. Will pin to |
Please do submit a PR if you think this is solvable in a deterministic and non-configurable way that addresses the concerns of folks like @jonathanmorley. |
@keithamus : The deterministic way was covered in the code example. To be clear, here it is again: - "build": "run-s build:*",
+ "build": "run-s build:ts build:cdk", Being explicit about the order and avoiding the magical I'll be blunt: |
@G-Rath has submitted a PR which sorts scripts unless |
Hmm... What if I have installed and still want to sort them? Examples above shows that. |
I guess you have two choices:
|
If you would like to improve the heuristic - if you think you could find a deterministic way to sort scripts without effecting existing implicit |
Don't forget |
Not sure if this is relevant, but We might need to implement a rule that is flexible, i.e. not hard-wired to |
Went through a "bisect" of sort-package-json versions until I ended up here to determine this was not a bug, but a conscious decision. This is definitely a breaking change and magic sorting (or lack of sorting?) because a dependency is included is unpredictable behavior. I use Users of sort-package-json should assume that the json will be resorted (excluding arrays); relying on ordering of object keys is not a bug within sort-package-json, but relying on an unreliability. Will be pinning to |
The fields option will override the values in the builtin fields array,
allowing users to signify that a given key should not be sorted, or sorted
in a particular way.