Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/v1-container-command-guidance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/vite-plugin": patch
---

Pass Container command guidance directly to shared helpers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changeset headline describes implementation details

The changeset headline describes passing arguments to helpers rather than the corrected Container guidance users receive. Repository review rules require user-facing changeset language.

Suggested change
Pass Container command guidance directly to shared helpers
Fix Container setup guidance in Vite development and preview

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


Keep local development and preview guidance aligned with the CLI and each Worker's configuration file, including legacy Wrangler configurations and the experimental cf delegate. Use the matching Container and deployment helper releases without relying on global command presentation state.
2 changes: 1 addition & 1 deletion packages/remote-bindings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@cloudflare/cli-shared-helpers": "0.2.6",
"@cloudflare/deploy-helpers": "0.21.0",
"@cloudflare/deploy-helpers": "0.22.0",
"@cloudflare/workers-auth": "0.14.0",
"@cloudflare/workers-utils": "0.47.2",
"chalk": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"devDependencies": {
"@cloudflare/build-output-utils": "0.9.3",
"@cloudflare/config": "0.27.0",
"@cloudflare/containers-shared": "0.22.1",
"@cloudflare/containers-shared": "0.23.0",
"@cloudflare/mock-npm-registry": "workspace:*",
"@cloudflare/remote-bindings": "workspace:*",
"@cloudflare/runtime-types": "0.1.13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ export default { plugins: [cloudflare({ inspectorPort: false, persistState: fals
expect(prepareContainerImagesForDev).not.toHaveBeenCalled();
} else {
expect(prepareContainerImagesForDev).toHaveBeenCalledTimes(1);
expect(prepareContainerImagesForDev).toHaveBeenCalledWith(
expect.objectContaining({
configFileName:
mode === "dev" ? "wrangler.jsonc" : "wrangler.json",
registryConfigureCommand:
"wrangler containers registries configure",
})
);
const options = vi.mocked(prepareContainerImagesForDev).mock
.calls[0]?.[0].containerOptions;
expect(options).toHaveLength(scenario === "configured" ? 1 : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ test("prepares registry images with their owning Worker configuration", async ({
dockerPath: "docker",
containerOptionsByWorker,
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
cliDisplayName: "Wrangler",
});

expect(preparations).toEqual([
Expand Down Expand Up @@ -201,6 +202,7 @@ test("prepares the sidecar for a configured Worker without images or registry cr
dockerPath: "test-docker",
containerOptionsByWorker: new Map([[{}, []]]),
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
cliDisplayName: "Wrangler",
});
expect(prepareContainerImagesForDev).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({
Expand Down Expand Up @@ -334,3 +336,40 @@ describe("Container image planning", () => {
expect(new Set(runtimeImageTags)).toEqual(imageTags);
});
});

test.for([
{
cliDisplayName: "Wrangler",
configPath: "project/wrangler.jsonc",
configFileName: "wrangler.jsonc",
registryConfigureCommand: "wrangler containers registries configure",
},
{
cliDisplayName: "Wrangler",
configPath: undefined,
configFileName: "cloudflare.config.ts",
registryConfigureCommand: "wrangler containers registries configure",
},
{
cliDisplayName: "cf",
configPath: undefined,
configFileName: "cloudflare.config.ts",
registryConfigureCommand: "cf containers registries create",
},
])(
"passes $configFileName and $cliDisplayName guidance to the Container helper",
async (
{ cliDisplayName, configPath, configFileName, registryConfigureCommand },
{ expect }
) => {
await prepareContainerImagesForVite({
dockerPath: "test-docker",
containerOptionsByWorker: new Map([[{ configPath }, []]]),
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
cliDisplayName,
});
expect(prepareContainerImagesForDev).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({ configFileName, registryConfigureCommand })
);
}
);
17 changes: 15 additions & 2 deletions packages/vite-plugin-cloudflare/src/containers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "node:path";
import {
configureOpenAPIForContainerPull,
isCloudflareRegistryImage,
Expand All @@ -15,7 +16,10 @@ import type {
} from "@cloudflare/containers-shared";
import type { ComplianceConfig } from "@cloudflare/workers-utils";

type ContainerWorkerConfig = ComplianceConfig & { account_id?: string };
type ContainerWorkerConfig = ComplianceConfig & {
account_id?: string;
configPath?: string;
};

/**
* Configures the Containers API client used to retrieve image pull credentials.
Expand Down Expand Up @@ -73,13 +77,14 @@ export function normalizeContainerImageUris(
* registry account and compliance settings, including Workers whose images
* are selected at start time.
*
* @param args - Planned images, Docker executable, and Vite logger.
* @param args - Planned images, Docker executable, Vite logger, and CLI identity.
* @returns No value.
*/
export async function prepareContainerImagesForVite(args: {
dockerPath: string;
containerOptionsByWorker: ContainerOptionsByWorker;
logger: ViteLogger;
cliDisplayName: string;
}): Promise<void> {
for (const [workerConfig, plannedOptions] of args.containerOptionsByWorker) {
let containerOptions = plannedOptions;
Expand Down Expand Up @@ -119,6 +124,14 @@ export async function prepareContainerImagesForVite(args: {
onContainerImagePreparationEnd: () => {},
logger: args.logger,
complianceConfig: workerConfig,
configFileName: workerConfig.configPath
? path.basename(workerConfig.configPath)
: "cloudflare.config.ts",
// TODO: Let cf provide its own command when the delegate supports that contract.
Comment on lines +128 to +130

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Container guidance names a nonexistent config

For Containers defined through inline config, configFileName becomes cloudflare.config.ts even when that file does not exist. Users receive guidance pointing away from their actual Worker configuration.

Learn more

The plugin accepts inline Worker configuration without a Wrangler file. In that case, resolveWorkerConfig starts with defaults and applies the inline customizer, leaving the Worker without a config path. cloudflare.config.ts is loaded only when experimental.newConfig is enabled. Passing its name for every fileless Worker makes the Container helper's filename guidance point to a file the user never created.

Example: A project configures cloudflare({ config: { containers: [...] } }) in vite.config.ts without either Worker config file. Container preparation passes cloudflare.config.ts as its config filename, even though the Container settings live in vite.config.ts.

Recommended fix: Distinguish experimental.newConfig from an inline, fileless Worker when constructing the helper's guidance. Pass the actual relevant configuration filename or use guidance that does not claim a cloudflare.config.ts exists.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

registryConfigureCommand:
args.cliDisplayName === "cf"
? "cf containers registries create"
: "wrangler containers registries configure",
});
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/vite-plugin-cloudflare/src/plugins/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const devPlugin = createPlugin("dev", (ctx) => {
dockerPath: getDockerPath(),
containerOptionsByWorker,
logger: viteDevServer.config.logger,
cliDisplayName: ctx.resolvedPluginConfig.cliDisplayName,
});

containerCleanup.track(
Expand Down
1 change: 1 addition & 0 deletions packages/vite-plugin-cloudflare/src/plugins/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const previewPlugin = createPlugin("preview", (ctx) => {
dockerPath,
containerOptionsByWorker,
logger: vitePreviewServer.config.logger,
cliDisplayName: ctx.resolvedPluginConfig.cliDisplayName,
});

containerCleanup.track(
Expand Down
41 changes: 12 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading