Skip to content

Commit

Permalink
perf(astro): reduce unnecessary path resolutions (#10021)
Browse files Browse the repository at this point in the history
- No need to call `process.cwd()` on every iteration.
- No need to create paths on memory
  • Loading branch information
anonrig committed Jan 3, 2024
1 parent e23050b commit 2aae69c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
};
};

const possibleFileExtensions = ['ts', 'js', 'tsx', 'jsx', 'mjs', 'cjs', 'mts'];

function findDefaultSdkInitFile(type: 'server' | 'client'): string | undefined {
const fileExtensions = ['ts', 'js', 'tsx', 'jsx', 'mjs', 'cjs', 'mts'];
return fileExtensions
.map(ext => path.resolve(path.join(process.cwd(), `sentry.${type}.config.${ext}`)))
.find(filename => fs.existsSync(filename));
const cwd = process.cwd();
return possibleFileExtensions.find(extension => {
const filename = path.resolve(path.join(cwd, `sentry.${type}.config.${extension}`));
return fs.existsSync(filename);
});
}

function getSourcemapsAssetsGlob(config: AstroConfig): string {
Expand Down

0 comments on commit 2aae69c

Please sign in to comment.