Skip to content

Commit 5dd4bfa

Browse files
committed
fix(cli): apply build path modifiers in one place, keep every native dry run local
--local-bundle, --detach and --dry-run are applied after the build path is resolved, whether a flag or the server chose it. A native dry run now always bundles locally on the Depot path (it previously deployed for real with --native-build --dry-run), and --local-bundle --dry-run stays on the local bundle path, which supports dry runs.
1 parent a157b32 commit 5dd4bfa

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it } from "vitest";
2+
import { applyBuildPathOptions } from "./buildPath.js";
3+
4+
const none = { localBundle: false, detach: false, dryRun: false };
5+
6+
describe("applyBuildPathOptions", () => {
7+
it("passes the resolved path through without modifiers", () => {
8+
expect(applyBuildPathOptions("depot", none)).toBe("depot");
9+
expect(applyBuildPathOptions("native", none)).toBe("native");
10+
expect(applyBuildPathOptions("native_local_bundle", none)).toBe("native_local_bundle");
11+
});
12+
13+
it("upgrades a native path to the local bundle variant with --local-bundle", () => {
14+
expect(applyBuildPathOptions("native", { ...none, localBundle: true })).toBe(
15+
"native_local_bundle"
16+
);
17+
});
18+
19+
it("rejects --local-bundle and --detach on Depot", () => {
20+
expect(() => applyBuildPathOptions("depot", { ...none, localBundle: true })).toThrow(
21+
/--local-bundle is only available with the native build server/
22+
);
23+
expect(() => applyBuildPathOptions("depot", { ...none, detach: true })).toThrow(
24+
/--detach is only available with the native build server/
25+
);
26+
});
27+
28+
it("keeps --detach on the native paths", () => {
29+
expect(applyBuildPathOptions("native", { ...none, detach: true })).toBe("native");
30+
expect(applyBuildPathOptions("native_local_bundle", { ...none, detach: true })).toBe(
31+
"native_local_bundle"
32+
);
33+
});
34+
35+
it("moves a native dry run onto the Depot path, however native was chosen", () => {
36+
expect(applyBuildPathOptions("native", { ...none, dryRun: true })).toBe("depot");
37+
});
38+
39+
it("lets a local-bundle dry run stay on the local bundle path", () => {
40+
expect(applyBuildPathOptions("native", { ...none, localBundle: true, dryRun: true })).toBe(
41+
"native_local_bundle"
42+
);
43+
expect(applyBuildPathOptions("native_local_bundle", { ...none, dryRun: true })).toBe(
44+
"native_local_bundle"
45+
);
46+
});
47+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { DeployBuildPath } from "@trigger.dev/core/v3/schemas";
2+
3+
export type BuildPathOptions = {
4+
localBundle: boolean;
5+
detach: boolean;
6+
dryRun: boolean;
7+
};
8+
9+
/**
10+
* Applies the native-only modifiers to the resolved build path. --local-bundle and --detach
11+
* need the native build server: with it they apply, on Depot they throw. A dry run never
12+
* reaches the plain native path (it has no dry-run mode and would deploy for real); it is
13+
* bundled locally on the Depot path instead. The local-bundle path handles dry runs itself.
14+
*/
15+
export function applyBuildPathOptions(
16+
resolved: DeployBuildPath,
17+
options: BuildPathOptions
18+
): DeployBuildPath {
19+
const nativeOnly = options.localBundle
20+
? "--local-bundle"
21+
: options.detach
22+
? "--detach"
23+
: undefined;
24+
25+
if (nativeOnly && resolved === "depot") {
26+
throw new Error(
27+
`${nativeOnly} is only available with the native build server. Pass --native-build, or configure the native build path for this environment.`
28+
);
29+
}
30+
31+
if (options.localBundle) {
32+
return "native_local_bundle";
33+
}
34+
35+
if (options.dryRun && resolved === "native") {
36+
return "depot";
37+
}
38+
39+
return resolved;
40+
}

0 commit comments

Comments
 (0)