@@ -274,8 +274,46 @@ runs:
274274 elif [ -f ".output/wrangler.json" ]; then
275275 NITRO_CONFIG=".output/wrangler.json"
276276 else
277- echo "::error::No Nuxt-generated wrangler.json found in .output/"
278- exit 1
277+ # No Nitro-generated config (e.g. NuxtHub's cloudflare-module preset).
278+ # Fall back to the project's wrangler.jsonc as the base config.
279+ if [ -f "wrangler.jsonc" ]; then
280+ echo "::notice::No Nuxt-generated wrangler.json in .output/, using project wrangler.jsonc as base"
281+ NITRO_CONFIG=".output/wrangler.json"
282+ mkdir -p .output
283+ # Strip JSONC comments and copy to .output/wrangler.json
284+ node --eval '
285+ const fs = require("fs");
286+ function stripJsonComments(str) {
287+ let result = "", inString = false, inLine = false, inBlock = false, i = 0;
288+ while (i < str.length) {
289+ if (!inLine && !inBlock && str[i] === "\"" && (i === 0 || str[i-1] !== "\\")) { inString = !inString; result += str[i]; i++; continue; }
290+ if (inString) { result += str[i]; i++; continue; }
291+ if (!inBlock && str.slice(i,i+2) === "//") { inLine = true; i += 2; continue; }
292+ if (!inLine && str.slice(i,i+2) === "/*") { inBlock = true; i += 2; continue; }
293+ if (inBlock && str.slice(i,i+2) === "*/") { inBlock = false; i += 2; continue; }
294+ if (inLine && (str[i] === "\n" || str[i] === "\r")) { inLine = false; result += str[i]; i++; continue; }
295+ if (inLine || inBlock) { i++; continue; }
296+ result += str[i]; i++;
297+ }
298+ return result;
299+ }
300+ const config = JSON.parse(stripJsonComments(fs.readFileSync("wrangler.jsonc", "utf8")));
301+ // Add standard Nitro output paths if not already set
302+ if (!config.main) {
303+ config.main = fs.existsSync(".output/server/index.mjs") ? "server/index.mjs" : "index.mjs";
304+ }
305+ if (!config.assets) {
306+ config.assets = { directory: "./public", binding: "ASSETS" };
307+ }
308+ if (!config.compatibility_flags) {
309+ config.compatibility_flags = ["nodejs_compat"];
310+ }
311+ fs.writeFileSync(".output/wrangler.json", JSON.stringify(config, null, 2));
312+ '
313+ else
314+ echo "::error::No Nuxt-generated wrangler.json found in .output/ and no wrangler.jsonc in project root"
315+ exit 1
316+ fi
279317 fi
280318
281319 echo "Merging $ENV_FILE into $NITRO_CONFIG..."
0 commit comments