|
1 | 1 | import { logger } from '@sentry/utils';
|
2 |
| -import * as fs from 'fs'; |
3 |
| -import * as path from 'path'; |
4 | 2 | import * as process from 'process';
|
5 | 3 |
|
6 | 4 | import type { BabelTransformer } from './vendor/metro/metroBabelTransformer';
|
7 | 5 |
|
8 |
| -/** |
9 |
| - * Saves default Babel transformer path to the project root. |
10 |
| - */ |
11 |
| -export function saveDefaultBabelTransformerPath(defaultBabelTransformerPath: string): void { |
12 |
| - try { |
13 |
| - fs.mkdirSync(path.join(process.cwd(), '.sentry'), { recursive: true }); |
14 |
| - fs.writeFileSync(getDefaultBabelTransformerPath(), defaultBabelTransformerPath); |
15 |
| - logger.debug('Saved default Babel transformer path'); |
16 |
| - } catch (e) { |
17 |
| - // eslint-disable-next-line no-console |
18 |
| - console.error('[Sentry] Failed to save default Babel transformer path:', e); |
19 |
| - } |
20 |
| -} |
| 6 | +export const SENTRY_DEFAULT_BABEL_TRANSFORMER_PATH = 'SENTRY_DEFAULT_BABEL_TRANSFORMER_PATH'; |
21 | 7 |
|
22 | 8 | /**
|
23 |
| - * Reads default Babel transformer path from the project root. |
| 9 | + * Sets default Babel transformer path to the environment variables. |
24 | 10 | */
|
25 |
| -export function readDefaultBabelTransformerPath(): string | undefined { |
26 |
| - try { |
27 |
| - return fs.readFileSync(getDefaultBabelTransformerPath()).toString(); |
28 |
| - } catch (e) { |
29 |
| - // eslint-disable-next-line no-console |
30 |
| - console.error('[Sentry] Failed to read default Babel transformer path:', e); |
31 |
| - } |
32 |
| - return undefined; |
| 11 | +export function setSentryDefaultBabelTransformerPathEnv(defaultBabelTransformerPath: string): void { |
| 12 | + process.env[SENTRY_DEFAULT_BABEL_TRANSFORMER_PATH] = defaultBabelTransformerPath; |
| 13 | + logger.debug(`Saved default Babel transformer path ${defaultBabelTransformerPath}`); |
33 | 14 | }
|
34 | 15 |
|
35 | 16 | /**
|
36 |
| - * Cleans default Babel transformer path from the project root. |
| 17 | + * Reads default Babel transformer path from the environment variables. |
37 | 18 | */
|
38 |
| -export function cleanDefaultBabelTransformerPath(): void { |
39 |
| - try { |
40 |
| - fs.unlinkSync(getDefaultBabelTransformerPath()); |
41 |
| - logger.debug('Cleaned default Babel transformer path'); |
42 |
| - } catch (e) { |
43 |
| - // We don't want to fail the build if we can't clean the file |
44 |
| - // eslint-disable-next-line no-console |
45 |
| - console.error('[Sentry] Failed to clean default Babel transformer path:', e); |
46 |
| - } |
47 |
| -} |
48 |
| - |
49 |
| -function getDefaultBabelTransformerPath(): string { |
50 |
| - return path.join(process.cwd(), '.sentry/.defaultBabelTransformerPath'); |
| 19 | +export function getSentryDefaultBabelTransformerPathEnv(): string | undefined { |
| 20 | + return process.env[SENTRY_DEFAULT_BABEL_TRANSFORMER_PATH]; |
51 | 21 | }
|
52 | 22 |
|
53 | 23 | /**
|
54 | 24 | * Loads default Babel transformer from `@react-native/metro-config` -> `@react-native/metro-babel-transformer`.
|
55 | 25 | */
|
56 | 26 | export function loadDefaultBabelTransformer(): BabelTransformer {
|
57 |
| - const defaultBabelTransformerPath = readDefaultBabelTransformerPath(); |
| 27 | + const defaultBabelTransformerPath = getSentryDefaultBabelTransformerPathEnv(); |
58 | 28 | if (!defaultBabelTransformerPath) {
|
59 |
| - throw new Error('Default Babel Transformer Path not found in `.sentry` directory.'); |
| 29 | + throw new Error( |
| 30 | + `Default Babel transformer path environment variable ${SENTRY_DEFAULT_BABEL_TRANSFORMER_PATH} is not set.`, |
| 31 | + ); |
60 | 32 | }
|
61 | 33 |
|
62 | 34 | logger.debug(`Loading default Babel transformer from ${defaultBabelTransformerPath}`);
|
|
0 commit comments