Skip to content

Commit 7735b7e

Browse files
committed
fix: adapt to js-yaml v5 breaking changes
- Add skipLibCheck for Uint8Array<ArrayBuffer> generic type (requires TS 5.7+) - Replace removed 'replacer' option with pre-dump data transformation
1 parent e484bbb commit 7735b7e

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/riff-raff-yaml-file/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.",

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"sourceMap": true,
1010
"inlineSourceMap": false,
1111
"inlineSources": true,
12-
"outDir": "lib"
12+
"outDir": "lib",
13+
"skipLibCheck": true
1314
},
1415
"include": ["src/**/*"],
1516
"exclude": ["node_modules", "src/**/*.test.ts", "src/**/__snapshots__/**"]

0 commit comments

Comments
 (0)