Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions packages/bundler-plugin-core/src/options-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ export type NormalizedOptions = {
| false
| undefined;
dist?: string;
deploy?: {
env: string;
started?: number | string;
finished?: number | string;
time?: number;
name?: string;
url?: string;
};
deploy?:
| {
env: string;
started?: number | string;
finished?: number | string;
time?: number;
name?: string;
url?: string;
}
| false;
uploadLegacySourcemaps?: string | IncludeEntry | Array<string | IncludeEntry>;
};
bundleSizeOptimizations:
Expand Down Expand Up @@ -195,7 +197,11 @@ export function validateOptions(options: NormalizedOptions, logger: Logger): boo
}
}

if (options.release?.deploy && !options.release?.deploy.env) {
if (
options.release?.deploy &&
typeof options.release.deploy === "object" &&
!options.release.deploy.env
) {
logger.error(
"The `deploy` option was specified but is missing the required `env` property.",
"Please set the `env` property."
Expand Down
4 changes: 3 additions & 1 deletion packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ export interface Options {

/**
* Configuration for adding deployment information to the release in Sentry.
*
* Set to `false` to disable automatic deployment detection and creation.
*/
deploy?: DeployOptions;
deploy?: DeployOptions | false;

/**
* Legacy method of uploading source maps. (not recommended unless necessary)
Expand Down
89 changes: 88 additions & 1 deletion packages/bundler-plugin-core/test/option-mappings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,86 @@ describe("normalizeUserOptions()", () => {
expect(normalizeUserOptions(options).telemetry).toBe(true);
}
);

describe("Vercel deploy detection", () => {
const originalEnv = process.env;

beforeEach(() => {
process.env = { ...originalEnv };
});

afterEach(() => {
process.env = originalEnv;
});

test("should automatically create deploy config when Vercel env vars are present", () => {
process.env["VERCEL"] = "1";
process.env["VERCEL_TARGET_ENV"] = "production";
process.env["VERCEL_URL"] = "my-app.vercel.app";

const userOptions: Options = {
org: "my-org",
project: "my-project",
authToken: "my-auth-token",
release: { name: "my-release" },
};

const normalizedOptions = normalizeUserOptions(userOptions);

expect(normalizedOptions.release.deploy).toEqual({
env: "vercel-production",
url: "https://my-app.vercel.app",
});
});

test("should not create deploy config when deploy is explicitly set to false", () => {
process.env["VERCEL"] = "1";
process.env["VERCEL_TARGET_ENV"] = "production";
process.env["VERCEL_URL"] = "my-app.vercel.app";

const userOptions: Options = {
org: "my-org",
project: "my-project",
authToken: "my-auth-token",
release: { name: "my-release", deploy: false },
};

const normalizedOptions = normalizeUserOptions(userOptions);

expect(normalizedOptions.release.deploy).toBe(false);
});

test("should not override manually provided deploy config", () => {
process.env["VERCEL"] = "1";
process.env["VERCEL_TARGET_ENV"] = "production";
process.env["VERCEL_URL"] = "my-app.vercel.app";

const manualDeployConfig = { env: "custom-env", name: "custom-deploy" };
const userOptions: Options = {
org: "my-org",
project: "my-project",
authToken: "my-auth-token",
release: { name: "my-release", deploy: manualDeployConfig },
};

const normalizedOptions = normalizeUserOptions(userOptions);

expect(normalizedOptions.release.deploy).toEqual(manualDeployConfig);
});

test("should not create deploy config when Vercel env vars are missing", () => {
const userOptions: Options = {
org: "my-org",
project: "my-project",
authToken: "my-auth-token",
release: { name: "my-release" },
};

const normalizedOptions = normalizeUserOptions(userOptions);

expect(normalizedOptions.release.deploy).toBeUndefined();
});
});
});

describe("validateOptions", () => {
Expand Down Expand Up @@ -164,7 +244,14 @@ describe("validateOptions", () => {
});

it("should return `true` if `deploy`is set and `env` is provided", () => {
const options = { deploy: { env: "my-env" } } as Partial<NormalizedOptions>;
const options = { release: { deploy: { env: "my-env" } } } as Partial<NormalizedOptions>;

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

it("should return `true` if `deploy` is set to `false`", () => {
const options = { release: { deploy: false } } as Partial<NormalizedOptions>;

expect(validateOptions(options as unknown as NormalizedOptions, mockedLogger)).toBe(true);
expect(mockedLogger.error).not.toHaveBeenCalled();
Expand Down
3 changes: 2 additions & 1 deletion packages/dev-utils/src/generate-documentation-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ Use the \`debug\` option to print information about source map resolution.
},
{
name: "deploy",
type: "DeployOptions | false",
fullDescription:
"Configuration for adding deployment information to the release in Sentry.",
"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).",
children: [
{
name: "env",
Expand Down
Loading