rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush-lib]: sort dependencies... with alphabetic order

Open chengcyber opened this issue 4 years ago • 3 comments

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

chengcyber avatar Jan 28 '21 11:01 chengcyber

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.

iclanton avatar Feb 01 '21 19:02 iclanton

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

chengcyber avatar Feb 02 '21 10:02 chengcyber

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.)

octogonz avatar Feb 19 '21 02:02 octogonz