Skip to content

Commit

Permalink
fix: use locale-independent comparison for sorting of overrides (#327)
Browse files Browse the repository at this point in the history
* fix: use locale-independent comparison for sorting of overrides

* Update index.js

Co-authored-by: Keith Cirkel <[email protected]>

---------

Co-authored-by: Jan Novotny <[email protected]>
Co-authored-by: Keith Cirkel <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 99a9760 commit 5213340
Show file tree
Hide file tree
Showing 5 changed files with 556 additions and 17 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const sortObjectBySemver = sortObjectBy((a, b) => {
const { name: bName, range: bRange } = parseNameAndVersionRange(b)

if (aName !== bName) {
return aName.localeCompare(bName)
return aName.localeCompare(bName, 'en')
}
if (!aRange) {
return -1
Expand Down
12 changes: 10 additions & 2 deletions tests/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function sortObjectAlphabetically(t, options = {}) {
for (let depth = 1; depth < maxDepth + 1; depth++) {
sortObject(t, {
...options,
value: keysToObject(['z', 'a'], depth),
expect: expect || keysToObject(['a', 'z'], depth),
value: keysToObject(['z', 'e', 'ch', 'a'], depth),
expect: expect || keysToObject(['a', 'ch', 'e', 'z'], depth),
})
}
}
Expand All @@ -73,6 +73,10 @@ function sortObjectWithRangeAlphabetically(t, options = {}) {
'@[email protected]',
'[email protected]',
'@b-package',
'@[email protected]',
'@[email protected]',
'[email protected]',
'[email protected]',
],
depth,
),
Expand All @@ -82,10 +86,14 @@ function sortObjectWithRangeAlphabetically(t, options = {}) {
[
'@[email protected]',
'@b-package',
'@[email protected]',
'@[email protected]',
'@[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
],
depth,
),
Expand Down
7 changes: 7 additions & 0 deletions tests/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ test('dependenciesMetaRange', macro.sortObjectWithRangeAlphabetically, {
// TODO: don't use snapshot, find a esaier way for review
expect: 'snapshot',
})

test('pnpm.overrides', macro.sortObjectWithRangeAlphabetically, {
path: 'pnpm.overrides',
maxDepth: 2,
// TODO: don't use snapshot, find a esaier way for review
expect: 'snapshot',
})
Loading

0 comments on commit 5213340

Please sign in to comment.