@@ -21,16 +21,13 @@ function run(cmd: string, options?: childProcess.ExecSyncOptions): string {
21
21
*/
22
22
async function buildLambdaLayer ( ) : Promise < void > {
23
23
console . log ( 'Building Lambda layer.' ) ;
24
+ buildPackageJson ( ) ;
24
25
console . log ( 'Installing local @sentry/aws-serverless into build/aws/dist-serverless/nodejs.' ) ;
25
-
26
- console . log ( 'Creating target directory for npm install.' ) ;
27
- fsForceMkdirSync ( './build/aws/dist-serverless/nodejs' ) ;
28
-
29
- run ( 'npm install . --prefix ./build/aws/dist-serverless/nodejs --install-links' ) ;
26
+ run ( 'yarn install --prod --cwd ./build/aws/dist-serverless/nodejs' ) ;
30
27
31
28
await pruneNodeModules ( ) ;
32
29
fs . rmSync ( './build/aws/dist-serverless/nodejs/package.json' , { force : true } ) ;
33
- fs . rmSync ( './build/aws/dist-serverless/nodejs/package-lock.json ' , { force : true } ) ;
30
+ fs . rmSync ( './build/aws/dist-serverless/nodejs/yarn.lock ' , { force : true } ) ;
34
31
35
32
// The layer also includes `awslambda-auto.js`, a helper file which calls `Sentry.init()` and wraps the lambda
36
33
// handler. It gets run when Node is launched inside the lambda, using the environment variable
@@ -142,3 +139,42 @@ function getAllFiles(dir: string): string[] {
142
139
walkDirectory ( dir ) ;
143
140
return files ;
144
141
}
142
+
143
+ function buildPackageJson ( ) : void {
144
+ console . log ( 'Building package.json' ) ;
145
+ const packagesDir = path . resolve ( __dirname , '..' ) ;
146
+ const packageDirs = fs
147
+ . readdirSync ( packagesDir , { withFileTypes : true } )
148
+ . filter ( dirent => dirent . isDirectory ( ) )
149
+ . map ( dirent => dirent . name )
150
+ . filter ( name => ! name . startsWith ( '.' ) ) // Skip hidden directories
151
+ . sort ( ) ;
152
+
153
+ const resolutions : Record < string , string > = { } ;
154
+
155
+ for ( const packageDir of packageDirs ) {
156
+ const packageJsonPath = path . join ( packagesDir , packageDir , 'package.json' ) ;
157
+ if ( fs . existsSync ( packageJsonPath ) ) {
158
+ try {
159
+ const packageContent = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) as { name ?: string } ;
160
+ const packageName = packageContent . name ;
161
+ if ( typeof packageName === 'string' && packageName ) {
162
+ resolutions [ packageName ] = `file:../../../../../../packages/${ packageDir } ` ;
163
+ }
164
+ } catch {
165
+ console . warn ( `Warning: Could not read package.json for ${ packageDir } ` ) ;
166
+ }
167
+ }
168
+ }
169
+
170
+ const packageJson = {
171
+ dependencies : {
172
+ '@sentry/aws-serverless' : version ,
173
+ } ,
174
+ resolutions,
175
+ } ;
176
+
177
+ fsForceMkdirSync ( './build/aws/dist-serverless/nodejs' ) ;
178
+ const packageJsonPath = './build/aws/dist-serverless/nodejs/package.json' ;
179
+ fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
180
+ }
0 commit comments