-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathoptions-mapping.ts
79 lines (72 loc) · 2.94 KB
/
options-mapping.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
import { Logger } from "./sentry/logger";
import { Options as UserOptions } from "./types";
import { determineReleaseName } from "./utils";
export type NormalizedOptions = ReturnType<typeof normalizeUserOptions>;
export const SENTRY_SAAS_URL = "https://sentry.io";
export function normalizeUserOptions(userOptions: UserOptions) {
const options = {
org: userOptions.org ?? process.env["SENTRY_ORG"],
project: userOptions.project ?? process.env["SENTRY_PROJECT"],
authToken: userOptions.authToken ?? process.env["SENTRY_AUTH_TOKEN"],
url: userOptions.url ?? process.env["SENTRY_URL"] ?? SENTRY_SAAS_URL,
headers: userOptions.headers,
debug: userOptions.debug ?? false,
silent: userOptions.silent ?? false,
errorHandler: userOptions.errorHandler,
telemetry: userOptions.telemetry ?? true,
disable: userOptions.disable ?? false,
sourcemaps: userOptions.sourcemaps,
release: {
...userOptions.release,
name: userOptions.release?.name ?? process.env["SENTRY_RELEASE"] ?? determineReleaseName(),
inject: userOptions.release?.inject ?? true,
create: userOptions.release?.create ?? true,
finalize: userOptions.release?.finalize ?? true,
vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin",
},
bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
reactComponentAnnotation: userOptions.reactComponentAnnotation,
moduleMetadata: userOptions.moduleMetadata || userOptions._experiments?.moduleMetadata,
_experiments: userOptions._experiments ?? {},
};
return options;
}
/**
* Validates a few combinations of options that are not checked by Sentry CLI.
*
* For all other options, we can rely on Sentry CLI to validate them. In fact,
* we can't validate them in the plugin because Sentry CLI might pick up options from
* its config file.
*
* @param options the internal options
* @param logger the logger
*
* @returns `true` if the options are valid, `false` otherwise
*/
export function validateOptions(options: NormalizedOptions, logger: Logger): boolean {
const setCommits = options.release?.setCommits;
if (setCommits) {
if (!setCommits.auto && !(setCommits.repo && setCommits.commit)) {
logger.error(
"The `setCommits` option was specified but is missing required properties.",
"Please set either `auto` or both, `repo` and `commit`."
);
return false;
}
if (setCommits.auto && setCommits.repo && setCommits) {
logger.warn(
"The `setCommits` options includes `auto` but also `repo` and `commit`.",
"Ignoring `repo` and `commit`.",
"Please only set either `auto` or both, `repo` and `commit`."
);
}
}
if (options.release?.deploy && !options.release?.deploy.env) {
logger.error(
"The `deploy` option was specified but is missing the required `env` property.",
"Please set the `env` property."
);
return false;
}
return true;
}