Skip to content

fix: improve-scripts-sorting - #376

Merged
keithamus merged 8 commits into
keithamus:mainfrom
Yaman-kumarsahu:fix/improve-scripts-sorting
Dec 8, 2025
Merged

keithamus merged 8 commits into
keithamus:mainfrom
Yaman-kumarsahu:fix/improve-scripts-sorting

Conversation

@Yaman-kumarsahu

@Yaman-kumarsahu Yaman-kumarsahu commented Oct 12, 2025 •

Copy link
Copy Markdown
Contributor

closes #360
Grouping keys before : and sorting the keys and the items in the group of the respective keys and then flattening the array.

Comment thread tests/scripts.js
Comment on lines +233 to +234
'test:a': 'foo',
'test:b': 'bar',

@fisker fisker Oct 12, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also test scripts contains mutiple :s? Eg: test:a:a, test:a:b

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure,
I have now added the test for this scenario.

Comment thread tests/scripts.js
Comment on lines +253 to +254
'test:a:a': 'foofoo',
'test:a:b': 'foobar',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'test:a:a': 'foofoo',
'test:a:b': 'foobar',
'test:a:a': 'foofoo',
'test:a:b': 'foobar',
'test:a-coverage': 'foobar',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the expected sorted file like this

'test:a',
'test:a-coverage',
'test:a:a',
'test:a:b',

or this

'test:a',
'test:a:a',
'test:a:b',
'test:a-coverage',

@Yaman-kumarsahu Yaman-kumarsahu Oct 13, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want the sorting to be like this

'test:a',
'test:a:a',
'test:a:b',
'test:a-coverage',

we can replace the entire logic with

source = keys.slice().sort((a, b) => 
      a.replace(/:/g, ' ')
      .localeCompare(b.replace(/:/g, ' '), 'en'));

else the current code will sort it in this way

'test:a',
'test:a-coverage',
'test:a:a',
'test:a:b',

Co-authored-by: fisker Cheung <lionkay@gmail.com>
Comment thread index.js Outdated
}
source = Array.from(groupMap.keys())
.sort()
.flatMap((groupKey) => groupMap.get(groupKey).sort())

@fisker fisker Oct 12, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should do recursively

@Yaman-kumarsahu Yaman-kumarsahu Oct 12, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I am following. Could you tell me why?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "group" can be deep

test
test:a
test:b
test-coverage

test:production
test:production:a
test:production:b
test:production-coverage

test:production:cjs
test:production:cjs:a
test:production:cjs:b
test:production:cjs-coverage

test:production:mjs
test:production:mjs:a
test:production:mjs:b
test:production:mjs-coverage

@fisker fisker Oct 13, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, current implementation seems relay on - and : order in ascii, it shouldn't

test
test:a
test:b
test[NO MATTER WHAT IS] # this should still put after the ones with `:`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fisker , I was not able to group them as above. But after sorting it will be like

    'test',                                   <---------  parent
    'test:a',                                 <---------  child
    'test:ab',
    'test:b',
    'test:production',
    'test:production:a',
    'test:production:b',
    'test:production:cjs',
    'test:production:cjs:a',
    'test:production:cjs:b',
    'test:production:cjs-coverage',
    'test:production:mjs',
    'test:production:mjs:a',
    'test:production:mjs:b',
    'test:production:mjs-coverage',
    'test:production-coverage',
    'test-coverage'                           <---------  overall coverage

Will this work?

Also the below three tests are flaky for me. Is this related to my changes?

  ✘ [fail]: cli › run `cli` on 2 good files and 2 bad files Should format 2 files.
  ✘ [fail]: cli › run `cli --check` on 2 bad files Should report 2 files.
  ✘ [fail]: cli › run `cli` on 2 bad files Should format 2 files.

fisker
fisker previously approved these changes Dec 8, 2025

@fisker fisker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result looks great! Thank you!

@keithamus
keithamus merged commit e6052c4 into keithamus:main Dec 8, 2025
3 checks passed
@github-actions

github-actions Bot commented Dec 8, 2025

Copy link
Copy Markdown

🎉 This PR is included in version 3.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve scripts sorting

3 participants