rushstack
rushstack copied to clipboard
[rush-lib]: sort dependencies... with alphabetic order
Summary
Keep alphabetic order for keys like dependencies, devDependencies when updating package.json Fixes https://github.com/microsoft/rushstack/issues/2115
Details
As per https://github.com/microsoft/rushstack/blob/master/apps/rush-lib/src/api/PackageJsonEditor.ts#L143, I think originally PackageJsonEditor
tends to sort dependencies and devDependencies, but jju
update function is trying to preserve the previous order. This PR is fixing the alphabetic order for dependencies
devDependencies
when updating package.json
How it was tested
Does this sort the existing package.json
entries, or does it just insert the new dependency in approximately-correct alphabetical order? If it's the former, we should control this with a flag.
Does this sort the existing
package.json
entries, or does it just insert the new dependency in approximately-correct alphabetical order? If it's the former, we should control this with a flag.
Yes, this sorts the existing package.json
, this behavior is same with npm
, yarn
, pnpm
...
It seems to me the current behavior is accidentally broken by jju.update
feature. but anyway this is a design choice to keep the current behavior. If a explicit parameter is required, could you help naming the param? I will implement it
FYI there was some more discussion of this feature in https://github.com/microsoft/rushstack/issues/2496
Also, in https://github.com/microsoft/rushstack/issues/1503 we proposed to add a switch preservePackageJsonLayout
for disabling these features.
(This is just FYI -- I'm not requesting a change for this PR necessarily.)