|
| 1 | +import * as SentryAstro from '@sentry/astro'; |
| 2 | +// import * as SentryBun from '@sentry/bun'; |
| 3 | +import * as SentryNextJs from '@sentry/nextjs'; |
| 4 | +import * as SentryNode from '@sentry/node'; |
| 5 | +import * as SentryRemix from '@sentry/remix'; |
| 6 | +import * as SentryServerless from '@sentry/serverless'; |
| 7 | +import * as SentrySvelteKit from '@sentry/sveltekit'; |
| 8 | + |
| 9 | +/* List of exports that are safe to ignore / we don't require in any depending package */ |
| 10 | +const NODE_EXPORTS_IGNORE = [ |
| 11 | + 'default', |
| 12 | + // Probably generated by transpilation, no need to require it |
| 13 | + '__esModule', |
| 14 | + // this function was deprecates almost immediately after it was introduced |
| 15 | + // due to a name change (startSpan). No need to re-export it IMHO. |
| 16 | + 'startActiveSpan', |
| 17 | + // this was never meant for external use (and documented as such) |
| 18 | + 'trace', |
| 19 | + // These Node exports were only made for type definition fixes (see #10339) |
| 20 | + 'Undici', |
| 21 | + 'Http', |
| 22 | + 'DebugSession', |
| 23 | + 'AnrIntegrationOptions', |
| 24 | + 'LocalVariablesIntegrationOptions', |
| 25 | + // deprecated |
| 26 | + 'spanStatusfromHttpCode', |
| 27 | +]; |
| 28 | + |
| 29 | +type Dependent = { |
| 30 | + package: string; |
| 31 | + exports: string[]; |
| 32 | + ignoreExports?: string[]; |
| 33 | + skip?: boolean; |
| 34 | +}; |
| 35 | + |
| 36 | +const DEPENDENTS: Dependent[] = [ |
| 37 | + { |
| 38 | + package: '@sentry/astro', |
| 39 | + exports: Object.keys(SentryAstro), |
| 40 | + }, |
| 41 | + { |
| 42 | + package: '@sentry/nextjs', |
| 43 | + // Next.js doesn't require explicit exports, so we can just merge top level and `default` exports: |
| 44 | + // @ts-expect-error: `default` is not in the type definition but it's defined |
| 45 | + exports: Object.keys({ ...SentryNextJs, ...SentryNextJs.default }), |
| 46 | + ignoreExports: ['withSentryConfig'], |
| 47 | + }, |
| 48 | + { |
| 49 | + package: '@sentry/remix', |
| 50 | + exports: Object.keys(SentryRemix), |
| 51 | + // TODO: Fix exports in remix |
| 52 | + skip: true, |
| 53 | + }, |
| 54 | + { |
| 55 | + package: '@sentry/serverless', |
| 56 | + exports: Object.keys(SentryServerless), |
| 57 | + ignoreExports: [ |
| 58 | + // Deprecated, no need to add this now to serverless |
| 59 | + 'extractTraceparentData', |
| 60 | + 'getModuleFromFilename', |
| 61 | + // TODO: Should these be exported from serverless? |
| 62 | + 'cron', |
| 63 | + 'enableAnrDetection', |
| 64 | + 'runWithAsyncContext', |
| 65 | + 'hapiErrorPlugin', |
| 66 | + ], |
| 67 | + // TODO: Fix exports in serverless |
| 68 | + skip: true, |
| 69 | + }, |
| 70 | + { |
| 71 | + package: '@sentry/sveltekit', |
| 72 | + exports: Object.keys(SentrySvelteKit), |
| 73 | + // TODO: Fix exports in sveltekit |
| 74 | + skip: true, |
| 75 | + }, |
| 76 | +]; |
| 77 | + |
| 78 | +/* Sanitized list of node exports */ |
| 79 | +const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e)); |
| 80 | + |
| 81 | +console.log('🔎 Checking for consistent exports of @sentry/node exports in depending packages'); |
| 82 | + |
| 83 | +const missingExports: Record<string, string[]> = {}; |
| 84 | +const dependentsToCheck = DEPENDENTS.filter(d => !d.skip); |
| 85 | + |
| 86 | +for (const nodeExport of nodeExports) { |
| 87 | + for (const dependent of dependentsToCheck) { |
| 88 | + if (dependent.ignoreExports?.includes(nodeExport)) { |
| 89 | + continue; |
| 90 | + } |
| 91 | + if (!dependent.exports.includes(nodeExport)) { |
| 92 | + missingExports[dependent.package] = [...(missingExports[dependent.package] ?? []), nodeExport]; |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +if (Object.keys(missingExports).length > 0) { |
| 98 | + console.error('\n❌ Found missing exports from @sentry/node in the following packages:\n'); |
| 99 | + console.log(JSON.stringify(missingExports, null, 2)); |
| 100 | + process.exit(1); |
| 101 | +} |
| 102 | + |
| 103 | +console.log('✅ All good :)'); |
0 commit comments