From 09d6ff90b08b9c467e393e2fd0a778b7f5d67360 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: Tue, 9 Oct 2018 12:34:01 +0200 Subject: [PATCH] fix: Emit valid YAML-1.1 `yamljs` would emit YAML version 1.2, but CloudFormation expects YAML version 1.1. The differences between versions include some surrogate representations of booleans (`ON`, `OFF`, `YES`, ...) that are no longer supported in 1.2. This changes implementation to `js-yaml`, which makes extra effort in emitting YAML that is compatible with previous versions of the standard. Fixes #875 --- packages/aws-cdk/bin/cdk.ts | 6 +++--- packages/aws-cdk/lib/api/deploy-stack.ts | 4 ++-- packages/aws-cdk/package.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 827aedb6e8ee0..b853e17cc0961 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -5,11 +5,11 @@ import cxapi = require('@aws-cdk/cx-api'); import childProcess = require('child_process'); import colors = require('colors/safe'); import fs = require('fs-extra'); +import YAML = require('js-yaml'); import minimatch = require('minimatch'); import os = require('os'); import path = require('path'); import util = require('util'); -import YAML = require('yamljs'); import yargs = require('yargs'); import cdkUtil = require('../lib/util'); @@ -676,7 +676,7 @@ async function initCommandLine() { /* Attempt to parse YAML, fall back to JSON. */ function parseTemplate(text: string): any { try { - return YAML.parse(text); + return YAML.safeLoad(text); } catch (e) { return JSON.parse(text); } @@ -785,7 +785,7 @@ async function initCommandLine() { } else { const inlineJsonAfterDepth = 16; const indentWidth = 4; - return YAML.stringify(object, inlineJsonAfterDepth, indentWidth); + return YAML.safeDump(object, { indent: indentWidth, flowLevel: inlineJsonAfterDepth }); } } } diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 5400dd7e66f87..3d2ec112f0341 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -1,8 +1,8 @@ import cxapi = require('@aws-cdk/cx-api'); import aws = require('aws-sdk'); import colors = require('colors/safe'); +import YAML = require('js-yaml'); import uuid = require('uuid'); -import YAML = require('yamljs'); import { prepareAssets } from '../assets'; import { debug, error } from '../logging'; import { Mode } from './aws-auth/credentials'; @@ -94,7 +94,7 @@ async function getStackOutputs(cfn: aws.CloudFormation, stackName: string): Prom * @param toolkitInfo information about the toolkit stack */ async function makeBodyParameter(stack: cxapi.SynthesizedStack, toolkitInfo?: ToolkitInfo): Promise { - const templateJson = YAML.stringify(stack.template, 16, 4); + const templateJson = YAML.safeDump(stack.template, { indent: 4, flowLevel: 16 }); if (toolkitInfo) { const s3KeyPrefix = `cdk/${stack.name}/`; const s3KeySuffix = '.yml'; diff --git a/packages/aws-cdk/package.json b/packages/aws-cdk/package.json index 0dd1a244e783d..560e0efba2111 100644 --- a/packages/aws-cdk/package.json +++ b/packages/aws-cdk/package.json @@ -37,7 +37,7 @@ "@types/mockery": "^1.4.29", "@types/request": "^2.47.1", "@types/uuid": "^3.4.3", - "@types/yamljs": "^0.2.0", + "@types/js-yaml": "^3.11.2", "@types/yargs": "^8.0.3", "cdk-build-tools": "^0.10.0", "mockery": "^2.1.0", @@ -58,7 +58,7 @@ "proxy-agent": "^3.0.1", "request": "^2.83.0", "source-map-support": "^0.5.6", - "yamljs": "^0.2.0", + "js-yaml": "^3.12.0", "yargs": "^9.0.1" }, "repository": {