Skip to content

Commit 4a4049c

Browse files
feat(vite-plugin): Add Containers-related info logs (#10071)
* feat(vite-plugin): Add Containers-related info logs * feedback fixes
1 parent c070c77 commit 4a4049c

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.changeset/afraid-experts-take.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
feat(vite-plugin): Add Containers-related info logs
6+
7+
Add logs, when a Worker has Containers configured, providing information about container build status, and how to rebuild containers during local development.

packages/vite-plugin-cloudflare/src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { generateStaticRoutingRuleMatcher } from "@cloudflare/workers-shared/ass
1010
import replace from "@rollup/plugin-replace";
1111
import MagicString from "magic-string";
1212
import { Miniflare } from "miniflare";
13+
import colors from "picocolors";
1314
import * as vite from "vite";
1415
import {
1516
createModuleReference,
@@ -449,13 +450,27 @@ if (import.meta.hot) {
449450
}
450451

451452
if (hasDevContainers) {
453+
viteDevServer.config.logger.info(
454+
colors.dim(
455+
colors.yellow(
456+
"∷ Building container images for local development...\n"
457+
)
458+
)
459+
);
452460
containerImageTagsSeen = await prepareContainerImages({
453461
containersConfig: entryWorkerConfig.containers,
454462
containerBuildId,
455463
isContainersEnabled: entryWorkerConfig.dev.enable_containers,
456464
dockerPath,
457465
configPath: entryWorkerConfig.configPath,
458466
});
467+
viteDevServer.config.logger.info(
468+
colors.dim(
469+
colors.yellow(
470+
"\n⚡️ Containers successfully built. To rebuild your containers during development, restart the Vite dev server (r + enter)."
471+
)
472+
)
473+
);
459474

460475
// poll Docker every two seconds and update the list of ids of all
461476
// running containers
@@ -575,13 +590,23 @@ if (import.meta.hot) {
575590
if (hasDevContainers) {
576591
const dockerPath = getDockerPath();
577592

593+
vitePreviewServer.config.logger.info(
594+
colors.dim(
595+
colors.yellow(
596+
"∷ Building container images for local preview...\n"
597+
)
598+
)
599+
);
578600
containerImageTagsSeen = await prepareContainerImages({
579601
containersConfig: entryWorkerConfig.containers,
580602
containerBuildId,
581603
isContainersEnabled: entryWorkerConfig.dev.enable_containers,
582604
dockerPath,
583605
configPath: entryWorkerConfig.configPath,
584606
});
607+
vitePreviewServer.config.logger.info(
608+
colors.dim(colors.yellow("\n⚡️ Containers successfully built.\n"))
609+
);
585610

586611
const dockerPollIntervalId = setInterval(async () => {
587612
if (containerImageTagsSeen?.size) {

packages/wrangler/src/dev/hotkeys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomUUID } from "crypto";
1+
import { generateContainerBuildId } from "@cloudflare/containers-shared";
22
import { LocalRuntimeController } from "../api/startDevWorker/LocalRuntimeController";
33
import registerHotKeys from "../cli-hotkeys";
44
import { logger } from "../logger";
@@ -71,7 +71,7 @@ export default function registerDevHotKeys(
7171
})
7272
);
7373

74-
const newContainerBuildId = randomUUID().slice(0, 8);
74+
const newContainerBuildId = generateContainerBuildId();
7575

7676
// updating the build ID will trigger a rebuild of the containers
7777
await devEnv.config.patch({

0 commit comments

Comments
 (0)