Skip to content

Commit ed990c9

Browse files
authored
feat(core): Extend deploy option to allow opting out of automatic deploy creation (#801)
1 parent 07c25ce commit ed990c9

File tree

4 files changed

+108
-12
lines changed

4 files changed

+108
-12
lines changed

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ export type NormalizedOptions = {
4444
| false
4545
| undefined;
4646
dist?: string;
47-
deploy?: {
48-
env: string;
49-
started?: number | string;
50-
finished?: number | string;
51-
time?: number;
52-
name?: string;
53-
url?: string;
54-
};
47+
deploy?:
48+
| {
49+
env: string;
50+
started?: number | string;
51+
finished?: number | string;
52+
time?: number;
53+
name?: string;
54+
url?: string;
55+
}
56+
| false;
5557
uploadLegacySourcemaps?: string | IncludeEntry | Array<string | IncludeEntry>;
5658
};
5759
bundleSizeOptimizations:
@@ -195,7 +197,11 @@ export function validateOptions(options: NormalizedOptions, logger: Logger): boo
195197
}
196198
}
197199

198-
if (options.release?.deploy && !options.release?.deploy.env) {
200+
if (
201+
options.release?.deploy &&
202+
typeof options.release.deploy === "object" &&
203+
!options.release.deploy.env
204+
) {
199205
logger.error(
200206
"The `deploy` option was specified but is missing the required `env` property.",
201207
"Please set the `env` property."

packages/bundler-plugin-core/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ export interface Options {
239239

240240
/**
241241
* Configuration for adding deployment information to the release in Sentry.
242+
*
243+
* Set to `false` to disable automatic deployment detection and creation.
242244
*/
243-
deploy?: DeployOptions;
245+
deploy?: DeployOptions | false;
244246

245247
/**
246248
* Legacy method of uploading source maps. (not recommended unless necessary)

packages/bundler-plugin-core/test/option-mappings.test.ts

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,86 @@ describe("normalizeUserOptions()", () => {
110110
expect(normalizeUserOptions(options).telemetry).toBe(true);
111111
}
112112
);
113+
114+
describe("Vercel deploy detection", () => {
115+
const originalEnv = process.env;
116+
117+
beforeEach(() => {
118+
process.env = { ...originalEnv };
119+
});
120+
121+
afterEach(() => {
122+
process.env = originalEnv;
123+
});
124+
125+
test("should automatically create deploy config when Vercel env vars are present", () => {
126+
process.env["VERCEL"] = "1";
127+
process.env["VERCEL_TARGET_ENV"] = "production";
128+
process.env["VERCEL_URL"] = "my-app.vercel.app";
129+
130+
const userOptions: Options = {
131+
org: "my-org",
132+
project: "my-project",
133+
authToken: "my-auth-token",
134+
release: { name: "my-release" },
135+
};
136+
137+
const normalizedOptions = normalizeUserOptions(userOptions);
138+
139+
expect(normalizedOptions.release.deploy).toEqual({
140+
env: "vercel-production",
141+
url: "https://my-app.vercel.app",
142+
});
143+
});
144+
145+
test("should not create deploy config when deploy is explicitly set to false", () => {
146+
process.env["VERCEL"] = "1";
147+
process.env["VERCEL_TARGET_ENV"] = "production";
148+
process.env["VERCEL_URL"] = "my-app.vercel.app";
149+
150+
const userOptions: Options = {
151+
org: "my-org",
152+
project: "my-project",
153+
authToken: "my-auth-token",
154+
release: { name: "my-release", deploy: false },
155+
};
156+
157+
const normalizedOptions = normalizeUserOptions(userOptions);
158+
159+
expect(normalizedOptions.release.deploy).toBe(false);
160+
});
161+
162+
test("should not override manually provided deploy config", () => {
163+
process.env["VERCEL"] = "1";
164+
process.env["VERCEL_TARGET_ENV"] = "production";
165+
process.env["VERCEL_URL"] = "my-app.vercel.app";
166+
167+
const manualDeployConfig = { env: "custom-env", name: "custom-deploy" };
168+
const userOptions: Options = {
169+
org: "my-org",
170+
project: "my-project",
171+
authToken: "my-auth-token",
172+
release: { name: "my-release", deploy: manualDeployConfig },
173+
};
174+
175+
const normalizedOptions = normalizeUserOptions(userOptions);
176+
177+
expect(normalizedOptions.release.deploy).toEqual(manualDeployConfig);
178+
});
179+
180+
test("should not create deploy config when Vercel env vars are missing", () => {
181+
const userOptions: Options = {
182+
org: "my-org",
183+
project: "my-project",
184+
authToken: "my-auth-token",
185+
release: { name: "my-release" },
186+
};
187+
188+
const normalizedOptions = normalizeUserOptions(userOptions);
189+
190+
expect(normalizedOptions.release.deploy).toBeUndefined();
191+
});
192+
});
113193
});
114194

115195
describe("validateOptions", () => {
@@ -164,7 +244,14 @@ describe("validateOptions", () => {
164244
});
165245

166246
it("should return `true` if `deploy`is set and `env` is provided", () => {
167-
const options = { deploy: { env: "my-env" } } as Partial<NormalizedOptions>;
247+
const options = { release: { deploy: { env: "my-env" } } } as Partial<NormalizedOptions>;
248+
249+
expect(validateOptions(options as unknown as NormalizedOptions, mockedLogger)).toBe(true);
250+
expect(mockedLogger.error).not.toHaveBeenCalled();
251+
});
252+
253+
it("should return `true` if `deploy` is set to `false`", () => {
254+
const options = { release: { deploy: false } } as Partial<NormalizedOptions>;
168255

169256
expect(validateOptions(options as unknown as NormalizedOptions, mockedLogger)).toBe(true);
170257
expect(mockedLogger.error).not.toHaveBeenCalled();

packages/dev-utils/src/generate-documentation-table.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ Use the \`debug\` option to print information about source map resolution.
221221
},
222222
{
223223
name: "deploy",
224+
type: "DeployOptions | false",
224225
fullDescription:
225-
"Configuration for adding deployment information to the release in Sentry.",
226+
"Configuration for adding deployment information to the release in Sentry.\n\nSet to `false` to disable automatic deployment detection and creation (e.g., when deploying on Vercel).",
226227
children: [
227228
{
228229
name: "env",

0 commit comments

Comments
 (0)