@@ -65,6 +65,38 @@ const appendToCDKContext = (projectPath: string, additionalContext: Record<strin
6565 writeFileSync ( cdkJsonPath , JSON . stringify ( cdkJson , null , 2 ) ) ;
6666} ;
6767
68+ /**
69+ * Pinned version of the `aws-cdk` CLI used to scaffold e2e test projects.
70+ *
71+ * The CLI must be pinned independently of `aws-cdk-lib`: the two have used separate version lines since CLI v2.1000.0, so there is no
72+ * `aws-cdk` release matching a modern `aws-cdk-lib` version. Leaving the CLI floating means `cdk init` silently picks up upstream template
73+ * changes, which has broken e2e groups before (the template switched the synth command from `ts-node` to `tsc && tsx`, turning synth into a
74+ * whole-project typecheck).
75+ */
76+ const CDK_CLI_VERSION = '2.1134.0' ;
77+
78+ /**
79+ * Removes the whole-project `tsc` typecheck from the generated `cdk.json` synth command.
80+ *
81+ * Backend templates are copied wholesale into the scratch project's `bin/` directory, and some of those files are lambda entry points that
82+ * are only ever referenced by esbuild as a path string -- they are never imported by `app.ts`. A whole-project typecheck compiles them
83+ * anyway, in a directory they were never written to resolve from, failing synth before it starts. Transpiling only the import graph (the
84+ * historical behavior) keeps synth scoped to code the app actually loads.
85+ */
86+ const removeWholeProjectTypecheckFromSynth = ( projectPath : string ) : void => {
87+ const cdkJsonPath = path . join ( projectPath , 'cdk.json' ) ;
88+ const cdkJson = JSON . parse ( readFileSync ( cdkJsonPath , 'utf-8' ) ) ;
89+ if ( typeof cdkJson . app !== 'string' ) {
90+ return ;
91+ }
92+ const appWithoutTypecheck = cdkJson . app . replace ( / ^ \s * n p x \s + t s c \s * & & \s * / , '' ) ;
93+ if ( appWithoutTypecheck === cdkJson . app ) {
94+ return ;
95+ }
96+ cdkJson . app = appWithoutTypecheck ;
97+ writeFileSync ( cdkJsonPath , JSON . stringify ( cdkJson , null , 2 ) ) ;
98+ } ;
99+
68100export type InitCDKProjectProps = {
69101 construct ?: CdkConstruct ;
70102 cdkContext ?: Record < string , string > ;
@@ -82,7 +114,7 @@ export type InitCDKProjectProps = {
82114export const initCDKProject = async ( cwd : string , templatePath : string , props ?: InitCDKProjectProps ) : Promise < string > => {
83115 const { cdkVersion = '2.260.0' , additionalDependencies = [ ] } = props ?? { } ;
84116
85- await spawn ( getNpxPath ( ) , [ ' cdk' , 'init' , 'app' , '--language' , 'typescript' ] , {
117+ await spawn ( getNpxPath ( ) , [ `aws- cdk@ ${ CDK_CLI_VERSION } ` , 'init' , 'app' , '--language' , 'typescript' ] , {
86118 cwd,
87119 stripColors : true ,
88120 // npx cdk does not work on verdaccio
@@ -93,6 +125,8 @@ export const initCDKProject = async (cwd: string, templatePath: string, props?:
93125 . sendYes ( )
94126 . runAsync ( ) ;
95127
128+ removeWholeProjectTypecheckFromSynth ( cwd ) ;
129+
96130 if ( props ?. cdkContext ) {
97131 appendToCDKContext ( cwd , props . cdkContext ) ;
98132 }
0 commit comments