MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / findDefaultSdkInitFile

Function findDefaultSdkInitFile

packages/nuxt/src/vite/utils.ts:30–71  ·  view source on GitHub ↗
(
  type: 'server' | 'client',
  nuxt?: Nuxt,
  options?: SentryNuxtModuleOptions,
)

Source from the content-addressed store, hash-verified

28 * The sentry.server.config file is prioritized over the instrument.server file.
29 */
30export async function findDefaultSdkInitFile(
31 type: 'server' | 'client',
32 nuxt?: Nuxt,
33 options?: SentryNuxtModuleOptions,
34): Promise<string | undefined> {
35 const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];
36 const relativePaths: string[] = [];
37
38 if (type === 'server') {
39 for (const ext of possibleFileExtensions) {
40 relativePaths.push(`sentry.${type}.config.${ext}`);
41 relativePaths.push(path.join('public', `instrument.${type}.${ext}`));
42 }
43 } else {
44 for (const ext of possibleFileExtensions) {
45 relativePaths.push(`sentry.${type}.config.${ext}`);
46 }
47 }
48
49 // Get layers from highest priority to lowest
50 const layers = [...(nuxt?.options._layers ?? [])].reverse();
51
52 for (const layer of layers) {
53 for (const relativePath of relativePaths) {
54 const fullPath = path.resolve(layer.cwd, relativePath);
55 if (fs.existsSync(fullPath)) {
56 return fullPath;
57 }
58 }
59 }
60
61 // As a fallback, also check CWD (left for pure compatibility)
62 const rootDir = options?.configDir ? await resolvePath(options.configDir, { type: 'dir' }) : process.cwd();
63 for (const relativePath of relativePaths) {
64 const fullPath = path.resolve(rootDir, relativePath);
65 if (fs.existsSync(fullPath)) {
66 return fullPath;
67 }
68 }
69
70 return undefined;
71}
72
73/**
74 * Extracts the filename from a node command with a path.

Callers 2

utils.test.tsFile · 0.90
setupFunction · 0.90

Calls 2

pushMethod · 0.80
resolveMethod · 0.65

Tested by

no test coverage detected