@@ -2,6 +2,7 @@ import * as fs from 'fs'
22import { Parameter } from '@aws-sdk/client-cloudformation'
33import { HttpsProxyAgent } from 'https-proxy-agent'
44import { Tag } from '@aws-sdk/client-cloudformation'
5+ import { yaml } from 'js-yaml'
56
67export function isUrl ( s : string ) : boolean {
78 let url
@@ -17,42 +18,41 @@ export function isUrl(s: string): boolean {
1718
1819export function parseTags ( s : string ) : Tag [ ] | undefined {
1920 if ( ! s || s . trim ( ) === '' ) {
20- return undefined ;
21+ return undefined
2122 }
2223
23- let tags ;
24+ let tags
2425
2526 // Try to parse as JSON first (backward compatibility)
2627 try {
27- tags = JSON . parse ( s ) ;
28- return tags ;
28+ tags = JSON . parse ( s )
29+ return tags
2930 } catch ( _ ) {
3031 // JSON parsing failed, try to parse as YAML
3132 }
3233
3334 // If JSON parsing fails, try to handle as YAML
3435 try {
35- const yaml = require ( 'js-yaml' ) ;
36- const parsed = yaml . load ( s ) ;
37-
36+ const parsed = yaml . load ( s )
37+
3838 if ( ! parsed ) {
39- return undefined ;
39+ return undefined
4040 }
4141
4242 // Handle the two YAML structure formats
4343 if ( Array . isArray ( parsed ) ) {
4444 // Already in the format [{Key: 'key', Value: 'value'}, ...]
45- return parsed ;
45+ return parsed
4646 } else if ( typeof parsed === 'object' ) {
4747 // Convert from {Key1: 'Value1', Key2: 'Value2'} format
48- return Object . entries ( parsed ) . map ( ( [ Key , Value ] ) => ( { Key, Value } ) ) ;
48+ return Object . entries ( parsed ) . map ( ( [ Key , Value ] ) => ( { Key, Value } ) )
4949 }
5050 } catch ( _ ) {
5151 // YAML parsing failed
52- return undefined ;
52+ return undefined
5353 }
5454
55- return undefined ;
55+ return undefined
5656}
5757
5858export function parseARNs ( s : string ) : string [ ] | undefined {
@@ -67,18 +67,23 @@ export function parseNumber(s: string): number | undefined {
6767 return parseInt ( s ) || undefined
6868}
6969
70- export function parseParameters ( parameterOverrides : string | Record < string , any > ) : Parameter [ ] {
70+ type CFParameterValue = string | string [ ] | boolean
71+ type CFParameterObject = Record < string , CFParameterValue >
72+ export function parseParameters (
73+ parameterOverrides : string | Record < string , CFParameterObject >
74+ ) : Parameter [ ] {
7175 // Case 1: Handle native YAML objects
7276 if ( parameterOverrides && typeof parameterOverrides !== 'string' ) {
7377 return Object . keys ( parameterOverrides ) . map ( key => {
7478 const value = parameterOverrides [ key ]
7579 return {
7680 ParameterKey : key ,
77- ParameterValue : typeof value === 'string' ? value : JSON . stringify ( value )
81+ ParameterValue :
82+ typeof value === 'string' ? value : JSON . stringify ( value )
7883 }
7984 } )
8085 }
81-
86+
8287 // Case 2: Empty string
8388 if ( ! parameterOverrides ) {
8489 return [ ]
0 commit comments