forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: deprecate
@aws-cdk/yaml-cfn
(aws#14001)
`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
Showing
17 changed files
with
203 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
---------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
---------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/@aws-cdk/cloudformation-include/lib/private/yaml-cfn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters