Skip to content

Commit

Permalink
pass bindings correctly to miniflare in dev (#173)
Browse files Browse the repository at this point in the history
* pass bindings correctly to miniflare in `dev`

When calling miniflare in `dev` the bindings are passed into the process that's spawned incorrectly; each arg needs to be a separate element in the args array to the spawn call. This PR fixes how they're added to the args array. It also enables logs on the miniflare process. (they're a bit noisy, but we can make that better separately.)

I'm personally annoyed because I can swear this was working previously, but without tests that's just my word against... my own word, lol.

fixes #172

* add a changeset
  • Loading branch information
threepointone authored Dec 30, 2021
1 parent baf3870 commit 7156e39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-humans-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Pass bindings correctly to miniflare/child_process.spawn in `dev`, to prevent miniflare from erroring out on startup
22 changes: 11 additions & 11 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ function useLocalWorker(props: {
"--kv-persist",
"--cache-persist",
"--do-persist",
...Object.entries(bindings.vars || {}).map(([key, value]) => {
return `--binding ${key}=${value}`;
...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
return ["--binding", `${key}=${value}`];
}),
...(bindings.kv_namespaces || []).map(({ binding }) => {
return `--kv ${binding}`;
...(bindings.kv_namespaces || []).flatMap(({ binding }) => {
return ["--kv", binding];
}),
...(bindings.durable_objects?.bindings || []).map(
...(bindings.durable_objects?.bindings || []).flatMap(
({ name, class_name }) => {
return `--do ${name}=${class_name}`;
return ["--do", `${name}=${class_name}`];
}
),
"--modules",
Expand All @@ -289,15 +289,15 @@ function useLocalWorker(props: {
}
});

local.current.stdout.on("data", (_data: string) => {
// console.log(`stdout: ${data}`);
local.current.stdout.on("data", (data: Buffer) => {
console.log(`${data.toString()}`);
});

local.current.stderr.on("data", (data: string) => {
// console.error(`stderr: ${data}`);
local.current.stderr.on("data", (data: Buffer) => {
console.error(`${data.toString()}`);
const matches =
/Debugger listening on (ws:\/\/127\.0\.0\.1:9229\/[A-Za-z0-9-]+)/.exec(
data
data.toString()
);
if (matches) {
setInspectorUrl(matches[1]);
Expand Down

0 comments on commit 7156e39

Please sign in to comment.