Skip to content

Commit

Permalink
Enable declaration files in all modules (#5)
Browse files Browse the repository at this point in the history
- Upgrade local-npm packages with latest version of JSII (that enables declaration files)
- Correct `package.json` files (the `types` field points to the `.d.ts` file now)
- Correct `tsconfig.json` files for non-JSII packages, so they enable declaration files.
- Add a `.npmignore` file to prevent `npm` from using `.gitignore` instead
  + Don't pack `.ts` files, but pack `.d.ts` files instead
- The change uncovered a bunch of "poor practices", that were fixed as well:
  + Importing from the package's root (where `package.json` is) cannot work with `.d.ts` files, this was particularly frequent in tests.
  • Loading branch information
RomainMuller authored and Elad Ben-Israel committed May 31, 2018
1 parent 82bfbb9 commit 1c5a2c6
Show file tree
Hide file tree
Showing 131 changed files with 249 additions and 115 deletions.
Binary file modified local-npm/codemaker-0.4.0.tgz
Binary file not shown.
Binary file modified local-npm/jsii-0.4.0.tgz
Binary file not shown.
Binary file modified local-npm/jsii-java-runtime-0.4.0.tgz
Binary file not shown.
Binary file modified local-npm/jsii-kernel-0.4.0.tgz
Binary file not shown.
Binary file modified local-npm/jsii-pacmak-0.4.0.tgz
Binary file not shown.
Binary file modified local-npm/jsii-runtime-0.4.0.tgz
Binary file not shown.
3 changes: 3 additions & 0 deletions packages/aws-cdk-acm/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
4 changes: 2 additions & 2 deletions packages/aws-cdk-acm/lib/certificate-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export abstract class CertificateRef extends Construct {
/**
* Import a certificate
*/
public static import(parent: Construct, name: string, props: CertificateRefProps) {
public static import(parent: Construct, name: string, props: CertificateRefProps): CertificateRef {
return new ImportedCertificate(parent, name, props);
}

Expand Down Expand Up @@ -50,4 +50,4 @@ export interface CertificateRefProps {
* The certificate's ARN
*/
certificateArn: CertificateArn;
}
}
2 changes: 1 addition & 1 deletion packages/aws-cdk-acm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "CDK Constructs for AWS ACM",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [],
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-all/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
1 change: 1 addition & 0 deletions packages/aws-cdk-all/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty file just so this package can be loaded as a dependency
1 change: 1 addition & 0 deletions packages/aws-cdk-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.6.0",
"description": "A single package that provides all of the CDK dependencies",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/awslabs/aws-cdk"
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-applet-js/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-applet-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "Javascript CDK applet host program",
"main": "bin/cdk-applet-js.js",
"types": "bin/cdk-applet-js.ts",
"types": "bin/cdk-applet-js.d.ts",
"bin": {
"cdk-applet-js": "bin/cdk-applet-js"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-assert/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-assert/lib/assertions/count-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StackInspector } from "../inspector";
/**
* An assertion to check whether a resource of a given type and with the given properties exists, disregarding properties
*/
export function countResources(resourceType: string, count = 1) {
export function countResources(resourceType: string, count = 1): Assertion<StackInspector> {
return new CountResourcesAssertion(resourceType, count);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-assert/lib/assertions/have-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StackInspector } from "../inspector";
/**
* An assertion to check whether a resource of a given type and with the given properties exists, disregarding properties
*/
export function haveResource(resourceType: string, properties?: any) {
export function haveResource(resourceType: string, properties?: any): Assertion<StackInspector> {
return new HaveResourceAssertion(resourceType, properties);
}

Expand Down Expand Up @@ -73,4 +73,4 @@ function isSuperObject(superObj: any, obj: any): boolean {
return true;
}
return superObj === obj;
}
}
2 changes: 1 addition & 1 deletion packages/aws-cdk-assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "An assertion library for use with CDK Apps",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"scripts": {
"prepare": "tslint -p . && tsc && chmod +x bin/cdk-integ bin/cdk-integ-assert && pkglint",
"watch": "tsc -w",
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk-assert/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"target":"es2018",
"lib": ["es2018"],
"lib": ["es2016", "es2017.object", "es2017.string"],
"module": "commonjs",
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-cloudformation-diff/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-cloudformation-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "Utilities to diff CDK stacks against CloudFormation templates",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"scripts": {
"prepare": "tslint -p . && tsc && pkglint",
"watch": "tsc -w",
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-cloudformation-diff/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target":"ES2018",
"module": "commonjs",
"lib": ["es2016", "es2017.object", "es2017.string"],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-cloudtrail/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-cloudtrail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "CDK Constructs for AWS CloudTrail",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [],
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-cloudtrail/test/test.cloudtrail.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Stack } from 'aws-cdk';
import { expect, haveResource, not } from 'aws-cdk-assert';
import { Test } from 'nodeunit';
import { CloudTrail, LogRetention, ReadWriteType } from '..';
import { CloudTrail, LogRetention, ReadWriteType } from '../lib';

export = {
'constructs the expected resources': {
Expand Down Expand Up @@ -96,4 +96,4 @@ export = {

function getTestStack(): Stack {
return new Stack(undefined, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } });
}
}
3 changes: 3 additions & 0 deletions packages/aws-cdk-codebuild/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
4 changes: 2 additions & 2 deletions packages/aws-cdk-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Role } from 'aws-cdk-iam';
import { EncryptionKeyRef } from 'aws-cdk-kms';
import { codebuild } from 'aws-cdk-resources';
import { BucketRef } from 'aws-cdk-s3';
import { BuildSource, CodePipelineBuildArtifacts } from '..';
import { BuildArtifacts, NoBuildArtifacts } from './artifacts';
import { BuildArtifacts, CodePipelineBuildArtifacts, NoBuildArtifacts } from './artifacts';
import { BuildSource } from './source';

const CODEPIPELINE_TYPE = 'CODEPIPELINE';

Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "CDK Constructs for AWS CodeBuild",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [],
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-codebuild/test/integ.project-bucket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { App, Stack } from 'aws-cdk';
import { Bucket } from 'aws-cdk-s3';
import { BuildProject, ComputeType, S3BucketSource } from '..';
import { BuildProject, ComputeType, S3BucketSource } from '../lib';

const app = new App(process.argv);

Expand All @@ -16,4 +16,4 @@ new BuildProject(stack, 'MyProject', {
}
});

process.stdout.write(app.run());
process.stdout.write(app.run());
4 changes: 2 additions & 2 deletions packages/aws-cdk-codebuild/test/integ.project-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { App, Stack } from 'aws-cdk';
import { Repository } from 'aws-cdk-codecommit';
import { Topic } from 'aws-cdk-sns';
import { BuildProject, CodeCommitSource } from '..';
import { BuildProject, CodeCommitSource } from '../lib';

const app = new App(process.argv);

Expand Down Expand Up @@ -38,4 +38,4 @@ onCommitRule.addTarget(topic, {
}
});

