Skip to content

Commit b5ab43f

Browse files
authored
Merge pull request #12 from alma-cdk/feature/allow-cdk-version-override
feat: add cdkVersion option to AlmaCdkConstructLibraryOptions
2 parents ed58898 + 2db5163 commit b5ab43f

5 files changed

Lines changed: 46 additions & 7 deletions

File tree

API.md

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AlmaCdkConstructLibrary.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { uniqueKeywordsCaseInsensitive } from './uniqueKeywordsCaseInsensitive';
1212

1313
export type { AlmaCdkConstructLibraryOptions } from './schemas/almaCdkConstructLibraryOptions';
1414

15-
const CDK_VERSION = '2.220.0';
1615
const CONSTRUCTS_VERSION = '10.3.0';
1716
const JSII_VERSION = '~5.9.0';
1817
const JEST_VERSION = '^30';
@@ -101,7 +100,6 @@ function buildAwsCdkConstructLibraryOptions(
101100
? buildPublishToGoOptions(validatedOptions.repositoryUrl)
102101
: undefined,
103102
// CDK
104-
cdkVersion: CDK_VERSION,
105103
constructsVersion: CONSTRUCTS_VERSION,
106104
// Git & dev
107105
gitignore: [...DEFAULT_GITIGNORE_PATTERNS],

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { CDK_DEFAULT_VERSION } from './schemas/almaCdkConstructLibraryOptions';
12
export {
23
AlmaCdkConstructLibrary,
34
type AlmaCdkConstructLibraryOptions,

src/schemas/almaCdkConstructLibraryOptions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function coerceValidSemver(value: string): semver.SemVer | null {
1616
}
1717

1818
/**
19-
* Node/engine version: must be valid semver or coercible to one (e.g. major-only `20`).
19+
* Version string: valid semver or coercible to one (e.g. major-only `20`, full `2.220.0`).
2020
* Parsed output is the original string — no normalization (e.g. `20` stays `20`, not `20.0.0`).
2121
*/
22-
const nodeVersionStringSchema = z.string().refine(
22+
const versionStringSchema = z.string().refine(
2323
(s) => coerceValidSemver(s) != null,
2424
{ message: 'Must be a valid semver or coercible to one' },
2525
);
@@ -79,6 +79,8 @@ export interface AlmaCdkConstructLibraryOptions {
7979
readonly pnpmSettings?: PnpmWorkspaceSpecification;
8080
/** Appended to generated `sonar-project.properties` after the default lines (e.g. Sonar multicriteria ignores). */
8181
readonly sonarProjectPropertiesExtraLines?: string[];
82+
/** AWS CDK version for the generated library (semver or coercible, same rules as Node version fields); when omitted, defaults to the exported `CDK_DEFAULT_VERSION` constant. */
83+
readonly cdkVersion?: string;
8284
readonly golang?: boolean;
8385
readonly python?: boolean;
8486
}
@@ -92,6 +94,9 @@ const NODEJS_MIN_VERSION = '20';
9294
const NODEJS_MAX_VERSION = '24';
9395
const NODEJS_WORKFLOW_VERSION = NODEJS_MAX_VERSION;
9496

97+
/** Default AWS CDK version passed to projen when `cdkVersion` is omitted from options. */
98+
export const CDK_DEFAULT_VERSION = '2.220.0';
99+
95100

96101
/** Projen AwsCdkConstructLibrary options with validation and defaults (min/max/workflow Node versions, package name, etc.). */
97102
// JSII cannot infer this schema shape cleanly, so we keep the runtime schema
@@ -114,11 +119,12 @@ export const almaCdkConstructLibraryOptionsSchema = z
114119
devDeps: z.array(z.string()).optional(),
115120
bundledDeps: z.array(z.string()).optional(),
116121
codeCov: z.boolean().default(false),
117-
minNodeVersion: nodeVersionStringSchema.default(NODEJS_MIN_VERSION),
118-
workflowNodeVersion: nodeVersionStringSchema.default(NODEJS_WORKFLOW_VERSION),
119-
maxNodeVersion: nodeVersionStringSchema.default(NODEJS_MAX_VERSION),
122+
minNodeVersion: versionStringSchema.default(NODEJS_MIN_VERSION),
123+
workflowNodeVersion: versionStringSchema.default(NODEJS_WORKFLOW_VERSION),
124+
maxNodeVersion: versionStringSchema.default(NODEJS_MAX_VERSION),
120125
pnpmSettings: pnpmSettingsSchema.optional(),
121126
sonarProjectPropertiesExtraLines: z.array(z.string()).optional(),
127+
cdkVersion: versionStringSchema.default(CDK_DEFAULT_VERSION),
122128
golang: z.boolean().default(true),
123129
python: z.boolean().default(true),
124130
})

test/schemas/almaCdkConstructLibraryOptions.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { cdk } from 'projen';
22
import {
33
almaCdkConstructLibraryOptionsSchema,
44
branchOptionsSchema,
5+
CDK_DEFAULT_VERSION,
56
} from '../../src/schemas/almaCdkConstructLibraryOptions';
67

78
const validBaseOptions = {
@@ -68,6 +69,7 @@ describe('almaCdkConstructLibraryOptionsSchema', () => {
6869
expect(result.minNodeVersion).toBe('20');
6970
expect(result.workflowNodeVersion).toBe('24');
7071
expect(result.maxNodeVersion).toBe('24');
72+
expect(result.cdkVersion).toBe(CDK_DEFAULT_VERSION);
7173
});
7274

7375
it('applies default Node versions when omitted', () => {
@@ -88,6 +90,23 @@ describe('almaCdkConstructLibraryOptionsSchema', () => {
8890
expect(result.codeCov).toBe(true);
8991
});
9092

93+
it('accepts cdkVersion override', () => {
94+
const result = almaCdkConstructLibraryOptionsSchema.parse({
95+
...validBaseOptions,
96+
cdkVersion: '2.100.0',
97+
});
98+
expect(result.cdkVersion).toBe('2.100.0');
99+
});
100+
101+
it('rejects invalid semver for cdkVersion', () => {
102+
expect(() =>
103+
almaCdkConstructLibraryOptionsSchema.parse({
104+
...validBaseOptions,
105+
cdkVersion: 'not-semver',
106+
}),
107+
).toThrow();
108+
});
109+
91110
it('accepts custom Node versions when min <= workflow <= max', () => {
92111
const result = almaCdkConstructLibraryOptionsSchema.parse({
93112
...validBaseOptions,

0 commit comments

Comments
 (0)