Skip to content

Commit e2c8063

Browse files
authored
chore(v2): literate examples missing from v2 (#18118)
The literate examples are `test/*.lit.ts` files that are included in the `README`s by jsii. Ubergen didn't copy `test` files, because there were issues with the test dependency `@aws-cdk/assert` which couldn't be included into `aws-cdk-lib`. In this PR, add copying of only the literate source files to `ubergen` so that we can include the examples again in READMEs. It is safe since those are integration tests that don't depend on `@aws-cdk/assert` (which is only used by unit tests). Updated some EKS integ tests to no longer depend on test files that don't get copied by this mechanism (`./util.ts`). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0fd80e1 commit e2c8063

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

packages/@aws-cdk/aws-eks-legacy/test/integ.eks-cluster.lit.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as ec2 from '@aws-cdk/aws-ec2';
22
import * as cdk from '@aws-cdk/core';
33
import * as eks from '../lib';
4-
import { TestStack } from './util';
54

6-
class EksClusterStack extends TestStack {
5+
const env = {
6+
region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION,
7+
account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
8+
};
9+
10+
class EksClusterStack extends cdk.Stack {
711
constructor(scope: cdk.App, id: string) {
8-
super(scope, id);
12+
super(scope, id, { env });
913

1014
/// !show
1115
const vpc = new ec2.Vpc(this, 'VPC');

packages/@aws-cdk/aws-eks-legacy/test/integ.eks-helm.lit.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22

33
import * as ec2 from '@aws-cdk/aws-ec2';
44
import * as iam from '@aws-cdk/aws-iam';
5-
import { App } from '@aws-cdk/core';
5+
import { App, Stack } from '@aws-cdk/core';
66
import { Construct } from 'constructs';
77
import { Cluster } from '../lib';
8-
import { TestStack } from './util';
98

10-
class VpcStack extends TestStack {
9+
const env = {
10+
region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION,
11+
account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
12+
};
13+
14+
class VpcStack extends Stack {
1115
public readonly vpc: ec2.Vpc;
1216

1317
constructor(scope: Construct, id: string) {
14-
super(scope, id);
18+
super(scope, id, { env });
1519
this.vpc = new ec2.Vpc(this, 'vpc', { maxAzs: 2 });
1620
}
1721
}
1822

19-
class ClusterStack extends TestStack {
23+
class ClusterStack extends Stack {
2024
public readonly cluster: Cluster;
2125

2226
constructor(scope: Construct, id: string, props: { vpc: ec2.Vpc }) {
23-
super(scope, id);
27+
super(scope, id, { env });
2428

2529
/// !show
2630
// define the cluster. kubectl is enabled by default.

packages/@aws-cdk/aws-eks-legacy/test/integ.eks-kubectl.lit.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22

33
import * as ec2 from '@aws-cdk/aws-ec2';
44
import * as iam from '@aws-cdk/aws-iam';
5-
import { App } from '@aws-cdk/core';
5+
import { App, Stack } from '@aws-cdk/core';
66
import { Construct } from 'constructs';
77
import { Cluster } from '../lib';
8-
import { TestStack } from './util';
98

10-
class VpcStack extends TestStack {
9+
const env = {
10+
region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION,
11+
account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
12+
};
13+
14+
class VpcStack extends Stack {
1115
public readonly vpc: ec2.Vpc;
1216

1317
constructor(scope: Construct, id: string) {
14-
super(scope, id);
18+
super(scope, id, { env });
1519
this.vpc = new ec2.Vpc(this, 'vpc', { maxAzs: 2 });
1620
}
1721
}
1822

19-
class ClusterStack extends TestStack {
23+
class ClusterStack extends Stack {
2024
public readonly cluster: Cluster;
2125

2226
constructor(scope: Construct, id: string, props: { vpc: ec2.Vpc }) {
23-
super(scope, id);
27+
super(scope, id, { env });
2428

2529
/// !show
2630
// define the cluster. kubectl is enabled by default.

packages/aws-cdk-lib/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,17 @@
373373
},
374374
"exports": {
375375
".": "./index.js",
376+
"./package.json": "./package.json",
377+
"./.jsii": "./.jsii",
378+
"./.warnings.jsii.js": "./.warnings.jsii.js",
376379
"./alexa-ask": "./alexa-ask/index.js",
377380
"./assertions": "./assertions/index.js",
378381
"./assets": "./assets/index.js",
379382
"./aws-accessanalyzer": "./aws-accessanalyzer/index.js",
380383
"./aws-acmpca": "./aws-acmpca/index.js",
381384
"./aws-amazonmq": "./aws-amazonmq/index.js",
382385
"./aws-amplify": "./aws-amplify/index.js",
386+
"./aws-amplifyuibuilder": "./aws-amplifyuibuilder/index.js",
383387
"./aws-apigateway": "./aws-apigateway/index.js",
384388
"./aws-apigatewayv2": "./aws-apigatewayv2/index.js",
385389
"./aws-appconfig": "./aws-appconfig/index.js",
@@ -458,6 +462,7 @@
458462
"./aws-events": "./aws-events/index.js",
459463
"./aws-events-targets": "./aws-events-targets/index.js",
460464
"./aws-eventschemas": "./aws-eventschemas/index.js",
465+
"./aws-evidently": "./aws-evidently/index.js",
461466
"./aws-finspace": "./aws-finspace/index.js",
462467
"./aws-fis": "./aws-fis/index.js",
463468
"./aws-fms": "./aws-fms/index.js",
@@ -495,6 +500,7 @@
495500
"./aws-lambda-destinations": "./aws-lambda-destinations/index.js",
496501
"./aws-lambda-event-sources": "./aws-lambda-event-sources/index.js",
497502
"./aws-lambda-nodejs": "./aws-lambda-nodejs/index.js",
503+
"./aws-lex": "./aws-lex/index.js",
498504
"./aws-licensemanager": "./aws-licensemanager/index.js",
499505
"./aws-lightsail": "./aws-lightsail/index.js",
500506
"./aws-location": "./aws-location/index.js",
@@ -528,7 +534,9 @@
528534
"./aws-ram": "./aws-ram/index.js",
529535
"./aws-rds": "./aws-rds/index.js",
530536
"./aws-redshift": "./aws-redshift/index.js",
537+
"./aws-refactorspaces": "./aws-refactorspaces/index.js",
531538
"./aws-rekognition": "./aws-rekognition/index.js",
539+
"./aws-resiliencehub": "./aws-resiliencehub/index.js",
532540
"./aws-resourcegroups": "./aws-resourcegroups/index.js",
533541
"./aws-robomaker": "./aws-robomaker/index.js",
534542
"./aws-route53": "./aws-route53/index.js",
@@ -537,6 +545,7 @@
537545
"./aws-route53recoverycontrol": "./aws-route53recoverycontrol/index.js",
538546
"./aws-route53recoveryreadiness": "./aws-route53recoveryreadiness/index.js",
539547
"./aws-route53resolver": "./aws-route53resolver/index.js",
548+
"./aws-rum": "./aws-rum/index.js",
540549
"./aws-s3": "./aws-s3/index.js",
541550
"./aws-s3-assets": "./aws-s3-assets/index.js",
542551
"./aws-s3-deployment": "./aws-s3-deployment/index.js",
@@ -580,6 +589,9 @@
580589
"./lambda-layer-kubectl": "./lambda-layer-kubectl/index.js",
581590
"./lambda-layer-node-proxy-agent": "./lambda-layer-node-proxy-agent/index.js",
582591
"./pipelines": "./pipelines/index.js",
592+
"./pipelines/package.json": "./pipelines/package.json",
593+
"./pipelines/.jsii": "./pipelines/.jsii",
594+
"./pipelines/.warnings.jsii.js": "./pipelines/.warnings.jsii.js",
583595
"./pipelines/lib/helpers-internal": "./pipelines/lib/helpers-internal/index.js",
584596
"./region-info": "./region-info/index.js"
585597
}

tools/@aws-cdk/ubergen/bin/ubergen.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ async function transformPackage(
378378
await copyOrTransformFiles(destination, destination, allLibraries, uberPackageJson);
379379
} else {
380380
await copyOrTransformFiles(library.root, destination, allLibraries, uberPackageJson);
381+
await copyLiterateSources(path.join(library.root, 'test'), path.join(destination, 'test'), allLibraries, uberPackageJson);
381382
}
382383

383384
await fs.writeFile(
@@ -507,6 +508,23 @@ async function copyOrTransformFiles(from: string, to: string, libraries: readonl
507508
await Promise.all(promises);
508509
}
509510

511+
async function copyLiterateSources(from: string, to: string, libraries: readonly LibraryReference[], uberPackageJson: PackageJson) {
512+
const libRoot = resolveLibRoot(uberPackageJson);
513+
await Promise.all((await fs.readdir(from)).flatMap(async name => {
514+
if (!name.endsWith('.lit.ts')) {
515+
return [];
516+
}
517+
518+
await fs.mkdirp(to);
519+
520+
return fs.writeFile(
521+
path.join(to, name),
522+
await rewriteLibraryImports(path.join(from, name), to, libRoot, libraries),
523+
{ encoding: 'utf8' },
524+
);
525+
}));
526+
}
527+
510528
/**
511529
* Rewrites the imports in README.md from v1 ('@aws-cdk') to v2 ('aws-cdk-lib') or monocdk ('monocdk').
512530
*/
@@ -594,4 +612,4 @@ function unixPath(x: string) {
594612
*/
595613
function resolveLibRoot(uberPackageJson: PackageJson): string {
596614
return path.resolve(uberPackageJson.ubergen?.libRoot ?? MONOPACKAGE_ROOT);
597-
}
615+
}

0 commit comments

Comments
 (0)