-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathconsistentExports.ts
114 lines (104 loc) · 3.26 KB
/
consistentExports.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as SentryAstro from '@sentry/astro';
import * as SentryBun from '@sentry/bun';
import * as SentryNextJs from '@sentry/nextjs';
import * as SentryNode from '@sentry/node';
import * as SentryRemix from '@sentry/remix';
import * as SentrySvelteKit from '@sentry/sveltekit';
// Serverless SDKs are CJS only
const SentryAWS = require('@sentry/aws-serverless');
const SentryGoogleCloud = require('@sentry/google-cloud-serverless');
/* List of exports that are safe to ignore / we don't require in any depending package */
const NODE_EXPORTS_IGNORE = [
'default',
// Probably generated by transpilation, no need to require it
'__esModule',
// Only required from the Node package
'setNodeAsyncContextStrategy',
'getDefaultIntegrationsWithoutPerformance',
'initWithoutDefaultIntegrations',
'SentryContextManager',
'validateOpenTelemetrySetup',
'preloadOpenTelemetry',
];
const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e));
type Dependent = {
package: string;
exports: string[];
ignoreExports?: string[];
skip?: boolean;
compareWith: string[];
};
const DEPENDENTS: Dependent[] = [
{
package: '@sentry/astro',
compareWith: nodeExports,
exports: Object.keys(SentryAstro),
ignoreExports: [
// Not needed for Astro
'setupFastifyErrorHandler',
],
},
{
package: '@sentry/bun',
compareWith: nodeExports,
exports: Object.keys(SentryBun),
ignoreExports: [
// not supported in bun:
'NodeClient',
],
},
{
package: '@sentry/nextjs',
compareWith: nodeExports,
// Next.js doesn't require explicit exports, so we can just merge top level and `default` exports:
// @ts-expect-error: `default` is not in the type definition but it's defined
exports: Object.keys({ ...SentryNextJs, ...SentryNextJs.default }),
},
{
package: '@sentry/remix',
compareWith: nodeExports,
exports: Object.keys(SentryRemix),
},
{
package: '@sentry/aws-serverless',
compareWith: nodeExports,
exports: Object.keys(SentryAWS),
ignoreExports: [
// Not needed for Serverless
'setupFastifyErrorHandler',
],
},
{
package: '@sentry/google-cloud-serverless',
compareWith: nodeExports,
exports: Object.keys(SentryGoogleCloud),
ignoreExports: [
// Not needed for Serverless
'setupFastifyErrorHandler',
],
},
{
package: '@sentry/sveltekit',
compareWith: nodeExports,
exports: Object.keys(SentrySvelteKit),
},
];
console.log('🔎 Checking for consistent exports of @sentry/node exports in depending packages');
const missingExports: Record<string, string[]> = {};
const dependentsToCheck = DEPENDENTS.filter(d => !d.skip);
for (const dependent of dependentsToCheck) {
for (const nodeExport of dependent.compareWith) {
if (dependent.ignoreExports?.includes(nodeExport)) {
continue;
}
if (!dependent.exports.includes(nodeExport)) {
missingExports[dependent.package] = [...(missingExports[dependent.package] ?? []), nodeExport];
}
}
}
if (Object.keys(missingExports).length > 0) {
console.log('\n❌ Found missing exports from @sentry/node in the following packages:\n');
console.log(JSON.stringify(missingExports, null, 2));
process.exit(1);
}
console.log('✅ All good :)');