Skip to content

Commit 0b528c2

Browse files
authored
fix: handle colon-prefixed script names in sorter (#389)
1 parent e6052c4 commit 0b528c2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function sortScriptNames(keys, prefix = '') {
278278
for (const key of keys) {
279279
const rest = prefix ? key.slice(prefix.length + 1) : key
280280
const idx = rest.indexOf(':')
281-
if (idx !== -1) {
281+
if (idx > 0) {
282282
const base = key.slice(0, (prefix ? prefix.length + 1 : 0) + idx)
283283
if (!groupMap.has(base)) groupMap.set(base, [])
284284
groupMap.get(base).push(key)

tests/scripts.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,34 @@ test('scripts: group base and colon scripts together, do not split with unrelate
244244
])
245245
})
246246

247+
test('scripts: handles names starting with colon and double colons', (t) => {
248+
const input = {
249+
scripts: {
250+
'::delta': 'echo',
251+
test: 'echo',
252+
':beta': 'echo',
253+
':alpha:sub': 'echo',
254+
':alpha': 'echo',
255+
'test::coverage': 'echo',
256+
':alpha::extra': 'echo',
257+
'test:lint': 'echo',
258+
'test::smoke': 'echo',
259+
},
260+
}
261+
const sorted = sortPackageJson(input)
262+
t.deepEqual(Object.keys(sorted.scripts), [
263+
'::delta',
264+
':alpha',
265+
':alpha::extra',
266+
':alpha:sub',
267+
':beta',
268+
'test',
269+
'test::coverage',
270+
'test::smoke',
271+
'test:lint',
272+
])
273+
})
274+
247275
test('scripts: group scripts with multiple colons', (t) => {
248276
const input = {
249277
scripts: {

0 commit comments

Comments
 (0)