Skip to content

Commit 3cedc0c

Browse files
authored
fix: Emit valid YAML-1.1 (#876)
`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
1 parent 1561a4d commit 3cedc0c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

packages/aws-cdk/bin/cdk.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import cxapi = require('@aws-cdk/cx-api');
55
import childProcess = require('child_process');
66
import colors = require('colors/safe');
77
import fs = require('fs-extra');
8+
import YAML = require('js-yaml');
89
import minimatch = require('minimatch');
910
import os = require('os');
1011
import path = require('path');
1112
import util = require('util');
12-
import YAML = require('yamljs');
1313
import yargs = require('yargs');
1414
import cdkUtil = require('../lib/util');
1515

@@ -676,7 +676,7 @@ async function initCommandLine() {
676676
/* Attempt to parse YAML, fall back to JSON. */
677677
function parseTemplate(text: string): any {
678678
try {
679-
return YAML.parse(text);
679+
return YAML.safeLoad(text);
680680
} catch (e) {
681681
return JSON.parse(text);
682682
}
@@ -785,7 +785,7 @@ async function initCommandLine() {
785785
} else {
786786
const inlineJsonAfterDepth = 16;
787787
const indentWidth = 4;
788-
return YAML.stringify(object, inlineJsonAfterDepth, indentWidth);
788+
return YAML.safeDump(object, { indent: indentWidth, flowLevel: inlineJsonAfterDepth });
789789
}
790790
}
791791
}

packages/aws-cdk/lib/api/deploy-stack.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import cxapi = require('@aws-cdk/cx-api');
22
import aws = require('aws-sdk');
33
import colors = require('colors/safe');
4+
import YAML = require('js-yaml');
45
import uuid = require('uuid');
5-
import YAML = require('yamljs');
66
import { prepareAssets } from '../assets';
77
import { debug, error } from '../logging';
88
import { Mode } from './aws-auth/credentials';
@@ -94,7 +94,7 @@ async function getStackOutputs(cfn: aws.CloudFormation, stackName: string): Prom
9494
* @param toolkitInfo information about the toolkit stack
9595
*/
9696
async function makeBodyParameter(stack: cxapi.SynthesizedStack, toolkitInfo?: ToolkitInfo): Promise<TemplateBodyParameter> {
97-
const templateJson = YAML.stringify(stack.template, 16, 4);
97+
const templateJson = YAML.safeDump(stack.template, { indent: 4, flowLevel: 16 });
9898
if (toolkitInfo) {
9999
const s3KeyPrefix = `cdk/${stack.name}/`;
100100
const s3KeySuffix = '.yml';

packages/aws-cdk/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@types/mockery": "^1.4.29",
3838
"@types/request": "^2.47.1",
3939
"@types/uuid": "^3.4.3",
40-
"@types/yamljs": "^0.2.0",
40+
"@types/js-yaml": "^3.11.2",
4141
"@types/yargs": "^8.0.3",
4242
"cdk-build-tools": "^0.10.0",
4343
"mockery": "^2.1.0",
@@ -58,7 +58,7 @@
5858
"proxy-agent": "^3.0.1",
5959
"request": "^2.83.0",
6060
"source-map-support": "^0.5.6",
61-
"yamljs": "^0.2.0",
61+
"js-yaml": "^3.12.0",
6262
"yargs": "^9.0.1"
6363
},
6464
"repository": {

0 commit comments

Comments
 (0)