@@ -27,6 +27,14 @@ function resolvePackagesDir(): string {
2727 return path . resolve ( __dirname , '../../../../../packages' ) ;
2828}
2929
30+ function materializePackage ( lambdaPath : string , packageName : string ) : void {
31+ const packagePath = path . join ( lambdaPath , 'node_modules' , ...packageName . split ( '/' ) ) ;
32+ const resolvedPackagePath = fs . realpathSync ( packagePath ) ;
33+
34+ fs . rmSync ( packagePath , { recursive : true , force : true } ) ;
35+ fs . cpSync ( resolvedPackagePath , packagePath , { recursive : true , dereference : true } ) ;
36+ }
37+
3038export class LocalLambdaStack extends Stack {
3139 constructor ( scope : Construct , id : string , props : StackProps , hostIp : string ) {
3240 console . log ( '[LocalLambdaStack] Creating local SAM Lambda Stack' ) ;
@@ -79,6 +87,15 @@ export class LocalLambdaStack extends Stack {
7987 dependencies [ name ] = `file:${ relativePath . replace ( / \\ / g, '/' ) } ` ;
8088 }
8189
90+ const awsServerlessPackageJson = JSON . parse (
91+ fs . readFileSync ( path . join ( packagesDir , 'aws-serverless' , 'package.json' ) , 'utf8' ) ,
92+ ) as { dependencies : Record < string , string > } ;
93+ const conventionsVersion = awsServerlessPackageJson . dependencies [ '@sentry/conventions' ] ;
94+ if ( ! conventionsVersion ) {
95+ throw new Error ( '[LocalLambdaStack] @sentry/aws-serverless does not declare @sentry/conventions' ) ;
96+ }
97+ dependencies [ '@sentry/conventions' ] = conventionsVersion ;
98+
8299 console . log ( `[LocalLambdaStack] Install dependencies for ${ functionName } ` ) ;
83100
84101 if ( fs . existsSync ( lockfilePath ) ) {
@@ -102,6 +119,9 @@ export class LocalLambdaStack extends Stack {
102119 stdio : 'inherit' ,
103120 } ) ;
104121
122+ // Lambda handler names cannot contain pnpm's `.pnpm` virtual-store path.
123+ materializePackage ( lambdaPath , '@sentry/aws-serverless' ) ;
124+
105125 if ( ! process . env . NODE_VERSION ) {
106126 throw new Error ( '[LocalLambdaStack] NODE_VERSION is not set' ) ;
107127 }
0 commit comments