@@ -985,6 +985,50 @@ class LocalstackPlugin {
985
985
return ;
986
986
}
987
987
}
988
+
989
+ function patchPreV3 ( ) {
990
+ const utilFile = customResources . getEntry ( 'utils.js' ) ;
991
+ if ( utilFile == null ) return ;
992
+ const data = utilFile . getData ( ) . toString ( ) ;
993
+ const legacyPatch = 'AWS.config.s3ForcePathStyle = true;' ;
994
+ if ( data . includes ( legacyPatch ) ) {
995
+ createPatchMarker ( ) ;
996
+ return true ;
997
+ }
998
+ const patchIndex = data . indexOf ( 'AWS.config.logger = console;' ) ;
999
+ if ( patchIndex === - 1 ) {
1000
+ return false ;
1001
+ }
1002
+ const newData =
1003
+ data . slice ( 0 , patchIndex ) + legacyPatch + '\n' + data . slice ( patchIndex ) ;
1004
+ utilFile . setData ( newData ) ;
1005
+ return true ;
1006
+ }
1007
+
1008
+ function patchV3 ( ) {
1009
+ this . debug (
1010
+ 'serverless-localstack: Patching V3' ,
1011
+ ) ;
1012
+ const customResourcesBucketFile = customResources . getEntry ( 's3/lib/bucket.js' ) ;
1013
+ if ( customResourcesBucketFile == null ) {
1014
+ // TODO debugging, remove
1015
+ this . log (
1016
+ 'serverless-localstack: Could not find file s3/lib/bucket.js to patch.' ,
1017
+ ) ;
1018
+ return ;
1019
+ }
1020
+ const data = customResourcesBucketFile . getData ( ) . toString ( ) ;
1021
+ const oldClientCreation = 'S3Client({ maxAttempts: MAX_AWS_REQUEST_TRY });' ;
1022
+ const newClientCreation = 'S3Client({ maxAttempts: MAX_AWS_REQUEST_TRY, forcePathStyle: true });' ;
1023
+ if ( data . includes ( newClientCreation ) ) {
1024
+ // patch already done
1025
+ createPatchMarker ( ) ;
1026
+ return ;
1027
+ }
1028
+ const newData = data . replace ( oldClientCreation , newClientCreation ) ;
1029
+
1030
+ customResourcesBucketFile . setData ( newData ) ;
1031
+ }
988
1032
989
1033
if ( fileExists ( patchMarker ) ) {
990
1034
this . debug (
@@ -1000,18 +1044,10 @@ class LocalstackPlugin {
1000
1044
}
1001
1045
1002
1046
const customResources = new AdmZip ( zipFilePath ) ;
1003
- const utilFile = customResources . getEntry ( 'utils.js' ) ;
1004
- if ( utilFile == null ) return ;
1005
- const data = utilFile . getData ( ) . toString ( ) ;
1006
- const patch = 'AWS.config.s3ForcePathStyle = true;' ;
1007
- if ( data . includes ( patch ) ) {
1008
- createPatchMarker ( ) ;
1009
- return ;
1047
+
1048
+ if ( ! patchPreV3 . call ( this ) ) {
1049
+ patchV3 . call ( this ) ;
1010
1050
}
1011
- const indexPatch = data . indexOf ( 'AWS.config.logger = console;' ) ;
1012
- const newData =
1013
- data . slice ( 0 , indexPatch ) + patch + '\n' + data . slice ( indexPatch ) ;
1014
- utilFile . setData ( newData ) ;
1015
1051
customResources . writeZip ( ) ;
1016
1052
createPatchMarker ( ) ;
1017
1053
this . debug (
0 commit comments