Skip to content

Commit 86e63f8

Browse files
authored
chore: bringing the changes from v2-main to master related to the experimental modules (aws#16401)
Bringing the changes from `v2-main` to `master` related to the experimental modules. These changes were made directly in `v2-main` because the version of the `@aws-cdk/assert` library compatible with `aws-cdk-lib` only existed in `v2-main`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 816a319 commit 86e63f8

File tree

26 files changed

+773
-13
lines changed

26 files changed

+773
-13
lines changed

buildspec-pr.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ phases:
1414
- yarn --version || npm -g install yarn
1515
build:
1616
commands:
17-
- /bin/bash ./build.sh --extract && git diff-index --exit-code --ignore-space-at-eol --stat HEAD
17+
- /bin/bash ./build.sh --extract
18+
- /bin/bash ./scripts/transform.sh --extract
19+
- git diff-index --exit-code --ignore-space-at-eol --stat HEAD

buildspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ phases:
1717
- 'if ${BUMP_CANDIDATE:-false}; then /bin/bash ./scripts/bump-candidate.sh; fi'
1818
- /bin/bash ./scripts/align-version.sh
1919
- /bin/bash ./build.sh
20+
- /bin/bash ./scripts/transform.sh
2021
post_build:
2122
commands:
2223
- "[ -f .BUILD_COMPLETED ] && /bin/bash ./pack.sh"

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171
"nohoist": [
7272
"**/jszip",
7373
"**/jszip/**",
74+
"@aws-cdk/assertions-alpha/colors",
75+
"@aws-cdk/assertions-alpha/colors/**",
76+
"@aws-cdk/assertions-alpha/diff",
77+
"@aws-cdk/assertions-alpha/diff/**",
78+
"@aws-cdk/assertions-alpha/fast-deep-equal",
79+
"@aws-cdk/assertions-alpha/fast-deep-equal/**",
80+
"@aws-cdk/assertions-alpha/string-width",
81+
"@aws-cdk/assertions-alpha/string-width/**",
82+
"@aws-cdk/assertions-alpha/table",
83+
"@aws-cdk/assertions-alpha/table/**",
7484
"@aws-cdk/assertions/colors",
7585
"@aws-cdk/assertions/colors/**",
7686
"@aws-cdk/assertions/diff",

packages/@aws-cdk/assertions/vendor-in.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ echo "⏳ Vendoring in modules..."
1717

1818
scriptdir=$(cd $(dirname $0) && pwd)
1919
cd $scriptdir
20+
21+
if [[ "$PHASE" == "transform" ]]; then
22+
# Make the script short-circuit when running in the packages/individual-packages build context.
23+
# That's required because the build done by individual-pkg-gen does import re-writing when copying the TS files
24+
# (because it needs to know which modules are also unstable to do the rewriting correctly),
25+
# but the vendor.sh script runs only after the 'build' script for this package has been invoked,
26+
# which means any TS files copied by it successfully would not have their imports re-written.
27+
exit 0
28+
fi
29+
2030
set -euo pipefail
2131
dest="lib/vendored"
2232
mkdir -p $dest
@@ -44,4 +54,4 @@ They also cannot be bundled since they are part of the monorepo.
4454
Instead vendor them directly into the assertv2 library.
4555
EOF
4656

47-
echo "✅ Vendoring complete"
57+
echo "✅ Vendoring complete"

packages/@aws-cdk/aws-kinesisfirehose-destinations/test/integ.s3-bucket.lit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
/// !cdk-integ pragma:ignore-assets
23
import * as path from 'path';
34
import * as firehose from '@aws-cdk/aws-kinesisfirehose';
45
import * as kms from '@aws-cdk/aws-kms';

packages/aws-cdk-migration/lib/rewrite.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import * as ts from 'typescript';
22

3+
/**
4+
* The options for rewriting the file.
5+
*/
6+
export interface RewriteOptions {
7+
/**
8+
* Optional module names that should result in replacing to something different than just 'aws-cdk-lib'.
9+
*/
10+
readonly customModules?: { [moduleName: string]: string };
11+
}
12+
313
/**
414
* Re-writes "hyper-modular" CDK imports (most packages in `@aws-cdk/*`) to the
515
* relevant "mono" CDK import path. The re-writing will only modify the imported
@@ -21,14 +31,14 @@ import * as ts from 'typescript';
2131
*
2232
* @returns the updated source code.
2333
*/
24-
export function rewriteImports(sourceText: string, fileName: string = 'index.ts'): string {
34+
export function rewriteImports(sourceText: string, fileName: string = 'index.ts', options: RewriteOptions = {}): string {
2535
const sourceFile = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.ES2018);
2636

2737
const replacements = new Array<{ original: ts.Node, updatedLocation: string }>();
2838

2939
const visitor = <T extends ts.Node>(node: T): ts.VisitResult<T> => {
3040
const moduleSpecifier = getModuleSpecifier(node);
31-
const newTarget = moduleSpecifier && updatedLocationOf(moduleSpecifier.text);
41+
const newTarget = moduleSpecifier && updatedLocationOf(moduleSpecifier.text, options);
3242

3343
if (moduleSpecifier != null && newTarget != null) {
3444
replacements.push({ original: moduleSpecifier, updatedLocation: newTarget });
@@ -92,11 +102,20 @@ const EXEMPTIONS = new Set([
92102
'@aws-cdk/cloudformation-diff',
93103
]);
94104

95-
function updatedLocationOf(modulePath: string): string | undefined {
105+
function updatedLocationOf(modulePath: string, options: RewriteOptions): string | undefined {
106+
const customModulePath = options.customModules?.[modulePath];
107+
if (customModulePath) {
108+
return customModulePath;
109+
}
110+
96111
if (!modulePath.startsWith('@aws-cdk/') || EXEMPTIONS.has(modulePath)) {
97112
return undefined;
98113
}
99114

115+
if (modulePath.startsWith('@aws-cdk/core/lib')) {
116+
return `aws-cdk-lib/lib/core/lib/${modulePath.substring('@aws-cdk/core/lib/'.length)}`;
117+
}
118+
100119
if (modulePath === '@aws-cdk/core') {
101120
return 'aws-cdk-lib';
102121
}
@@ -106,6 +125,12 @@ function updatedLocationOf(modulePath: string): string | undefined {
106125
return '@aws-cdk/assert';
107126
}
108127

128+
// can't use simple equality here,
129+
// because we have imports like "import '@aws-cdk/assert-internal/jest'"
130+
if (modulePath.startsWith('@aws-cdk/assert-internal')) {
131+
return modulePath.replace(/^@aws-cdk\/assert-internal/, '@aws-cdk/assert');
132+
}
133+
109134
if (modulePath === '@aws-cdk/assert/jest') {
110135
return '@aws-cdk/assert/jest';
111136
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
In this directory we generate at build time all individual packages in V2
2+
that we release separately from `aws-cdk-lib`
3+
(right now, those are the experimental and developer preview packages).
4+
5+
The packages are generated by the [`individual-pkg-gen` tool](../../tools/individual-pkg-gen).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"lerna": "3.15.0",
3+
"npmClient": "yarn",
4+
"packages": [
5+
"*"
6+
],
7+
"rejectCycles": "true",
8+
"version": "independent"
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "individual-packages",
3+
"version": "0.0.0",
4+
"private": true,
5+
"devDependencies": {
6+
"lerna": "^4.0.0"
7+
}
8+
}

0 commit comments

Comments
 (0)