Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement dev registry as background daemon #4241

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion fixtures/external-service-bindings-app/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("Pages Functions", () => {
expect(json).toMatchInlineSnapshot(`
{
"moduleWorkerCResponse": "Hello from module worker c (staging)",
"moduleWorkerDResponse": "You should start up wrangler dev --local on the STAGING_MODULE_D_SERVICE worker",
"moduleWorkerDResponse": "[wrangler] Couldn't find \`wrangler dev\` session for service \\"STAGING_MODULE_D_SERVICE\\" to proxy to",
}
`);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function buildMain(flags: BuildFlags = {}) {

const options: BuildOptions = {
keepNames: true,
entryPoints: ["./src/cli.ts"],
entryPoints: ["./src/cli.ts", "./src/dev-registry/daemon.ts"],
bundle: true,
outdir,
platform: "node",
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/api-devregistry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetch } from "undici";
import { unstable_dev } from "../api";
import { msw } from "./helpers/msw";

jest.unmock("child_process");
jest.unmock("undici");
Expand All @@ -15,6 +16,7 @@ describe("multi-worker testing", () => {
let parentWorker: any;

beforeAll(async () => {
msw.close();
childWorker = await unstable_dev(
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
{
Expand Down
43 changes: 19 additions & 24 deletions packages/wrangler/src/__tests__/unstableDev.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
import { fetch } from "undici";
import {
stopWorkerRegistry,
registerWorker,
startWorkerRegistry,
} from "../dev-registry";
import { RegistryHandle } from "../dev-registry";
import { msw } from "./helpers/msw";

jest.unmock("undici");

/**
* Sometimes the devRegistry killed by some reason, the register worker will to restart it.
*/
describe("unstable devRegistry testing", () => {
afterAll(async () => {
await stopWorkerRegistry();
beforeAll(() => {
msw.close();
});

it("should start the devRegistry if the devRegistry not start", async () => {
await registerWorker("test", {
const handle = new RegistryHandle("test", () => {});
await handle.update({
port: 6789,
protocol: "http",
host: "localhost",
mode: "local",
durableObjects: [{ name: "testing", className: "testing" }],
});
const resp = await fetch("http://localhost:6284/workers");
if (resp) {
const parsedResp = (await resp.json()) as {
test: unknown;
};
expect(parsedResp.test).toBeTruthy();
}
const parsedResp = (await resp.json()) as {
test: unknown;
};
expect(parsedResp.test).toBeTruthy();
});

it("should not restart the devRegistry if the devRegistry already start", async () => {
await startWorkerRegistry();
const handle = new RegistryHandle("test", () => {});
await handle.query(); // Ensure registry started

await fetch("http://localhost:6284/workers/init", {
method: "POST",
body: JSON.stringify({}),
});

await registerWorker("test", {
await handle.update({
port: 6789,
protocol: "http",
host: "localhost",
Expand All @@ -49,13 +46,11 @@ describe("unstable devRegistry testing", () => {
});

const resp = await fetch("http://localhost:6284/workers");
if (resp) {
const parsedResp = (await resp.json()) as {
test: unknown;
init: unknown;
};
expect(parsedResp.init).toBeTruthy();
expect(parsedResp.test).toBeTruthy();
}
const parsedResp = (await resp.json()) as {
test: unknown;
init: unknown;
};
expect(parsedResp.init).toBeTruthy();
expect(parsedResp.test).toBeTruthy();
});
});
5 changes: 0 additions & 5 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,6 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
assets: config.assets,
// enable the cache when publishing
bypassAssetCache: false,
services: config.services,
// We don't set workerDefinitions here,
// because we don't want to apply the dev-time
// facades on top of it
workerDefinitions: undefined,
// We want to know if the build is for development or publishing
// This could potentially cause issues as we no longer have identical behaviour between dev and deploy?
targetConsumer: "deploy",
Expand Down
28 changes: 0 additions & 28 deletions packages/wrangler/src/deployment-bundle/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export type BundleOptions = {
nodejsCompat?: boolean;
define: Config["define"];
checkFetch: boolean;
services?: Config["services"];
workerDefinitions?: WorkerRegistry;
targetConsumer: "dev" | "deploy";
testScheduled?: boolean;
inject?: string[];
Expand Down Expand Up @@ -111,8 +109,6 @@ export async function bundleWorker(
checkFetch,
assets,
bypassAssetCache,
workerDefinitions,
services,
targetConsumer,
testScheduled,
inject: injectOption,
Expand Down Expand Up @@ -186,30 +182,6 @@ export async function bundleWorker(
});
}

if (
targetConsumer === "dev" &&
!!(
workerDefinitions &&
Object.keys(workerDefinitions).length > 0 &&
services &&
services.length > 0
)
) {
middlewareToLoad.push({
name: "multiworker-dev",
path: "templates/middleware/middleware-multiworker-dev.ts",
config: {
workers: Object.fromEntries(
(services || []).map((serviceBinding) => [
serviceBinding.binding,
workerDefinitions?.[serviceBinding.service] || null,
])
),
},
supports: ["modules"],
});
}

// If using watch, build result will not be returned.
// This plugin will retrieve the build result on the first build.
let initialBuildResult: (result: esbuild.BuildResult) => void;
Expand Down
213 changes: 0 additions & 213 deletions packages/wrangler/src/dev-registry.ts

This file was deleted.

Loading