Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,29 @@ test('scripts: group base and colon scripts together, do not split with unrelate
'test-coverage',
])
})

test('scripts: group scripts with multiple colons', (t) => {
const input = {
scripts: {
test: 'run-s test:a test:b',
'test:a': 'foo',
'test:b': 'bar',
'test:a:a': 'foofoo',
'test:a:b': 'foobar',
Comment on lines +257 to +258
Copy link
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
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',

Copy link
Author

@Yaman-kumarsahu Yaman-kumarsahu Oct 13, 2025

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',

'test:b:a': 'barfoo',
'test:b:b': 'barbar',
'test-coverage': 'c8 node --run test',
},
}
const sorted = sortPackageJson(input)
t.deepEqual(Object.keys(sorted.scripts), [
'test',
'test:a',
'test:a:a',
'test:a:b',
'test:b',
'test:b:a',
'test:b:b',
'test-coverage',
])
})