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

[BREAKING] Move @aws-cdk/resources classes into L2 packages #264

Merged
merged 6 commits into from
Jul 10, 2018

Conversation

RomainMuller
Copy link
Contributor

The create_missing_libraries.sh script was used to bootstrap L2
packages for all the namespaces that didn't have one already.

Existing L2 packages were manually edited to:

  • Invoke cfn2ts to generate the L1 class library for the service/scope
  • Depend on @aws-cdk/runtime (which used to be blended in
    @aws-cdk/resources, and was extracted out)
  • Export the L1 library as expected

The @aws-cdk/assert behavior was changed to rely on
@aws-cdk/cloudformation-resource-spec to determine the UpdateType of
attributes, rendering the registry mechanism that was introduced to
@aws-cdk/resources a while ago redundant (hence it got dropped).

Bonus: Renamed the prepare command in all package.json to build (Fixes #197).

The `create_missing_libraries.sh` script was used to bootstrap L2
packages for all the namespaces that didn't have one already.

Existing L2 packages were manually edited to:
- Invoke `cfn2ts` to generate the L1 class library for the service/scope
- Depend on `@aws-cdk/runtime` (which used to be blended in
  `@aws-cdk/resources`, and was extracted out)
- Export the L1 library as expected

The `@aws-cdk/assert` behavior was changed to rely on
`@aws-cdk/cloudformation-resource-spec` to determine the `UpdateType` of
attributes, rendering the `registry` mechanism that was introduced to
`@aws-cdk/resources` a while ago redundant (hence it got dropped).
@rix0rrr
Copy link
Contributor

rix0rrr commented Jul 9, 2018

Can we merge @aws-cdk/runtime back into each package? I'd prefer minimizing dependencies, and it's not huge. (We do need to check that it doesn't use instanceof anywhere because that's definitely going to break)

@rix0rrr
Copy link
Contributor

rix0rrr commented Jul 9, 2018

Also, if you're asking me, this PR is trying to do too many things at once. But I understand it's going to be a bitch trying to factor those out, so never mind.

@rix0rrr
Copy link
Contributor

rix0rrr commented Jul 9, 2018

I thought the plan was to put CFN resources into a cloudformation namespace? Is that off the table?

Although I understand that might complicate export of the property types.

@RomainMuller
Copy link
Contributor Author

I agree with there being lots in this PR, but yeas, isolating each individual change is an order of magnitude more work to just build & un-build stuff so it si buildable & all... I know it sucks.

Regarding @aws-cdk/runtime, I don't like the idea of duplicating the classes everywhere. Parts of what's interesting in isolating in own package is that said package comes with it's own test suite, which previously was blended with @aws-cdk/resources (when the code being tested was defined in cfn2ts in the form of a template fragment).

Regarding the cloudformation namespace, it can be done... Would have to create a namespace specifically for the Resource classes, which may make the code generation logic more complex (but nothing impossible).

echo "boostrapping..."
lerna bootstrap --reject-cycles
echo "building..."
lerna exec --stream "npm run build"
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this build symlinks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, lerna bootstrap will have done that at the install.sh step. I can duplicate the bootstrap command, though if you feel it's better... It's incredibly cheap to run.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should automatically run ./install.sh is node_modules doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already do (L4-6 in build.sh).

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

🥇

Please generate all resource types into the cloudformation namespace.

echo "boostrapping..."
lerna bootstrap --reject-cycles
echo "building..."
lerna exec --stream "npm run build"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should automatically run ./install.sh is node_modules doesn't exist.

@@ -0,0 +1,97 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Use hyphens in file names create-missing-libraries.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

echo "⏳ Creating package ${P} for scope ${S}..."
mkdir -p packages/${P}/test
mkdir -p packages/${P}/lib
echo '*.js' >> packages/${P}/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please use HEREDOCs instead? Will be wayyyy more readable...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I find the fact that HEREDOCs require you to break indentation very disturbing, BTW).

Copy link
Contributor

Choose a reason for hiding this comment

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

I know. Me too, but they are still way better than this 😜

@@ -1,2 +1,5 @@
export * from './certificate';
export * from './certificate-ref';

// The L1 library for AWS::CertificateManager:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the terminology AWS::CertificateManager CloudFormation resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,2 @@
// The L1 Library for AWS::ApiGateway:
export * from '../cfn/apigateway';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the generated code should go under lib/cloudformation/

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, make sure cfn2ts creates a README file under the generated directory that says that it is generated and from which spec date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That information is already included in the generated file itself... Do we really need it repeated?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you are right.

this.code.openFile(this.outputFile);

const meta = {
generatedOn: new Date(),
Copy link
Contributor

Choose a reason for hiding this comment

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

so java.... I would go with generated and fingerprint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const prop = spec.Properties[pname];
if (prop.Required) {
const propName = pname.toLocaleLowerCase() === 'name' ? resourceNameProperty(resourceName.specName!) : pname;
this.code.line(`this.required(properties, '${genspec.cloudFormationToScriptName(propName)}');`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was just about to deprecate construct.required. Can you just add this to runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


generator.addSpec(spec);
if (force || !await generator.upToDate(outPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: prefer early bailout: if (!force && await upToDate) { return; }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -25,6 +25,7 @@
},
"license": "LicenseRef-LICENSE",
"dependencies": {
"@aws-cdk/cloudformation-resource-spec": "^0.7.3-beta",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd call this package @aws-cdk/cloudformation-spec or even @aws-cdk/cfnspec. Keep 'em short!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wish this was said on the two occasions I asked for naming suggestions 🤨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming to @aws-cdk/cdk-cfnspec.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Are we doing the cdk-xxx as part of this change, or just this one for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just this one. This changeset is already bloated enough I think :)

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I was worried that you are crazier than I thought

},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta",
"@aws-cdk/runtime": "^0.7.3-beta"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just merge runtime into core? I agree with @rix0rrr - doesn't seem like a useful module. And also, the name is way too presumptuous for what it's doing 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Much prefer this than duplicating it into every generated package.

- Namespace resource and property classes under 'cloudformation'
- Merge @aws-cdk/runtime into @aws-cdk/core
- Rename @aws-cdk/clouformation-resource-spec to @aws-cdk/cdk-cfnspec
- Generate code into lib/<ns>.generated.ts
Disabling use of '--reject-cycles' on 'lerna bootstrap' as it would blow up on the cycle
created by (e.g:) how aws-cdk uses @aws-cdk/s3, which itself uses @aws-cdk/assert.
@RomainMuller RomainMuller merged commit aa404a0 into master Jul 10, 2018
@RomainMuller RomainMuller deleted the rmuller/split-resources branch July 10, 2018 15:06
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
@pahud pahud mentioned this pull request Nov 19, 2019
2 tasks
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.

Move our build scripts from “npm prepare” to “npm run build”
4 participants