Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecate @aws-cdk/yaml-cfn #14001

Merged
merged 7 commits into from
Apr 7, 2021
Merged

chore: deprecate @aws-cdk/yaml-cfn #14001

merged 7 commits into from
Apr 7, 2021

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Apr 6, 2021

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 (#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 #13933.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

`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 (#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 #13933.
@rix0rrr rix0rrr requested a review from a team April 6, 2021 13:10
@rix0rrr rix0rrr self-assigned this Apr 6, 2021
@gitpod-io
Copy link

gitpod-io bot commented Apr 6, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Apr 6, 2021
* @param obj the data structure to serialize
* @returns a string containing the YAML representation of {@param obj}
*/
export function serialize(obj: any): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this to 'core' and reduce the dupes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI still cannot depend on core so doesn't help that much.

Also it should not be part of the public API, this package is/was an implementation detail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not a strong opinion but) put it in cx-api but not export it? Usage would be -

import * as yaml_cfn from '@aws-cdk/cx-api/yaml-cfn'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tricks/hacks for making things in core not public. See cfn-parse.ts, for example.

@rix0rrr rix0rrr requested a review from nija-at April 6, 2021 14:21
@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Apr 6, 2021
* @param obj the data structure to serialize
* @returns a string containing the YAML representation of {@param obj}
*/
export function serialize(obj: any): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not a strong opinion but) put it in cx-api but not export it? Usage would be -

import * as yaml_cfn from '@aws-cdk/cx-api/yaml-cfn'

Comment on lines 21 to 59
/**
* 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',
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only use serialize in CodeBuild, let's maybe remove all this?

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Apr 7, 2021
@mergify
Copy link
Contributor

mergify bot commented Apr 7, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Apr 7, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 2b0e562 into master Apr 7, 2021
@mergify mergify bot deleted the huijbers/remove-yaml-cfn branch April 7, 2021 12:28
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 96d6e4e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
`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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants