Skip to content

Commit

Permalink
chore: deprecate @aws-cdk/yaml-cfn (aws#14001)
Browse files Browse the repository at this point in the history
`aws-cdk-lib` needs to have no dependencies (except for `constructs`),
and we don't want to support this package as part of its public API.
Therefore, it needs to be bundled into all packages that consume it.

NPM has a bug that makes it impossible to `bundledDependencies` a
package that is linked from the monorepo.

We tried to work around that bug but it blocked our build because the
`.tgz` is sometimes not available during the `postpack` phase (aws#13933).

Simplest way around this now is to just copy/paste the implementation
of `yaml-cfn` 3 times. Should we ever need to bundle monorepo
dependencies again in the future, we can try to revive the `postpack`
solution of aws#13933.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Apr 7, 2021
1 parent b1ecd3d commit 2b0e562
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 22 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"nohoist": [
"**/jszip",
"**/jszip/**",
"@aws-cdk/aws-codebuild/yaml",
"@aws-cdk/aws-codebuild/yaml/**",
"@aws-cdk/aws-codepipeline-actions/case",
"@aws-cdk/aws-codepipeline-actions/case/**",
"@aws-cdk/aws-cognito/punycode",
Expand All @@ -63,6 +65,8 @@
"@aws-cdk/cloud-assembly-schema/jsonschema/**",
"@aws-cdk/cloud-assembly-schema/semver",
"@aws-cdk/cloud-assembly-schema/semver/**",
"@aws-cdk/cloudformation-include/yaml",
"@aws-cdk/cloudformation-include/yaml/**",
"@aws-cdk/core/@balena/dockerignore",
"@aws-cdk/core/@balena/dockerignore/**",
"@aws-cdk/core/fs-extra",
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-codebuild/NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
AWS Cloud Development Kit (AWS CDK)
Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

-------------------------------------------------------------------------------

The AWS CDK includes the following third-party software/licensing:

** yaml - https://www.npmjs.com/package/yaml
Copyright 2018 Eemeli Aro <eemeli@gmail.com>

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

----------------
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/lib/build-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IResolveContext, Lazy, Stack } from '@aws-cdk/core';
import * as yaml_cfn from '@aws-cdk/yaml-cfn';
import * as yaml_cfn from './private/yaml-cfn';

/**
* BuildSpec for CodeBuild projects
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/private/yaml-cfn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as yaml from 'yaml';
import * as yaml_types from 'yaml/types';

/**
* Serializes the given data structure into valid YAML.
*
* @param obj the data structure to serialize
* @returns a string containing the YAML representation of {@param obj}
*/
export function serialize(obj: any): string {
const oldFold = yaml_types.strOptions.fold.lineWidth;
try {
yaml_types.strOptions.fold.lineWidth = 0;
return yaml.stringify(obj, { schema: 'yaml-1.1' });
} finally {
yaml_types.strOptions.fold.lineWidth = oldFold;
}
}
9 changes: 6 additions & 3 deletions packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@
"@aws-cdk/aws-secretsmanager": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/region-info": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"constructs": "^3.3.69"
"constructs": "^3.3.69",
"yaml": "1.10.2"
},
"bundledDependencies": [
"yaml"
],
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"@aws-cdk/assets": "0.0.0",
"@aws-cdk/aws-cloudwatch": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
Expand All @@ -119,7 +123,6 @@
"@aws-cdk/aws-secretsmanager": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/region-info": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"constructs": "^3.3.69"
},
"engines": {
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/cloudformation-include/NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
AWS Cloud Development Kit (AWS CDK)
Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

-------------------------------------------------------------------------------

The AWS CDK includes the following third-party software/licensing:

** yaml - https://www.npmjs.com/package/yaml
Copyright 2018 Eemeli Aro <eemeli@gmail.com>

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

----------------
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cloudformation-include/lib/file-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import * as yaml_cfn from '@aws-cdk/yaml-cfn';
import * as yaml_cfn from './private/yaml-cfn';

export function readJsonSync(filePath: string): any {
const fileContents = fs.readFileSync(filePath);
Expand Down
60 changes: 60 additions & 0 deletions packages/@aws-cdk/cloudformation-include/lib/private/yaml-cfn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as yaml from 'yaml';
import * as yaml_cst from 'yaml/parse-cst';
import * as yaml_types from 'yaml/types';

/**
* Serializes the given data structure into valid YAML.
*
* @param obj the data structure to serialize
* @returns a string containing the YAML representation of {@param obj}
*/
export function serialize(obj: any): string {
const oldFold = yaml_types.strOptions.fold.lineWidth;
try {
yaml_types.strOptions.fold.lineWidth = 0;
return yaml.stringify(obj, { schema: 'yaml-1.1' });
} finally {
yaml_types.strOptions.fold.lineWidth = oldFold;
}
}

/**
* Deserialize the YAML into the appropriate data structure.
*
* @param str the string containing YAML
* @returns the data structure the YAML represents
* (most often in case of CloudFormation, an object)
*/
export function deserialize(str: string): any {
return parseYamlStrWithCfnTags(str);
}

function makeTagForCfnIntrinsic(intrinsicName: string, addFnPrefix: boolean): yaml_types.Schema.CustomTag {
return {
identify(value: any) { return typeof value === 'string'; },
tag: `!${intrinsicName}`,
resolve: (_doc: yaml.Document, cstNode: yaml_cst.CST.Node) => {
const ret: any = {};
ret[addFnPrefix ? `Fn::${intrinsicName}` : intrinsicName] =
// the +1 is to account for the ! the short form begins with
parseYamlStrWithCfnTags(cstNode.toString().substring(intrinsicName.length + 1));
return ret;
},
};
}

const shortForms: yaml_types.Schema.CustomTag[] = [
'Base64', 'Cidr', 'FindInMap', 'GetAZs', 'ImportValue', 'Join', 'Sub',
'Select', 'Split', 'Transform', 'And', 'Equals', 'If', 'Not', 'Or', 'GetAtt',
].map(name => makeTagForCfnIntrinsic(name, true)).concat(
makeTagForCfnIntrinsic('Ref', false),
makeTagForCfnIntrinsic('Condition', false),
);

function parseYamlStrWithCfnTags(text: string): any {
return yaml.parse(text, {
customTags: shortForms,
schema: 'core',
});
}

8 changes: 5 additions & 3 deletions packages/@aws-cdk/cloudformation-include/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
"@aws-cdk/aws-wafv2": "0.0.0",
"@aws-cdk/aws-workspaces": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"constructs": "^3.3.69"
"constructs": "^3.3.69",
"yaml": "1.10.2"
},
"peerDependencies": {
"@aws-cdk/alexa-ask": "0.0.0",
Expand Down Expand Up @@ -363,7 +363,6 @@
"@aws-cdk/aws-wafv2": "0.0.0",
"@aws-cdk/aws-workspaces": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"constructs": "^3.3.69"
},
"devDependencies": {
Expand All @@ -375,6 +374,9 @@
"ts-jest": "^26.5.4",
"@aws-cdk/assert-internal": "0.0.0"
},
"bundledDependencies": [
"yaml"
],
"keywords": [
"aws",
"cdk",
Expand Down
8 changes: 2 additions & 6 deletions packages/@aws-cdk/yaml-cfn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@

---

![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
![Deprecated](https://img.shields.io/badge/deprecated-critical.svg?style=for-the-badge)

> The APIs of higher level constructs in this module are experimental and under active development.
> They are subject to non-backward compatible changes or removal in any future version. These are
> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
> announced in the release notes. This means that while you may use them, you may need to update
> your source code when upgrading to a newer version of this package.
> This API may emit warnings. Backward compatibility is not guaranteed.
---

Expand Down
5 changes: 3 additions & 2 deletions packages/@aws-cdk/yaml-cfn/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@aws-cdk/yaml-cfn",
"deprecated": "This module is no longer supported and will be removed in a future release.",
"version": "0.0.0",
"description": "Utilities for handling CloudFormation-flavored YAML",
"main": "lib/index.js",
Expand Down Expand Up @@ -82,8 +83,8 @@
"engines": {
"node": ">= 10.13.0 <13 || >=13.7.0"
},
"stability": "experimental",
"maturity": "experimental",
"stability": "deprecated",
"maturity": "deprecated",
"awscdkio": {
"announce": false
},
Expand Down
1 change: 0 additions & 1 deletion packages/aws-cdk-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@
"@aws-cdk/lambda-layer-kubectl": "0.0.0",
"@aws-cdk/pipelines": "0.0.0",
"@aws-cdk/region-info": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"@types/fs-extra": "^8.1.1",
"@types/node": "^10.17.56",
"cdk-build-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as yaml_cfn from '@aws-cdk/yaml-cfn';
import * as fs from 'fs-extra';
import * as yaml_cfn from './util/yaml-cfn';

/**
* Stringify to YAML
Expand Down
59 changes: 59 additions & 0 deletions packages/aws-cdk/lib/util/yaml-cfn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as yaml from 'yaml';
import * as yaml_cst from 'yaml/parse-cst';
import * as yaml_types from 'yaml/types';

/**
* Serializes the given data structure into valid YAML.
*
* @param obj the data structure to serialize
* @returns a string containing the YAML representation of {@param obj}
*/
export function serialize(obj: any): string {
const oldFold = yaml_types.strOptions.fold.lineWidth;
try {
yaml_types.strOptions.fold.lineWidth = 0;
return yaml.stringify(obj, { schema: 'yaml-1.1' });
} finally {
yaml_types.strOptions.fold.lineWidth = oldFold;
}
}

/**
* Deserialize the YAML into the appropriate data structure.
*
* @param str the string containing YAML
* @returns the data structure the YAML represents
* (most often in case of CloudFormation, an object)
*/
export function deserialize(str: string): any {
return parseYamlStrWithCfnTags(str);
}

function makeTagForCfnIntrinsic(intrinsicName: string, addFnPrefix: boolean): yaml_types.Schema.CustomTag {
return {
identify(value: any) { return typeof value === 'string'; },
tag: `!${intrinsicName}`,
resolve: (_doc: yaml.Document, cstNode: yaml_cst.CST.Node) => {
const ret: any = {};
ret[addFnPrefix ? `Fn::${intrinsicName}` : intrinsicName] =
// the +1 is to account for the ! the short form begins with
parseYamlStrWithCfnTags(cstNode.toString().substring(intrinsicName.length + 1));
return ret;
},
};
}

const shortForms: yaml_types.Schema.CustomTag[] = [
'Base64', 'Cidr', 'FindInMap', 'GetAZs', 'ImportValue', 'Join', 'Sub',
'Select', 'Split', 'Transform', 'And', 'Equals', 'If', 'Not', 'Or', 'GetAtt',
].map(name => makeTagForCfnIntrinsic(name, true)).concat(
makeTagForCfnIntrinsic('Ref', false),
makeTagForCfnIntrinsic('Condition', false),
);

function parseYamlStrWithCfnTags(text: string): any {
return yaml.parse(text, {
customTags: shortForms,
schema: 'core',
});
}
2 changes: 1 addition & 1 deletion packages/aws-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@aws-cdk/cloudformation-diff": "0.0.0",
"@aws-cdk/cx-api": "0.0.0",
"@aws-cdk/region-info": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"archiver": "^5.3.0",
"aws-sdk": "^2.848.0",
"camelcase": "^6.2.0",
Expand All @@ -89,6 +88,7 @@
"table": "^6.0.9",
"uuid": "^8.3.2",
"wrap-ansi": "^7.0.0",
"yaml": "1.10.2",
"yargs": "^16.2.0"
},
"repository": {
Expand Down
1 change: 0 additions & 1 deletion packages/decdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"@aws-cdk/lambda-layer-kubectl": "0.0.0",
"@aws-cdk/pipelines": "0.0.0",
"@aws-cdk/region-info": "0.0.0",
"@aws-cdk/yaml-cfn": "0.0.0",
"constructs": "^3.3.69",
"fs-extra": "^9.1.0",
"jsii-reflect": "^1.27.0",
Expand Down
2 changes: 0 additions & 2 deletions tools/pkglint/lib/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,6 @@ export class MustDependonCdkByPointVersions extends ValidationRule {
'@aws-cdk/cx-api',
'@aws-cdk/cloud-assembly-schema',
'@aws-cdk/region-info',
'@aws-cdk/yaml-cfn',
];

for (const [depName, depVersion] of Object.entries(pkg.dependencies)) {
Expand Down Expand Up @@ -1574,7 +1573,6 @@ export class UbergenPackageVisibility extends ValidationRule {
'@aws-cdk/cloudformation-diff',
'@aws-cdk/cx-api',
'@aws-cdk/region-info',
'@aws-cdk/yaml-cfn',
'aws-cdk-lib',
'aws-cdk',
'awslint',
Expand Down

0 comments on commit 2b0e562

Please sign in to comment.