Skip to content

Commit

Permalink
fix: Emit valid YAML-1.1 (#876)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
RomainMuller authored Oct 9, 2018
1 parent 1561a4d commit 3cedc0c
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
}
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
@@ -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<TemplateBodyParameter> {
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';
4 changes: 2 additions & 2 deletions packages/aws-cdk/package.json
Original file line number Diff line number Diff line change
@@ -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": {

0 comments on commit 3cedc0c

Please sign in to comment.