Skip to content

Commit

Permalink
Upgrade jsii (support statics) (aws#90)
Browse files Browse the repository at this point in the history
Update jsii distribution to jsii-0.4.0-pre+6248947 following
added support for static methods and properties (aws/jsii#26).

Minor fixes required to adhere to jsii support for
static methods and properties:

Rename RESOURCE_TYPE_NAME and RESOURCE_PROPERTIES
of the property registry to camelCase.

Return `any` in Resource.attribute decoration
since jsii doesn't support lambda functions.

Add tslint.json to .gitigonre since now it is created
by jsii (if it doesn't already exist).

To maintain traceability with the official jsii build
used, we now check in the bundle zip file instead of
the tarballs and expand them in ./install.sh to `./.local-npm` 
(which is not checked-in)
  • Loading branch information
Elad Ben-Israel authored Jun 13, 2018
1 parent 2f3b1ab commit 8eba865
Show file tree
Hide file tree
Showing 43 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lerna-debug.log
dist
pack
.BUILD_COMPLETED
.local-npm
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ npm run pkglint

### Updating jsii

Run `./pack.sh` in the jsii repository and copy the tarballs to `./local-npm`.
Make sure all tarballs are defined in the root `package.json`.
Download an official jsii zip bundle and replace the file under `./vendor`.
Any added dependencies, they will need to be added to the root `package.json`.

# Language Support

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export PATH=node_modules/.bin:$PATH

echo "============================================================================================="
echo "boostrapping..."
lerna bootstrap --reject-cycles --loglevel=debug
lerna bootstrap --reject-cycles

echo "============================================================================================="
echo "testing..."
Expand Down
2 changes: 1 addition & 1 deletion bundle-beta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ echo "Staging: ${staging}"
# Create a local npm repository
mkdir -p repo/npm
rsync -aL ${root}/pack/*.tgz repo/npm # cdk modules
rsync -aL ${root}/local-npm/*.tgz repo/npm # jsii modules
rsync -aL ${root}/.local-npm/*.tgz repo/npm # jsii modules

# Create a local maven repository
mkdir -p repo/maven
Expand Down
3 changes: 3 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -euo pipefail

mkdir -p .local-npm
(cd .local-npm && unzip ../vendor/*.zip)

echo "============================================================================================="
echo "installing repo-global dependencies..."
npm i --no-package-lock --global-style
1 change: 0 additions & 1 deletion local-npm/.gitignore

This file was deleted.

Binary file removed local-npm/codemaker-0.4.0-pre.tgz
Binary file not shown.
Binary file removed local-npm/jsii-0.4.0-pre.tgz
Binary file not shown.
Binary file removed local-npm/jsii-java-runtime-0.4.0-pre.tgz
Binary file not shown.
Binary file removed local-npm/jsii-kernel-0.4.0-pre.tgz
Binary file not shown.
Binary file removed local-npm/jsii-pacmak-0.4.0-pre.tgz
Binary file not shown.
Binary file removed local-npm/jsii-runtime-0.4.0-pre.tgz
Binary file not shown.
Binary file removed local-npm/jsii-spec-0.4.0-pre.tgz
Binary file not shown.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"typescript": "^2.8.3",
"tslint": "^5.10.0",
"nyc": "^11.8.0",
"jsii": "file:local-npm/jsii-0.4.0-pre.tgz",
"jsii-java-runtime": "file:local-npm/jsii-java-runtime-0.4.0-pre.tgz",
"jsii-pacmak": "file:local-npm/jsii-pacmak-0.4.0-pre.tgz",
"jsii-runtime": "file:local-npm/jsii-runtime-0.4.0-pre.tgz",
"jsii-spec": "file:local-npm/jsii-spec-0.4.0-pre.tgz",
"jsii-kernel": "file:local-npm/jsii-kernel-0.4.0-pre.tgz",
"codemaker": "file:local-npm/codemaker-0.4.0-pre.tgz"
"jsii": "file:.local-npm/jsii-0.4.0-pre.tgz",
"jsii-java-runtime": "file:.local-npm/jsii-java-runtime-0.4.0-pre.tgz",
"jsii-pacmak": "file:.local-npm/jsii-pacmak-0.4.0-pre.tgz",
"jsii-runtime": "file:.local-npm/jsii-runtime-0.4.0-pre.tgz",
"jsii-spec": "file:.local-npm/jsii-spec-0.4.0-pre.tgz",
"jsii-kernel": "file:.local-npm/jsii-kernel-0.4.0-pre.tgz",
"codemaker": "file:.local-npm/codemaker-0.4.0-pre.tgz"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/acm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cloudformation-diff/lib/diff/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function diffResource(oldValue: types.Resource, newValue: types.Resource)

function _diffProperty(oldV: any, newV: any, key: string, resourceClass?: ResourceClass) {
let changeImpact: types.ResourceImpact | undefined;
const spec = resourceClass && resourceClass.RESOURCE_PROPERTIES[key];
const spec = resourceClass && resourceClass.resourceProperties[key];
if (spec) {
switch (spec.updateType) {
case 'Immutable':
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/cloudfront/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.js
*.d.ts
tsconfig.json
tslint.json
*.js.map
dist
coverage
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/cloudtrail/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
1 change: 1 addition & 0 deletions packages/@aws-cdk/codebuild/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/codecommit/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
tsconfig.json
tslint.json
1 change: 1 addition & 0 deletions packages/@aws-cdk/codepipeline/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.js
*.d.ts
tsconfig.json
tslint.json
*.js.map
dist
coverage
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/core/lib/cloudformation/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export class Resource extends Referenceable {
/**
* A decoration used to create a CloudFormation attribute property.
* @param customName Custom name for the attribute (default is the name of the property)
* NOTE: we return "any" here to satistfy jsii, which doesn't support lambdas.
*/
public static attribute(customName?: string) {
public static attribute(customName?: string): any {
return (prototype: any, key: string) => {
const name = customName || key;
Object.defineProperty(prototype, key, {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/custom-resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
1 change: 1 addition & 0 deletions packages/@aws-cdk/cx-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
tsconfig.json
tslint.json
2 changes: 2 additions & 0 deletions packages/@aws-cdk/dynamodb/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
node_modules
dist
tsconfig.json
tslint.json

1 change: 1 addition & 0 deletions packages/@aws-cdk/ec2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/events/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/iam/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
1 change: 1 addition & 0 deletions packages/@aws-cdk/kms/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
tsconfig.json
tslint.json
2 changes: 2 additions & 0 deletions packages/@aws-cdk/lambda/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
node_modules
dist
tsconfig.json
tslint.json

1 change: 1 addition & 0 deletions packages/@aws-cdk/neptune/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/quickstarts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
1 change: 1 addition & 0 deletions packages/@aws-cdk/rds/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/route53/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
tsconfig.json
tslint.json
1 change: 1 addition & 0 deletions packages/@aws-cdk/rtv/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/s3/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
dist
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/sns/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
tsconfig.json
tslint.json
2 changes: 2 additions & 0 deletions packages/@aws-cdk/sqs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
node_modules
dist
tsconfig.json
tslint.json

4 changes: 2 additions & 2 deletions tools/cfn2ts/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ export default class CodeGenerator {
this.code.line('/**');
this.code.line(` * The CloudFormation resource type name for this resource class.`);
this.code.line(' */');
this.code.line(`public static readonly RESOURCE_TYPE_NAME = ${JSON.stringify(resourceName.specName!.fqn)};`);
this.code.line(`public static readonly resourceTypeName = ${JSON.stringify(resourceName.specName!.fqn)};`);
this.code.line();
this.code.line('/**');
this.code.line(' * The list of properties on the CloudFormation model for this resource, with their attache metadata.');
this.code.line(' */');
this.code.open(`public static readonly RESOURCE_PROPERTIES: { [name: string]: ${REGISTRY}.PropertySpecification } = {`);
this.code.open(`public static readonly resourceProperties: { [name: string]: ${REGISTRY}.PropertySpecification } = {`);
for (const pname of Object.keys(spec.Properties).sort()) {
const prop = spec.Properties[pname];
this.code.line(`${pname}: { isRequired: ${JSON.stringify(prop.Required)}, updateType: ${JSON.stringify(prop.UpdateType)} },`);
Expand Down
2 changes: 1 addition & 1 deletion tools/cfn2ts/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default async function(specFiles: string[], enrichmentsDir?: string) {
await fs.mkdirp(jsonPath);
await fs.copy(templateDir, outPath, { recursive: true });
const indexFile = fs.createWriteStream(indexPath);
indexFile.write('export { PropertySpecification, ResourceClass, resourceImplementationFor } from \'./registry\';\n\n');
indexFile.write('export * from \'./registry\';\n\n');

for (const mod of Object.keys(specByModule).sort()) {
const spec = specByModule[mod];
Expand Down
6 changes: 3 additions & 3 deletions tools/cfn2ts/module-template/lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export interface PropertySpecification {
}

export interface ResourceClass {
readonly RESOURCE_PROPERTIES: { [name: string]: PropertySpecification | undefined };
readonly RESOURCE_TYPE_NAME: string;
readonly resourceProperties: { [name: string]: PropertySpecification | undefined };
readonly resourceTypeName: string;
}

const catalog: { [resourceType: string]: ResourceClass } = {};
Expand All @@ -17,7 +17,7 @@ const catalog: { [resourceType: string]: ResourceClass } = {};
* @param resourceClass the corresponding Resource implementation.
*/
export function registerResourceType(resourceClass: ResourceClass) {
const typeName = resourceClass.RESOURCE_TYPE_NAME;
const typeName = resourceClass.resourceTypeName;
if (catalog.hasOwnProperty(typeName)) {
throw new Error(`Attempted to re-define CloudFormation resource ${typeName}`);
}
Expand Down
Binary file added vendor/jsii-0.4.0-pre+6248947.zip
Binary file not shown.

0 comments on commit 8eba865

Please sign in to comment.