process.stdout.write(app.run());
process.stdout.write(app.run());
2 changes: 1 addition & 1 deletion packages/aws-cdk-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, haveResource } from 'aws-cdk-assert';
import { Repository } from 'aws-cdk-codecommit';
import { Bucket } from 'aws-cdk-s3';
import { Test } from 'nodeunit';
import { BuildProject, CodeCommitSource, CodePipelineBuildArtifacts, CodePipelineSource, NoBuildArtifacts, S3BucketSource } from '..';
import { BuildProject, CodeCommitSource, CodePipelineBuildArtifacts, CodePipelineSource, NoBuildArtifacts, S3BucketSource } from '../lib';

// tslint:disable:object-literal-key-quotes

Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-codecommit/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-codecommit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "CDK Constructs for AWS CodeCommit",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-codecommit/test/test.codecommit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App, Stack } from 'aws-cdk';
import { Test } from 'nodeunit';
import { Repository, RepositoryProps } from '..';
import { Repository, RepositoryProps } from '../lib';

export = {
'default properties': {
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-codepipeline/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-codepipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "Better interface to AWS Code Pipeline",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-custom-resources/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-custom-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "CDK Constructs to make it easier to build custom resources",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [],
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-cx-api/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
2 changes: 1 addition & 1 deletion packages/aws-cdk-cx-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "Cloud executable protocol",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"names": {
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-dynamodb/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
6 changes: 4 additions & 2 deletions packages/aws-cdk-dynamodb/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct } from 'aws-cdk';
import { Construct, Token } from 'aws-cdk';
import { dynamodb } from 'aws-cdk-resources';

const HASH_KEY_TYPE = 'HASH';
Expand Down Expand Up @@ -55,7 +55,7 @@ export class Table extends Construct {
}

public get tableName() {
return this.table.ref;
return this.table.ref as TableName;
}

public get tableStreamArn() {
Expand Down Expand Up @@ -111,6 +111,8 @@ export class Table extends Construct {
}
}

export class TableName extends Token {}

export enum KeyAttributeType {
Binary = 'B',
Number = 'N',
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.6.0",
"description": "CDK Constructs for AWS DynamoDB",
"main": "lib/index.js",
"types": "lib/index.ts",
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"bundledDependencies": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-dynamodb/test/integ.dynamodb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Stack } from 'aws-cdk';
import { KeyAttributeType, Table } from '..';
import { KeyAttributeType, Table } from '../lib';

const app = new App(process.argv);

Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App, Stack } from 'aws-cdk';
import { Test } from 'nodeunit';
import { KeyAttributeType, Table } from '..';
import { KeyAttributeType, Table } from '../lib';

export = {
'default properties': {
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-ec2/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz
6 changes: 3 additions & 3 deletions packages/aws-cdk-ec2/lib/vpc-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export abstract class VpcNetworkRef extends Construct implements IDependable {
/**
* Import an exported VPC
*/
public static import(parent: Construct, name: string, props: VpcNetworkRefProps) {
public static import(parent: Construct, name: string, props: VpcNetworkRefProps): VpcNetworkRef {
return new ImportedVpcNetwork(parent, name, props);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ export class VpcNetworkId extends Token {
* A new or imported VPC Subnet
*/
export abstract class VpcSubnetRef extends Construct implements IDependable {
public static import(parent: Construct, name: string, props: VpcSubnetRefProps) {
public static import(parent: Construct, name: string, props: VpcSubnetRefProps): VpcSubnetRef {
return new ImportedVpcSubnet(parent, name, props);
}

Expand Down Expand Up @@ -224,4 +224,4 @@ function range(n: number): number[] {
ret.push(i);
}
return ret;
}
}
Loading

0 comments on commit 1c5a2c6

Please sign in to comment.