From f3d6af6ac16c15c58edc4b684848b468966aca58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Thu, 20 Jun 2019 16:05:18 +0200 Subject: [PATCH] fix(cli): Disable line folding in YAML Certain versions of YAML support long line folding, however the CloudFormation YAML parser does not handle those. Disabling folding when generating YAML so that we keep generating correct templates. Fixes #2703 --- packages/aws-cdk/lib/serialize.ts | 11 ++++++++++- packages/aws-cdk/test/test.serialize.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/aws-cdk/test/test.serialize.ts diff --git a/packages/aws-cdk/lib/serialize.ts b/packages/aws-cdk/lib/serialize.ts index 3219cb5a48836..70f0550ddfbba 100644 --- a/packages/aws-cdk/lib/serialize.ts +++ b/packages/aws-cdk/lib/serialize.ts @@ -1,10 +1,19 @@ import YAML = require('yaml'); +// tslint:disable-next-line: no-var-requires +const yamlTypes = require('yaml/types'); + /** * Stringify to YAML */ export function toYAML(obj: any): string { + const oldFold = yamlTypes.strOptions.fold.lineWidth; + try { + yamlTypes.strOptions.fold.lineWidth = 0; return YAML.stringify(obj, { schema: 'yaml-1.1' }); + } finally { + yamlTypes.strOptions.fold.lineWidth = oldFold; + } } /** @@ -35,4 +44,4 @@ export function serializeStructure(object: any, json: boolean) { } else { return toYAML(object); } -} \ No newline at end of file +} diff --git a/packages/aws-cdk/test/test.serialize.ts b/packages/aws-cdk/test/test.serialize.ts new file mode 100644 index 0000000000000..54b1d1db6c3cc --- /dev/null +++ b/packages/aws-cdk/test/test.serialize.ts @@ -0,0 +1,12 @@ +import nodeunit = require('nodeunit'); +import { toYAML } from '../lib/serialize'; + +export = nodeunit.testCase({ + toYAML: { + 'does not wrap lines'(test: nodeunit.Test) { + const longString = 'Long string is long!'.repeat(1_024); + test.equal(toYAML({ longString }), `longString: ${longString}\n`); + test.done(); + } + } +});