-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathoptions-mapping.ts
More file actions
129 lines (120 loc) · 4.65 KB
/
options-mapping.ts
File metadata and controls
129 lines (120 loc) · 4.65 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Logger } from "./sentry/logger";
import { Options as UserOptions, SetCommitsOptions } 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",
setCommits: userOptions.release?.setCommits as
| (SetCommitsOptions & { shouldNotThrowOnFailure?: boolean })
| false
| undefined,
},
bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
reactComponentAnnotation: userOptions.reactComponentAnnotation,
_metaOptions: {
telemetry: {
metaFramework: userOptions._metaOptions?.telemetry?.metaFramework,
},
},
applicationKey: userOptions.applicationKey,
moduleMetadata: userOptions.moduleMetadata,
_experiments: userOptions._experiments ?? {},
};
if (options.release.setCommits === undefined) {
if (
process.env["VERCEL"] &&
process.env["VERCEL_GIT_COMMIT_SHA"] &&
process.env["VERCEL_GIT_REPO_SLUG"] &&
process.env["VERCEL_GIT_REPO_OWNER"] &&
// We only want to set commits for the production env because Sentry becomes extremely noisy (eg on slack) for
// preview environments because the previous commit is always the "stem" commit of the preview/PR causing Sentry
// to notify you for other people creating PRs.
process.env["VERCEL_TARGET_ENV"] === "production"
) {
options.release.setCommits = {
shouldNotThrowOnFailure: true,
commit: process.env["VERCEL_GIT_COMMIT_SHA"],
previousCommit: process.env["VERCEL_GIT_PREVIOUS_SHA"],
repo: `${process.env["VERCEL_GIT_REPO_OWNER"]}/${process.env["VERCEL_GIT_REPO_SLUG"]}`,
ignoreEmpty: true,
ignoreMissing: true,
};
} else {
options.release.setCommits = {
shouldNotThrowOnFailure: true,
auto: true,
ignoreEmpty: true,
ignoreMissing: true,
};
}
}
if (
options.release.deploy === undefined &&
process.env["VERCEL"] &&
process.env["VERCEL_TARGET_ENV"]
) {
options.release.deploy = {
env: `vercel-${process.env["VERCEL_TARGET_ENV"]}`,
url: process.env["VERCEL_URL"] ? `https://${process.env["VERCEL_URL"]}` : undefined,
};
}
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;
}