Skip to content

Commit bf9dfc3

Browse files
committed
fix: cleanup ngcc file for lambda layer
1 parent f8824a4 commit bf9dfc3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/aws-serverless/scripts/buildLambdaLayer.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function run(cmd: string, options?: childProcess.ExecSyncOptions): string {
2222
async function buildLambdaLayer(): Promise<void> {
2323
console.log('Building Lambda layer.');
2424
buildPackageJson();
25+
// Clean up Angular ngcc lock files that can cause yarn install to fail when using file: dependencies
26+
cleanupNgccLockFiles();
2527
console.log('Installing local @sentry/aws-serverless into build/aws/dist-serverless/nodejs.');
2628
run('yarn install --prod --cwd ./build/aws/dist-serverless/nodejs');
2729

@@ -153,6 +155,31 @@ function getAllFiles(dir: string): string[] {
153155
return files;
154156
}
155157

158+
/**
159+
* Clean up Angular ngcc lock files from all packages that could interfere with yarn install.
160+
* These lock files can cause ENOENT errors when yarn tries to copy files from file: dependencies.
161+
*/
162+
function cleanupNgccLockFiles(): void {
163+
const packagesDir = path.resolve(__dirname, '../..');
164+
const packageDirs = fs
165+
.readdirSync(packagesDir, { withFileTypes: true })
166+
.filter(dirent => dirent.isDirectory())
167+
.map(dirent => dirent.name)
168+
.filter(name => !name.startsWith('.'));
169+
170+
for (const packageDir of packageDirs) {
171+
const lockFilePath = path.join(packagesDir, packageDir, 'node_modules', '.ngcc_lock_file');
172+
if (fs.existsSync(lockFilePath)) {
173+
try {
174+
fs.unlinkSync(lockFilePath);
175+
console.log(`Removed ${lockFilePath}`);
176+
} catch {
177+
console.warn(`Warning: Could not remove ${lockFilePath}`);
178+
}
179+
}
180+
}
181+
}
182+
156183
function buildPackageJson(): void {
157184
console.log('Building package.json');
158185
const packagesDir = path.resolve(__dirname, '../..');

0 commit comments

Comments
 (0)