fix(cdk)!: rename DotStack.env to envName for aws-cdk-lib >=2.234.0 compat#7
Merged
shellscape merged 2 commits intoshellscape:masterfrom Apr 27, 2026
Merged
Conversation
…ompat In aws-cdk-lib 2.234.0 (PR aws/aws-cdk#36599, released 2026-01-08), Stack.env was changed from a writable property to a getter returning the resolved AWS Environment object. DotStack's `this.env = env;` assignment in the constructor now throws: TypeError: Cannot set property env of [object Object] which has only a getter. Resolution: rename the deploy-environment string field on DotStack to envName, leaving the parent Stack.env getter unshadowed. After this change, stack.env returns the AWS { account, region } object and stack.envName returns the deploy-environment string ('prod', 'dev', etc.). All internal call sites that read scope.env as a string have been updated to scope.envName (dynamo.ts, signing.ts, amplify.ts, function.ts, node-function.ts, ws.ts). A peerDependency on aws-cdk-lib >=2.234.0 has been added to enforce version compatibility, since v5 is incompatible with versions before 2.234.0 (DotStack would set the field but consumers reading stack.envName would get undefined). BREAKING CHANGE: DotStack.env is renamed to DotStack.envName. Consumer code reading stack.env as a deploy-environment string should be updated to read stack.envName. The node.tryGetContext('env') context key is unchanged for backward compatibility.
shellscape
reviewed
Apr 27, 2026
| { | ||
| "name": "@dot/cdk", | ||
| "version": "4.2.1", | ||
| "version": "5.0.0", |
Owner
There was a problem hiding this comment.
Suggested change
| "version": "5.0.0", | |
| "version": "4.2.1", |
This is automatic with release tooling.
shellscape
reviewed
Apr 27, 2026
| }, | ||
| "engines": { | ||
| "node": ">=18" | ||
| "node": ">=20" |
Owner
There was a problem hiding this comment.
Suggested change
| "node": ">=20" | |
| "node": ">=22" |
Node 20 is end of life in 3 days
Contributor
Author
shellscape
reviewed
Apr 27, 2026
| "peerDependencies": { | ||
| "@swc-node/register": "^1.5.4", | ||
| "@swc/core": "^1.3.5", | ||
| "aws-cdk-lib": "^2.234.0", |
Owner
There was a problem hiding this comment.
Suggested change
| "aws-cdk-lib": "^2.234.0", |
It's already a direct dependency
- Revert version to 4.2.1 (release tooling auto-bumps from breaking commit marker; see @dot/versioner) - Bump engines.node from >=20 to >=22 (Node 20 EOL imminent) - Drop aws-cdk-lib peerDependencies entry (already a direct dependency) - Trim README sentence referencing the removed peerDep Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains a:
Are tests included?
Breaking Changes?
Description
In aws-cdk-lib 2.234.0 (released 2026-01-08, via aws/aws-cdk#36599), the parent
Stack.envwas changed from a writable property to a getter that returns the resolved AWSEnvironmentobject ({ account, region }).DotStack's constructor doesthis.env = env;(whereenvis the deploy-environment string'prod'/'dev'/etc.), which now throws:This collision has existed conceptually for a while —
DotStackrepurposed the parent'senvname to mean "deploy-env string" rather than "AWS environment object" — but the runtime didn't surface it until aws-cdk-lib hardened the property descriptor.Resolution
Rename the deploy-environment string field on
DotStackfromenvtoenvName, leaving the parent'sStack.envgetter unshadowed. After this change:stack.envNamereturns the deploy-environment string ('prod','dev', etc.).stack.envreturns the inheritedaws-cdk-libgetter ({ account, region }).All internal call sites that read
scope.envas a string have been updated toscope.envName(amplify.ts,dynamo.ts,fargate.ts,function.ts,node-function.ts,signing.ts,ws.ts). This includes two destructured-access patterns (const { env } = scope) infargate.tsandnode-function.tsthat would silently break otherwise.The
node.setContext('env', this.envName)call preserves the context key'env'for backwards compatibility — consumer code readingnode.tryGetContext('env')continues to work.Adjacent dep alignment
Tightened a couple of pre-existing dep mismatches with the new
aws-cdk-libfloor while we're here:peerDependencies.aws-cdk-lib: added at^2.234.0(was previously dependencies-only; now correctly dedupes with the consumer's CDK install).dependencies.aws-cdk-lib: bumped from^2.185.0to^2.234.0.engines.node:>=18→>=20(matchesaws-cdk-lib@2.251.0's engine requirement).constructs:^10.4.2→^10.5.0(matchesaws-cdk-lib@2.251.0's peer requirement).Happy to split those out if you'd prefer the PR scope to stay strictly on the env rename.
Verification
pnpm --filter @dot/cdk buildpasses (TypeScript compile).pnpm lintclean (one pre-existing warning insecurity.ts, unrelated).new DotStack(app, { name: 'smoke' })withDEPLOY_ENV=prodnow succeeds (noTypeError);stack.envName === 'prod';stack.envreturns the parent getter's{ account, region }.grep -rn "scope\\.env\\b\\|this\\.env\\b" packages/cdk/src/empty — no straggling string-env reads.Migration
A "Migrating from v4 to v5" section has been added to
packages/cdk/README.mdsummarizing the rename and flagging the destructured / template-literal cases that consumers might miss.BREAKING CHANGES:
DotStack.envis renamed toDotStack.envName. Consumer code readingstack.envas a deploy-environment string should be updated tostack.envName. Thenode.tryGetContext('env')context key is unchanged.