Skip to content

Commit 386ff6e

Browse files
authored
[miniflare] Register workers in the dev registry by default (#15061)
1 parent 35c87e9 commit 386ff6e

12 files changed

Lines changed: 17 additions & 69 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
"miniflare": major
2+
"miniflare": minor
33
---
44

5-
Add per-worker control over dev registry registration
5+
Add an option to disable dev registry registration
66

7-
Miniflare workers must now opt in to the dev registry with `unsafeRegisterWorker`. Wrangler and the Cloudflare Vite plugin use this option to advertise user workers without exposing internal or external workers.
7+
Set `unsafeRegisterWorker` to `false` to prevent a Miniflare worker from being advertised in the dev registry. Workers continue to be registered by default.

fixtures/entrypoints-rpc-tests/tests/entrypoints.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ describe("entrypoints", () => {
890890
const boundWorker = new Miniflare({
891891
name: "bound",
892892
unsafeDevRegistryPath: isolatedDevRegistryPath,
893-
unsafeRegisterWorker: true,
894893
compatibilityFlags: ["experimental"],
895894
modules: true,
896895
https: true,

packages/miniflare/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ parameter in module format Workers.
220220

221221
- `unsafeRegisterWorker?: boolean`
222222

223-
If `true`, advertises this Worker in the dev registry configured by
224-
`unsafeDevRegistryPath`. Defaults to `false`.
223+
Whether to advertise this Worker in the dev registry configured by
224+
`unsafeDevRegistryPath`. Defaults to `true`.
225225

226226
- `rootPath?: string`
227227

@@ -603,8 +603,8 @@ Options shared between all Workers/"nanoservices".
603603

604604
Path to the dev registry directory. This allows Miniflare to automatically
605605
discover external services and Durable Objects running on another Miniflare
606-
instance and connect them. Workers must opt in to being advertised by setting
607-
`unsafeRegisterWorker` to `true`.
606+
instance and connect them. Workers are advertised by default; set
607+
`unsafeRegisterWorker` to `false` to opt out.
608608

609609
- `unsafeDevRegistryDurableObjectProxy?: boolean`
610610

packages/miniflare/src/plugins/core/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ const CoreOptionsSchemaInput = z.intersection(
189189

190190
unsafeEvalBinding: z.string().optional(),
191191
unsafeUseModuleFallbackService: z.boolean().optional(),
192-
/** Whether this Worker should be advertised in the dev registry. Defaults to `false`. */
193-
unsafeRegisterWorker: z.boolean().optional(),
192+
/** Whether this Worker should be advertised in the dev registry. Defaults to `true`. */
193+
unsafeRegisterWorker: z.boolean().default(true),
194194

195195
/** Used to set the vitest pool worker SELF binding to point to the Router Worker if there are assets.
196196
(If there are assets but we're not using vitest, the miniflare entry worker can point directly to

packages/miniflare/src/shared/DEV_REGISTRY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type WorkerDefinition = {
5555
```
5656

5757
- **Heartbeat**: Every 30s, the file's mtime is touched to signal that the Worker is still running.
58-
- **Registration**: Only workers with `unsafeRegisterWorker: true` are advertised.
58+
- **Registration**: Named workers are advertised by default. Workers with `unsafeRegisterWorker: false` are not advertised.
5959
- **Stale cleanup**: On every read, files older than 5 minutes are deleted (5 minutes is much longer than 30s just to provide a safe buffer)
6060
- **Change detection**: Chokidar watches the registry directory. When a file changes, `refresh()` compares the new state against the previous JSON snapshot and fires `onUpdate` only if a watched external service actually changed.
6161

packages/miniflare/test/dev-registry.spec.ts

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useDispose, useTmp } from "./test-shared";
66
import type { MiniflareOptions, WorkerRegistry } from "miniflare";
77

88
describe.sequential("DevRegistry", () => {
9-
test("only registers workers that opt in", async ({ expect }) => {
9+
test("registers workers by default unless opted out", async ({ expect }) => {
1010
const unsafeDevRegistryPath = await useTmp();
1111
const workerOptions = {
1212
name: "worker",
@@ -19,17 +19,16 @@ describe.sequential("DevRegistry", () => {
1919
useDispose(mf);
2020
await mf.ready;
2121

22-
expect(getWorkerRegistry(unsafeDevRegistryPath)).toEqual({});
23-
24-
await mf.setOptions({ ...workerOptions, unsafeRegisterWorker: true });
2522
expect(getWorkerRegistry(unsafeDevRegistryPath)["worker"]).toBeDefined();
23+
24+
await mf.setOptions({ ...workerOptions, unsafeRegisterWorker: false });
25+
expect(getWorkerRegistry(unsafeDevRegistryPath)).toEqual({});
2626
});
2727

2828
test("fetch to service worker", async ({ expect }) => {
2929
const unsafeDevRegistryPath = await useTmp();
3030
const remote = new Miniflare({
3131
name: "remote-worker",
32-
unsafeRegisterWorker: true,
3332
unsafeDevRegistryPath,
3433
compatibilityFlags: ["experimental"],
3534
script: `addEventListener("fetch", (event) => {
@@ -114,7 +113,6 @@ describe.sequential("DevRegistry", () => {
114113

115114
const remote = new Miniflare({
116115
name: "remote-worker",
117-
unsafeRegisterWorker: true,
118116
unsafeDevRegistryPath,
119117
compatibilityFlags: ["experimental"],
120118
modules: true,
@@ -192,7 +190,6 @@ describe.sequential("DevRegistry", () => {
192190

193191
const remote = new Miniflare({
194192
name: "remote-worker",
195-
unsafeRegisterWorker: true,
196193
unsafeDevRegistryPath,
197194
compatibilityFlags: ["experimental"],
198195
modules: true,
@@ -269,7 +266,6 @@ describe.sequential("DevRegistry", () => {
269266

270267
const remote = new Miniflare({
271268
name: "remote-worker",
272-
unsafeRegisterWorker: true,
273269
unsafeDevRegistryPath,
274270
compatibilityFlags: ["experimental"],
275271
modules: true,
@@ -341,7 +337,6 @@ describe.sequential("DevRegistry", () => {
341337

342338
const remote = new Miniflare({
343339
name: "remote-worker",
344-
unsafeRegisterWorker: true,
345340
unsafeDevRegistryPath,
346341
compatibilityFlags: ["experimental"],
347342
modules: true,
@@ -382,7 +377,6 @@ describe.sequential("DevRegistry", () => {
382377
const unsafeDevRegistryPath = await useTmp();
383378
const remote = new Miniflare({
384379
name: "remote-worker",
385-
unsafeRegisterWorker: true,
386380
unsafeDevRegistryPath,
387381
compatibilityFlags: ["experimental"],
388382
modules: true,
@@ -471,7 +465,6 @@ describe.sequential("DevRegistry", () => {
471465

472466
const remote = new Miniflare({
473467
name: "remote-worker",
474-
unsafeRegisterWorker: true,
475468
unsafeDevRegistryPath,
476469
compatibilityFlags: ["experimental"],
477470
modules: true,
@@ -555,7 +548,6 @@ describe.sequential("DevRegistry", () => {
555548

556549
const remote = new Miniflare({
557550
name: "remote-worker",
558-
unsafeRegisterWorker: true,
559551
unsafeDevRegistryPath,
560552
compatibilityFlags: ["experimental"],
561553
modules: true,
@@ -597,7 +589,6 @@ describe.sequential("DevRegistry", () => {
597589
const unsafeDevRegistryPath = await useTmp();
598590
const remote = new Miniflare({
599591
name: "remote-worker",
600-
unsafeRegisterWorker: true,
601592
unsafeDevRegistryPath,
602593

603594
compatibilityFlags: ["experimental"],
@@ -665,7 +656,6 @@ describe.sequential("DevRegistry", () => {
665656
const unsafeDevRegistryPath = await useTmp();
666657
const remote = new Miniflare({
667658
name: "remote-worker",
668-
unsafeRegisterWorker: true,
669659
unsafeDevRegistryPath,
670660

671661
compatibilityFlags: ["experimental"],
@@ -766,7 +756,6 @@ describe.sequential("DevRegistry", () => {
766756

767757
const remote = new Miniflare({
768758
name: "remote-worker",
769-
unsafeRegisterWorker: true,
770759
unsafeDevRegistryPath,
771760

772761
compatibilityFlags: ["experimental"],
@@ -845,7 +834,6 @@ describe.sequential("DevRegistry", () => {
845834

846835
const remote = new Miniflare({
847836
name: "remote-worker",
848-
unsafeRegisterWorker: true,
849837
unsafeDevRegistryPath,
850838

851839
compatibilityFlags: ["experimental"],
@@ -906,7 +894,6 @@ describe.sequential("DevRegistry", () => {
906894

907895
const remote = new Miniflare({
908896
name: "remote-worker",
909-
unsafeRegisterWorker: true,
910897
unsafeDevRegistryPath,
911898

912899
workflows: {
@@ -950,7 +937,6 @@ describe.sequential("DevRegistry", () => {
950937

951938
const remote = new Miniflare({
952939
name: "remote-worker",
953-
unsafeRegisterWorker: true,
954940
unsafeDevRegistryPath,
955941
compatibilityFlags: ["experimental"],
956942
durableObjects: {
@@ -1014,7 +1000,6 @@ describe.sequential("DevRegistry", () => {
10141000
// Restart remote — gets a new debug port, registry file updates
10151001
await remote.setOptions({
10161002
name: "remote-worker",
1017-
unsafeRegisterWorker: true,
10181003
unsafeDevRegistryPath,
10191004
compatibilityFlags: ["experimental"],
10201005
durableObjects: {
@@ -1053,7 +1038,6 @@ describe.sequential("DevRegistry", () => {
10531038

10541039
const remote = new Miniflare({
10551040
name: "remote-worker",
1056-
unsafeRegisterWorker: true,
10571041
unsafeDevRegistryPath,
10581042
compatibilityFlags: ["experimental"],
10591043
modules: true,
@@ -1103,7 +1087,6 @@ describe.sequential("DevRegistry", () => {
11031087
// Restart remote — gets a new debug port, registry file updates
11041088
await remote.setOptions({
11051089
name: "remote-worker",
1106-
unsafeRegisterWorker: true,
11071090
unsafeDevRegistryPath,
11081091
compatibilityFlags: ["experimental"],
11091092
modules: true,
@@ -1131,7 +1114,6 @@ describe.sequential("DevRegistry", () => {
11311114
const unsafeDevRegistryPath = await useTmp();
11321115
const remote = new Miniflare({
11331116
name: "remote-worker",
1134-
unsafeRegisterWorker: true,
11351117
unsafeDevRegistryPath,
11361118
unsafeTriggerHandlers: true,
11371119
compatibilityFlags: ["experimental"],
@@ -1194,7 +1176,6 @@ describe.sequential("DevRegistry", () => {
11941176
const unsafeDevRegistryPath = await useTmp();
11951177
const remote = new Miniflare({
11961178
name: "remote-worker",
1197-
unsafeRegisterWorker: true,
11981179
unsafeDevRegistryPath,
11991180
compatibilityFlags: ["experimental"],
12001181
modules: true,
@@ -1304,7 +1285,6 @@ describe.sequential("DevRegistry", () => {
13041285
const unsafeDevRegistryPath = await useTmp();
13051286
const remote = new Miniflare({
13061287
name: "remote-worker",
1307-
unsafeRegisterWorker: true,
13081288
unsafeDevRegistryPath,
13091289
compatibilityFlags: ["experimental"],
13101290
modules: true,
@@ -1407,7 +1387,6 @@ describe.sequential("DevRegistry", () => {
14071387
};
14081388
const remoteOptions: MiniflareOptions = {
14091389
name: "remote-worker",
1410-
unsafeRegisterWorker: true,
14111390
compatibilityFlags: ["experimental"],
14121391
modules: true,
14131392
script: `
@@ -1513,7 +1492,6 @@ describe.sequential("DevRegistry", () => {
15131492

15141493
const remote = new Miniflare({
15151494
name: "remote-worker",
1516-
unsafeRegisterWorker: true,
15171495
unsafeDevRegistryPath,
15181496
compatibilityFlags: ["experimental"],
15191497
modules: true,
@@ -1581,7 +1559,6 @@ describe.sequential("DevRegistry", () => {
15811559

15821560
const remote = new Miniflare({
15831561
name: "remote-worker",
1584-
unsafeRegisterWorker: true,
15851562
unsafeDevRegistryPath,
15861563

15871564
https: true,
@@ -1666,7 +1643,6 @@ describe.sequential("DevRegistry", () => {
16661643
const unrelated = new Miniflare({
16671644
name: "unrelated-worker",
16681645
unsafeDevRegistryPath,
1669-
unsafeRegisterWorker: true,
16701646
compatibilityFlags: ["experimental"],
16711647
modules: true,
16721648
script: `
@@ -1688,7 +1664,6 @@ describe.sequential("DevRegistry", () => {
16881664
// Create remote worker (one we're actually bound to) - this should trigger the callback
16891665
const remote = new Miniflare({
16901666
name: "remote-worker",
1691-
unsafeRegisterWorker: true,
16921667
unsafeDevRegistryPath,
16931668
compatibilityFlags: ["experimental"],
16941669
modules: true,
@@ -1792,7 +1767,6 @@ describe.sequential("DevRegistry", () => {
17921767
const sharedOptions = {
17931768
name: "consumer-worker",
17941769
unsafeDevRegistryPath,
1795-
unsafeRegisterWorker: true,
17961770
compatibilityFlags: ["experimental"],
17971771
modules: true,
17981772
} satisfies Partial<MiniflareOptions>;
@@ -1846,7 +1820,6 @@ describe("registry churn across config updates", () => {
18461820
const unsafeDevRegistryPath = await useTmp();
18471821
const mf = new Miniflare({
18481822
name: "stable-worker",
1849-
unsafeRegisterWorker: true,
18501823
unsafeDevRegistryPath,
18511824
modules: true,
18521825
script: script("before"),
@@ -1881,7 +1854,6 @@ describe("registry churn across config updates", () => {
18811854

18821855
await mf.setOptions({
18831856
name: "stable-worker",
1884-
unsafeRegisterWorker: true,
18851857
unsafeDevRegistryPath,
18861858
modules: true,
18871859
script: script("after"),
@@ -1910,7 +1882,6 @@ describe("registry churn across config updates", () => {
19101882
const unsafeDevRegistryPath = await useTmp();
19111883
const mf = new Miniflare({
19121884
name: "doomed-worker",
1913-
unsafeRegisterWorker: true,
19141885
unsafeDevRegistryPath,
19151886
modules: true,
19161887
script: script("before"),
@@ -1932,7 +1903,6 @@ describe("registry churn across config updates", () => {
19321903
await expect(
19331904
mf.setOptions({
19341905
name: "doomed-worker",
1935-
unsafeRegisterWorker: true,
19361906
unsafeDevRegistryPath,
19371907
modules: true,
19381908
script: script("after"),
@@ -1957,15 +1927,13 @@ describe("registry churn across config updates", () => {
19571927
workers: [
19581928
{
19591929
name: "kept-worker",
1960-
unsafeRegisterWorker: true,
19611930
modules: true,
19621931
script: script("kept"),
19631932
},
19641933
// A name that exists on `Object.prototype`, so a membership test that
19651934
// walks the prototype chain would report it as still configured.
19661935
{
19671936
name: "constructor",
1968-
unsafeRegisterWorker: true,
19691937
modules: true,
19701938
script: script("dropped"),
19711939
},
@@ -1990,7 +1958,6 @@ describe("registry churn across config updates", () => {
19901958
workers: [
19911959
{
19921960
name: "kept-worker",
1993-
unsafeRegisterWorker: true,
19941961
modules: true,
19951962
script: script("kept"),
19961963
},
@@ -2016,13 +1983,11 @@ describe("registry churn across config updates", () => {
20161983
workers: [
20171984
{
20181985
name: "kept-worker",
2019-
unsafeRegisterWorker: true,
20201986
modules: true,
20211987
script: script("kept"),
20221988
},
20231989
{
20241990
name: "dropped-worker",
2025-
unsafeRegisterWorker: true,
20261991
modules: true,
20271992
script: script("dropped"),
20281993
},
@@ -2045,7 +2010,6 @@ describe("registry churn across config updates", () => {
20452010
workers: [
20462011
{
20472012
name: "kept-worker",
2048-
unsafeRegisterWorker: true,
20492013
modules: true,
20502014
script: script("kept"),
20512015
},

0 commit comments

Comments
 (0)