diff --git a/.gitignore b/.gitignore index 450c0ffc94eaf..1be7eae0b8a63 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,7 @@ coverage/ cdk.context.json .cdk.staging/ cdk.out/ +*.tabl.json +# Yarn error log +yarn-error.log diff --git a/.mergify.yml b/.mergify.yml index d58d427e27eb7..4bd8b174e4a1a 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -22,6 +22,8 @@ pull_request_rules: - -label~=(blocked|do-not-merge) - -merged - -closed + - author!=dependabot[bot] + - author!=dependabot-preview[bot] - "#approved-reviews-by>=1" - -approved-reviews-by~=author - "#changes-requested-reviews-by=0" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 521a36c30aac3..6b8b44adf9c3c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,7 @@ and let us know if it's not up-to-date (even better, submit a PR with your corr - [Updating all Dependencies](#updating-all-dependencies) - [Running CLI integration tests](#running-cli-integration-tests) - [API Compatibility Checks](#api-compatibility-checks) + - [Examples](#examples) - [Feature Flags](#feature-flags) - [Troubleshooting](#troubleshooting) - [Debugging](#debugging) @@ -201,7 +202,7 @@ The build process is divided into stages, so you can invoke them as needed from - __`yarn build`__: runs the `build` and `test` commands in all modules (in topological order). - __`yarn pack`__: packages all modules to all supported languages and produces a `dist/` directory with all the outputs - (running this script requires that you installed the [toolchains](#Toolchains) for all target languages on your + (running this script requires that you installed the [toolchains](#getting-started) for all target languages on your system). ### Partial build tools @@ -302,10 +303,17 @@ if a task fails, it will stop, and then to resume, simply run `foreach.sh` again To reset the session (either when all tasks finished or if you wish to run a different session), run: ```console -$ rm -f ~/.foreach.* +$ scripts/foreach.sh --reset ``` -This will effectively delete the state files. +If you wish to run a command only against a module's dependency closure, use: + +```console +$ cd packages/my-module +$ ../scripts/foreach.sh --up COMMAND +``` + +This will execute `COMMAND` against `my-module` and all it's deps (in a topological order of course). ### Jetbrains support (WebStorm/IntelliJ) @@ -336,7 +344,7 @@ $ ./install.sh $ yarn build ``` -If you also wish to package to all languages, make sure you have all the [toolchains](#Toolchains) and now run: +If you also wish to package to all languages, make sure you have all the [toolchains](#getting-started) and now run: ``` $ ./pack.sh @@ -375,6 +383,8 @@ $ cd packages/@aws-cdk/aws-ec2 $ ../../../scripts/buildup ``` +Note that `buildup` uses `foreach.sh`, which means it's resumable. If your build fails and you wish to resume, just run `buildup` again. If you wish to restart, run `buildup --restart`. + ### Quick Iteration After you've built the modules you want to work on once, use `lr watch` for each module that you are modifying. @@ -518,6 +528,62 @@ this API we will not break anyone, because they weren't able to use it. The file `allowed-breaking-changes.txt` in the root of the repo is an exclusion file that can be used in these cases. +### Examples + +Examples typed in fenced code blocks (looking like `'''ts`, but then with backticks +instead of regular quotes) will be automatically extrated, compiled and translated +to other languages when the bindings are generated. + +To successfully do that, they must be compilable. The easiest way to do that is using +a *fixture*, which looks like this: + +``` +'''ts fixture=with-bucket +bucket.addLifecycleTransition({ ... }); +''' +``` + +While processing the examples, the tool will look for a file called +`rosetta/with-bucket.ts-fixture` in the package directory. This file will be +treated as a regular TypeScript source file, but it must also contain the text +`/// here`, at which point the example will be inserted. The complete file must +compile properly. + +Before the `/// here` marker, the fixture should import the necessary packages +and initialize the required variables. + +If no fixture is specified, the fixture with the name +`rosetta/default.ts-fixture` will be used if present. `nofixture` can be used to +opt out of that behavior. + +In an `@example` block, which is unfenced, the first line of the example can +contain three slashes to achieve the same effect: + +``` +/** + * @example + * /// fixture=with-bucket + * bucket.addLifecycleTransition({ ... }); + */ +``` + +When including packages in your examples (even the package you're writing the +examples for), use the full package name (e.g. `import s3 = +require('@aws-cdk/aws-s3);`). The example will be compiled in an environment +where all CDK packages are available using their public names. In this way, +it's also possible to import packages that are not in the dependency set of +the current package. + +For a practical example of how making sample code compilable works, see the +`aws-ec2` package. + +Examples of all packages are extracted and compiled as part of the packaging +step. If you are working on getting rid of example compilation errors of a +single package, you can run `scripts/compile-samples` on the package by itself. + +For now, non-compiling examples will not yet block the build, but at some point +in the future they will. + ### Feature Flags Sometimes we want to introduce new breaking behavior because we believe this is @@ -550,9 +616,9 @@ The pattern is simple: 5. Under `BREAKING CHANGES` in your commit message describe this new behavior: ``` - BREAKING CHANGE: template file names for new projects created through "cdk init" - will use the template artifact ID instead of the physical stack name to enable - multiple stacks to use the same name. This is enabled through the flag + BREAKING CHANGE: template file names for new projects created through "cdk init" + will use the template artifact ID instead of the physical stack name to enable + multiple stacks to use the same name. This is enabled through the flag `@aws-cdk/core:enableStackNameDuplicates` in newly generated `cdk.json` files. ``` diff --git a/LICENSE b/LICENSE index 46c185646b439..b71ec1688783a 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/allowed-breaking-changes.txt b/allowed-breaking-changes.txt index 402968212c43d..794a8ed3e5b98 100644 --- a/allowed-breaking-changes.txt +++ b/allowed-breaking-changes.txt @@ -27,3 +27,8 @@ incompatible-argument:@aws-cdk/aws-servicediscovery.Service.fromServiceAttribute removed:@aws-cdk/core.ConstructNode.addReference removed:@aws-cdk/core.ConstructNode.references removed:@aws-cdk/core.OutgoingReference +change-return-type:@aws-cdk/aws-lambda-destinations.EventBridgeDestination.bind +change-return-type:@aws-cdk/aws-lambda-destinations.LambdaDestination.bind +change-return-type:@aws-cdk/aws-lambda-destinations.SnsDestination.bind +change-return-type:@aws-cdk/aws-lambda-destinations.SqsDestination.bind + diff --git a/pack.sh b/pack.sh index 199ad97a51c77..49166439a4777 100755 --- a/pack.sh +++ b/pack.sh @@ -25,22 +25,31 @@ function lerna_scopes() { done } -echo "Packaging jsii modules" >&2 +# Compile examples with respect to "decdk" directory, as all packages will +# be symlinked there so they can all be included. +echo "Extracting code samples" >&2 +node --experimental-worker $(which jsii-rosetta) \ + --compile \ + --output samples.tabl.json \ + --directory packages/decdk \ + $(cat $TMPDIR/jsii.txt) # Jsii packaging (all at once using jsii-pacmak) +echo "Packaging jsii modules" >&2 jsii-pacmak \ --verbose \ - --outdir $distdir/ \ + --rosetta-tablet samples.tabl.json \ $(cat $TMPDIR/jsii.txt) # Non-jsii packaging, which means running 'package' in every individual -# module and rsync'ing the result to the shared dist directory. +# module echo "Packaging non-jsii modules" >&2 lerna run $(lerna_scopes $(cat $TMPDIR/nonjsii.txt)) --sort --concurrency=1 --stream package +# Finally rsync all 'dist' directories together into a global 'dist' directory for dir in $(find packages -name dist | grep -v node_modules | grep -v run-wrappers); do - echo "Merging ${dir} into ${distdir}" - rsync -av $dir/ ${distdir}/ + echo "Merging ${dir} into ${distdir}" >&2 + rsync -a $dir/ ${distdir}/ done # Remove a JSII aggregate POM that may have snuk past diff --git a/package.json b/package.json index 6705c99ead087..938fc89aefc26 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,11 @@ "devDependencies": { "conventional-changelog-cli": "^2.0.31", "fs-extra": "^8.1.0", - "jsii-diff": "^0.20.11", - "jsii-pacmak": "^0.20.11", - "lerna": "^3.18.4", - "typescript": "~3.7.3" + "jsii-diff": "^0.21.1", + "jsii-pacmak": "^0.21.1", + "jsii-rosetta": "^0.21.1", + "lerna": "^3.20.2", + "typescript": "~3.7.4" }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/alexa-ask/.gitignore b/packages/@aws-cdk/alexa-ask/.gitignore index 7b20ed5f53385..95ee96981d6b4 100644 --- a/packages/@aws-cdk/alexa-ask/.gitignore +++ b/packages/@aws-cdk/alexa-ask/.gitignore @@ -6,7 +6,7 @@ .jsii .LAST_BUILD .LAST_PACKAGE -.nycrc +nyc.config.js .nyc_output coverage dist diff --git a/packages/@aws-cdk/alexa-ask/LICENSE b/packages/@aws-cdk/alexa-ask/LICENSE index 46c185646b439..b71ec1688783a 100644 --- a/packages/@aws-cdk/alexa-ask/LICENSE +++ b/packages/@aws-cdk/alexa-ask/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/packages/@aws-cdk/alexa-ask/NOTICE b/packages/@aws-cdk/alexa-ask/NOTICE index 8585168af8b7d..bfccac9a7f69c 100644 --- a/packages/@aws-cdk/alexa-ask/NOTICE +++ b/packages/@aws-cdk/alexa-ask/NOTICE @@ -1,2 +1,2 @@ AWS Cloud Development Kit (AWS CDK) -Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/alexa-ask/package.json b/packages/@aws-cdk/alexa-ask/package.json index 36084acf566e5..87ba87f815189 100644 --- a/packages/@aws-cdk/alexa-ask/package.json +++ b/packages/@aws-cdk/alexa-ask/package.json @@ -70,7 +70,13 @@ "branches": 60, "statements": 80 } - } + }, + "collectCoverage": true, + "coverageReporters": [ + "lcov", + "html", + "text-summary" + ] }, "license": "Apache-2.0", "devDependencies": { @@ -89,4 +95,4 @@ "node": ">= 10.3.0" }, "stability": "experimental" -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/app-delivery/.gitignore b/packages/@aws-cdk/app-delivery/.gitignore index c49007df54187..e83cd3c5e30bb 100644 --- a/packages/@aws-cdk/app-delivery/.gitignore +++ b/packages/@aws-cdk/app-delivery/.gitignore @@ -3,7 +3,7 @@ dist .LAST_BUILD .jsii .nyc_output -.nycrc +nyc.config.js tsconfig.json *.js *.d.ts diff --git a/packages/@aws-cdk/app-delivery/LICENSE b/packages/@aws-cdk/app-delivery/LICENSE index 46c185646b439..b71ec1688783a 100644 --- a/packages/@aws-cdk/app-delivery/LICENSE +++ b/packages/@aws-cdk/app-delivery/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/packages/@aws-cdk/app-delivery/NOTICE b/packages/@aws-cdk/app-delivery/NOTICE index 8585168af8b7d..bfccac9a7f69c 100644 --- a/packages/@aws-cdk/app-delivery/NOTICE +++ b/packages/@aws-cdk/app-delivery/NOTICE @@ -1,2 +1,2 @@ AWS Cloud Development Kit (AWS CDK) -Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/app-delivery/package.json b/packages/@aws-cdk/app-delivery/package.json index 1a11a6a53c71a..c369e6c6ad524 100644 --- a/packages/@aws-cdk/app-delivery/package.json +++ b/packages/@aws-cdk/app-delivery/package.json @@ -55,7 +55,7 @@ "@types/nodeunit": "^0.0.30", "cdk-build-tools": "1.19.0", "cdk-integ-tools": "1.19.0", - "fast-check": "^1.20.1", + "fast-check": "^1.21.0", "nodeunit": "^0.11.3", "pkglint": "1.19.0" }, diff --git a/packages/@aws-cdk/assert/.gitignore b/packages/@aws-cdk/assert/.gitignore index 6cff5540e188a..eb142198f6493 100644 --- a/packages/@aws-cdk/assert/.gitignore +++ b/packages/@aws-cdk/assert/.gitignore @@ -7,6 +7,6 @@ dist .LAST_BUILD .nyc_output coverage -.nycrc +nyc.config.js .LAST_PACKAGE -*.snk \ No newline at end of file +*.snk diff --git a/packages/@aws-cdk/assert/LICENSE b/packages/@aws-cdk/assert/LICENSE index 46c185646b439..b71ec1688783a 100644 --- a/packages/@aws-cdk/assert/LICENSE +++ b/packages/@aws-cdk/assert/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/packages/@aws-cdk/assert/NOTICE b/packages/@aws-cdk/assert/NOTICE index 8585168af8b7d..bfccac9a7f69c 100644 --- a/packages/@aws-cdk/assert/NOTICE +++ b/packages/@aws-cdk/assert/NOTICE @@ -1,2 +1,2 @@ AWS Cloud Development Kit (AWS CDK) -Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/assert/package.json b/packages/@aws-cdk/assert/package.json index 390800a41ad17..d485dc658a68f 100644 --- a/packages/@aws-cdk/assert/package.json +++ b/packages/@aws-cdk/assert/package.json @@ -14,10 +14,25 @@ "build+test+package": "npm run build+test && npm run package", "build+test": "npm run build && npm test" }, - "nyc": { - "statements": 40, - "lines": 40, - "branches": 30 + "jest": { + "collectCoverage": true, + "coverageReporters": [ + "lcov", + "html", + "text-summary" + ], + "coverageThreshold": { + "global": { + "statements": 80, + "lines": 80, + "branches": 60 + } + }, + "preset": "ts-jest", + "testMatch": [ + "**/__tests__/**/*.ts?(x)", + "**/?(*.)+(spec|test).ts?(x)" + ] }, "author": { "name": "Amazon Web Services", @@ -26,18 +41,19 @@ }, "license": "Apache-2.0", "devDependencies": { - "@types/jest": "^24.0.23", - "@types/nodeunit": "^0.0.30", + "@types/jest": "^24.0.25", "cdk-build-tools": "1.19.0", - "nodeunit": "^0.11.3", - "pkglint": "1.19.0" + "jest": "^24.9.0", + "pkglint": "1.19.0", + "ts-jest": "^24.2.0" }, "dependencies": { "@aws-cdk/cloudformation-diff": "1.19.0", "@aws-cdk/core": "1.19.0", - "@aws-cdk/cx-api": "1.19.0", - "jest": "^24.9.0", - "source-map-support": "^0.5.16" + "@aws-cdk/cx-api": "1.19.0" + }, + "peerDependencies": { + "jest": "^24.9.0" }, "repository": { "url": "https://github.com/aws/aws-cdk.git", diff --git a/packages/@aws-cdk/assert/test/test.assertions.ts b/packages/@aws-cdk/assert/test/assertions.test.ts similarity index 80% rename from packages/@aws-cdk/assert/test/test.assertions.ts rename to packages/@aws-cdk/assert/test/assertions.test.ts index dcfa5a602505f..26e5cb1707c5f 100644 --- a/packages/@aws-cdk/assert/test/test.assertions.ts +++ b/packages/@aws-cdk/assert/test/assertions.test.ts @@ -1,37 +1,34 @@ -import 'source-map-support/register'; - import * as cdk from '@aws-cdk/core'; import * as cx from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; -import { countResources, exist, expect, haveType, MatchStyle, matchTemplate } from '../lib/index'; +import { countResources, exist, expect as cdkExpect, haveType, MatchStyle, matchTemplate } from '../lib/index'; passingExample('expect at to have ', () => { const resourceType = 'Test::Resource'; const synthStack = synthesizedStack(stack => { new TestResource(stack, 'TestResource', { type: resourceType }); }); - expect(synthStack).at('/TestResource').to(haveType(resourceType)); + cdkExpect(synthStack).at('/TestResource').to(haveType(resourceType)); }); passingExample('expect non-synthesized stack at to have ', () => { const resourceType = 'Test::Resource'; const stack = new cdk.Stack(); new TestResource(stack, 'TestResource', { type: resourceType }); - expect(stack).at('/TestResource').to(haveType(resourceType)); + cdkExpect(stack).at('/TestResource').to(haveType(resourceType)); }); passingExample('expect at *not* to have ', () => { const resourceType = 'Test::Resource'; const synthStack = synthesizedStack(stack => { new TestResource(stack, 'TestResource', { type: resourceType }); }); - expect(synthStack).at('/TestResource').notTo(haveType('Foo::Bar')); + cdkExpect(synthStack).at('/TestResource').notTo(haveType('Foo::Bar')); }); passingExample('expect at to exist', () => { const resourceType = 'Test::Resource'; const synthStack = synthesizedStack(stack => { new TestResource(stack, 'TestResource', { type: resourceType }); }); - expect(synthStack).at('/TestResource').to(exist()); + cdkExpect(synthStack).at('/TestResource').to(exist()); }); passingExample('expect to match (exactly)