@@ -43,11 +43,12 @@ import {checkPortAvailability, getAvailableTCPPort} from '@shopify/cli-kit/node/
43
43
import { TunnelClient } from '@shopify/cli-kit/node/plugins/tunnel'
44
44
import { getBackendPort } from '@shopify/cli-kit/node/environment'
45
45
import { basename } from '@shopify/cli-kit/node/path'
46
- import { renderWarning , renderInfo , Token } from '@shopify/cli-kit/node/ui'
46
+ import { renderWarning , renderInfo } from '@shopify/cli-kit/node/ui'
47
47
import { reportAnalyticsEvent } from '@shopify/cli-kit/node/analytics'
48
48
import { OutputProcess , formatPackageManagerCommand , outputDebug } from '@shopify/cli-kit/node/output'
49
49
import { hashString } from '@shopify/cli-kit/node/crypto'
50
50
import { AbortError } from '@shopify/cli-kit/node/error'
51
+ import { asHumanFriendlyArray } from '@shopify/cli-kit/common/array'
51
52
52
53
export interface NoTunnel {
53
54
mode : 'use-localhost'
@@ -637,44 +638,11 @@ export function renderPortWarnings(portWarnings: PortWarning[] = []) {
637
638
return
638
639
}
639
640
640
- const formattedWarningTypes = asHumanFriendlyTokenList ( portWarnings . map ( ( warning ) => warning . type ) ) . join ( ' ' )
641
- const formattedFlags = asHumanFriendlyTokenList ( portWarnings . map ( ( warning ) => ( { command : warning . flag } ) ) )
641
+ const formattedWarningTypes = asHumanFriendlyArray ( portWarnings . map ( ( warning ) => warning . type ) ) . join ( ' ' )
642
+ const formattedFlags = asHumanFriendlyArray ( portWarnings . map ( ( warning ) => ( { command : warning . flag } ) ) )
642
643
643
644
renderWarning ( {
644
645
headline : [ `Random ports will be used for ${ formattedWarningTypes } because the requested ports are not available.` ] ,
645
646
body : [ `If you want to use specific ports, you can choose different ports using the` , ...formattedFlags , `flags.` ] ,
646
647
} )
647
648
}
648
-
649
- /**
650
- * Converts an array of Tokens into a human friendly list
651
- *
652
- * Returns a new array that contains the items separated by commas,
653
- * except for the last item, which is seperated by "and".
654
- * This is useful for creating human-friendly sentences.
655
- *
656
- * @example
657
- * ```ts
658
- * const items = ['apple', 'banana', 'cherry'];
659
- * const result = asHumanFriendlyList(items)
660
- *
661
- * //['apple', ',', 'banana', ',', 'and', 'cherry']
662
- * console.log(result);
663
- * ```
664
- */
665
-
666
- function asHumanFriendlyTokenList ( items : Token [ ] ) : Token [ ] {
667
- if ( items . length < 2 ) {
668
- return items
669
- }
670
-
671
- return items . reduce < Token [ ] > ( ( acc , item , index ) => {
672
- if ( index === items . length - 1 ) {
673
- acc . push ( 'and' )
674
- } else if ( index !== 0 ) {
675
- acc . push ( ', ' )
676
- }
677
- acc . push ( item )
678
- return acc
679
- } , [ ] )
680
- }
0 commit comments