-
Notifications
You must be signed in to change notification settings - Fork 203
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
Add new --bindings
command line argument
#218
Comments
@JacobMGEvans is keen to be involved in the implementation of this |
Hey everyone! 👋 Just had a chat with @JacobMGEvans and proposed an alternative. Instead of adding a Basically instead of using miniflare/packages/miniflare/src/cli.ts Lines 93 to 104 in 870b401
It would be up to you to define the options format then, and you could use a stringified JSON array if you wanted. The API is much more amenable to Wrangler's use case anyways and it already supports arbitrary bindings :
// See https://miniflare.dev/get-started/api#reference for reference
const options = {};
const bindings = JSON.parse(process.argv[2]);
for (const binding of bindings) {
if (binding.type === "plain_text") {
options.bindings ??= {};
options.bindings[binding.name] = binding.text;
}
// ...
}
// Also already supports JSON bindings
options.bindings["b"] = 42;
const mf = new Miniflare(options); |
I have a branch where instead of passing everything as command line args, I generate a wrangler.toml instead. @mrbbot do json bindings work via wrangler.toml in miniflare? |
Yeah that sounds like a much better idea. I was actually wondering if there was potential for a programmatic approach. |
I think a direct programmatic approach is cleanest, right? Rather than having another layer of indirection. |
No, they're intentionally stringified to match Wrangler 1 behaviour: miniflare/packages/core/src/plugins/bindings.ts Lines 116 to 127 in 870b401
|
Just trying to avoid a major refactor at this point, but if that's the only option we have, sure I guess. |
This argument is a JSON stringified array of all the bindings that are being passed from Wrangler in the same format as would be uploaded to a Worker during publishing...
For example, if you have the following
vars
in wrangler.toml:Then we actually create bindings that look like:
The same would apply to other binding types such as
It is then up to Miniflare to parse the JSON and work out how to assign the bindings to the appropriate plugins.
This would mean that Wrangler would not need to use the specific keys such as
--kv
,--binding
, etc in a backwardly compatible way.The text was updated successfully, but these errors were encountered: