@@ -252,7 +252,7 @@ const patchToolkitInfo = (ToolkitInfo) => {
252
252
await prefetchBucketUrl ( toolkitInfoObject ) ;
253
253
return toolkitInfoObject ;
254
254
} ;
255
-
255
+
256
256
const fromStackFn = ToolkitInfo . fromStack ;
257
257
ToolkitInfo . fromStack = ( ...args ) => {
258
258
const toolkitInfoObject = fromStackFn ( ...args ) ;
@@ -451,6 +451,13 @@ const patchPre_2_14 = () => {
451
451
applyPatches ( provider , CdkToolkit , SDK , ToolkitInfo ) ;
452
452
} ;
453
453
454
+ const configureEnvironment = ( ) => {
455
+ // This _must_ use localhost.localstack.cloud as we require valid subdomains of these paths to
456
+ // resolve. Unfortunately though `curl` seems to support subdomains of localhost, the CDK does not.
457
+ process . env . AWS_ENDPOINT_URL_S3 = process . env . AWS_ENDPOINT_URL_S3 || `${ PROTOCOL } ://s3.localhost.localstack.cloud:${ EDGE_PORT } ` ;
458
+ process . env . AWS_ENDPOINT_URL = process . env . AWS_ENDPOINT_URL || `${ PROTOCOL } ://localhost.localstack.cloud:${ EDGE_PORT } ` ;
459
+ } ;
460
+
454
461
const patchPost_2_14 = ( ) => {
455
462
var lib = null ;
456
463
try {
@@ -463,7 +470,27 @@ const patchPost_2_14 = () => {
463
470
}
464
471
}
465
472
466
- applyPatches ( lib , lib , lib . SDK , lib . ToolkitInfo , false ) ;
473
+ // detect if we are using version 2.177.0 or later. This version has reorganised the package
474
+ // structure so that we cannot import and patch the aws-cdk package as we did for versions
475
+ // <2.177.0. We use the specific error raised by the node require system to determine if we are
476
+ // using pre or post 2.177.0.
477
+ try {
478
+ require ( "aws-cdk/lib/legacy-exports" ) ;
479
+ } catch ( e ) {
480
+ switch ( e . code ) {
481
+ case "MODULE_NOT_FOUND" :
482
+ // pre 2.177
483
+ applyPatches ( lib , lib , lib . SDK , lib . ToolkitInfo , false ) ;
484
+ break ;
485
+ case "ERR_PACKAGE_PATH_NOT_EXPORTED" :
486
+ // post 2.177
487
+ configureEnvironment ( ) ;
488
+ break ;
489
+ default :
490
+ // a different error
491
+ throw e
492
+ }
493
+ }
467
494
} ;
468
495
469
496
if ( isEsbuildBundle ( ) ) {
0 commit comments