Whilst looking at making a PR from honojs/honox#83, I have noticed that the value for env used by the dev-server plugin is overwritten depending on the configuration used.
See:
let env: Env = {}
console.log('OPTIONS', options)
if (options?.env) {
if (typeof options.env === 'function') {
env = await options.env()
} else {
env = options.env
}
} else if (options?.cf) {
env = await cloudflarePagesGetEnv(options.cf)()
}
if (options?.plugins) {
for (const plugin of options.plugins) {
if (plugin.env) {
env = typeof plugin.env === 'function' ? await plugin.env() : plugin.env
}
}
}
if you supply via root env, and then also cf (albeit deprecated), and then multiple plugins, only the values in the last plugin will be passed through.
Is this intended behaviour? Or should each configuration option extend env
I found this by adding a second plugin in the e2e tests, see below.
export default defineConfig(async () => {
const { env, dispose } = await getPlatformProxy({ configPath: './wrangler.toml' })
return {
plugins: [
devServer({
entry: './mock/worker.ts',
exclude: [...defaultOptions.exclude, '/app/**'],
plugins: [
{ onServerClose: dispose, env },
pages({
bindings: {
NAME: 'Hono',
},
}),
],
}),
],
}
})
This results in only the NAME binding passed through, and those set in wrangler.toml picked up by getPlatformProxy being ignored.
This can be worked around by extending the bindings property of the cloudflare-pages package like so
pages({
bindings: {
NAME: 'Hono',
...env,
},
}),
Is it intended to be able to supply multiple methods of configuration? If so, this code can be updated to extend rather than assign.
Whilst looking at making a PR from honojs/honox#83, I have noticed that the value for
envused by the dev-server plugin is overwritten depending on the configuration used.See:
if you supply via root
env, and then alsocf(albeit deprecated), and then multiple plugins, only the values in the last plugin will be passed through.Is this intended behaviour? Or should each configuration option extend
envI found this by adding a second plugin in the e2e tests, see below.
This results in only the NAME binding passed through, and those set in wrangler.toml picked up by getPlatformProxy being ignored.
This can be worked around by extending the
bindingsproperty of thecloudflare-pagespackage like soIs it intended to be able to supply multiple methods of configuration? If so, this code can be updated to extend rather than assign.