@@ -270,14 +270,23 @@ export class RiffRaffYamlFile {
270270 */
271271 toYAML ( riffRaffProjectName : RiffRaffProjectName = UnknownRiffRaffProjectName ) : string {
272272 // Add support for ES6 Set and Map. See https://github.com/nodeca/js-yaml/issues/436.
273- const replacer = ( _key : string , value : unknown ) => {
273+ // js-yaml v5 removed the `replacer` option, so we transform the data before dumping.
274+ const transformValue = ( value : unknown ) : unknown => {
274275 if ( value instanceof Set ) {
275- // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- this is how `js-yaml` is typed
276- return Array . from ( value ) ;
276+ return Array . from ( value ) . map ( transformValue ) ;
277277 }
278278 if ( value instanceof Map ) {
279- // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- this is how `js-yaml` is typed
280- return Object . fromEntries ( value ) ;
279+ return Object . fromEntries (
280+ Array . from ( value . entries ( ) ) . map ( ( [ k , v ] ) => [ k , transformValue ( v ) ] ) ,
281+ ) ;
282+ }
283+ if ( Array . isArray ( value ) ) {
284+ return value . map ( transformValue ) ;
285+ }
286+ if ( value !== null && typeof value === "object" ) {
287+ return Object . fromEntries (
288+ Object . entries ( value ) . map ( ( [ k , v ] ) => [ k , transformValue ( v ) ] ) ,
289+ ) ;
281290 }
282291 return value ;
283292 } ;
@@ -288,7 +297,7 @@ export class RiffRaffYamlFile {
288297 throw new Error ( `No Riff-Raff project found with name: ${ riffRaffProjectName } ` ) ;
289298 }
290299
291- const yaml = dump ( content , { replacer } ) ;
300+ const yaml = dump ( transformValue ( content ) ) ;
292301
293302 const comments = [
294303 "This file was generated by @guardian/cdk, do not edit it directly." ,
0 commit comments