Skip to content

Commit 9767dd1

Browse files
committed
chore(aws-serverless): Fix local cache issues
1 parent 9de002b commit 9767dd1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/aws-serverless/scripts/buildLambdaLayer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { nodeFileTrace } from '@vercel/nft';
33
import * as childProcess from 'child_process';
44
import * as fs from 'fs';
5+
import * as os from 'os';
56
import * as path from 'path';
67
import { version } from '../package.json';
78

@@ -23,11 +24,19 @@ async function buildLambdaLayer(): Promise<void> {
2324
console.log('Building Lambda layer.');
2425
buildPackageJson();
2526
console.log('Installing local @sentry/aws-serverless into build/aws/dist-serverless/nodejs.');
26-
run('yarn install --prod --cwd ./build/aws/dist-serverless/nodejs');
27+
// Use a temporary cache folder to avoid stale cache references to local file: packages.
28+
// Yarn's global cache can contain outdated references to build artifacts from other
29+
// @sentry/* packages (e.g., build/node_modules paths that no longer exist), causing
30+
// ENOENT errors during file copying.
31+
// The cache folder must be outside the monorepo to avoid recursive nesting when Yarn
32+
// follows file: links and copies package directories.
33+
const cacheFolder = path.join(os.tmpdir(), `sentry-lambda-build-cache-${Date.now()}`);
34+
run(`yarn install --prod --cwd ./build/aws/dist-serverless/nodejs --cache-folder "${cacheFolder}"`);
2735

2836
await pruneNodeModules();
2937
fs.rmSync('./build/aws/dist-serverless/nodejs/package.json', { force: true });
3038
fs.rmSync('./build/aws/dist-serverless/nodejs/yarn.lock', { force: true });
39+
fs.rmSync(cacheFolder, { recursive: true, force: true });
3140

3241
// The layer also includes `awslambda-auto.js`, a helper file which calls `Sentry.init()` and wraps the lambda
3342
// handler. It gets run when Node is launched inside the lambda, using the environment variable

0 commit comments

Comments
 (0)