-
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathsentryReleaseInjector.ts
More file actions
47 lines (38 loc) · 1.35 KB
/
sentryReleaseInjector.ts
File metadata and controls
47 lines (38 loc) · 1.35 KB
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
import type { MixedOutput, Module, ReadOnlyGraph } from 'metro';
import type { VirtualJSOutput } from './utils';
import { createVirtualJSModule, getExpoConfig, prependModule } from './utils';
const RELEASE_CONSTANTS_MODULE_PATH = '__sentryReleaseConstants__';
/**
* Adds Sentry Release constants to the bundle.
*/
export const unstableReleaseConstantsPlugin =
(projectRoot: string) =>
({ graph, premodules }: { graph: ReadOnlyGraph<MixedOutput>; premodules: Module[]; debugId?: string }): Module[] => {
const notWeb = graph.transformOptions.platform !== 'web';
if (notWeb) {
return premodules;
}
const { name, version } = getExpoConfig(projectRoot);
if (!name || !version) {
return premodules;
}
return prependModule(
premodules,
createSentryReleaseModule({
name,
version,
}),
);
};
function createSentryReleaseModule({
name,
version,
}: {
name: string;
version: string;
}): Module<VirtualJSOutput> & { setSource: (code: string) => void } {
return createVirtualJSModule(RELEASE_CONSTANTS_MODULE_PATH, createReleaseConstantsSnippet({ name, version }));
}
function createReleaseConstantsSnippet({ name, version }: { name: string; version: string }): string {
return `var SENTRY_RELEASE;SENTRY_RELEASE={name: ${JSON.stringify(name)}, version: ${JSON.stringify(version)}};`;
}