feat: interactive JSON / JSON5 mode selector at build time

Lets the operator pick between strict JSON (legacy) and JSON5 for every
configuration file consumed by Nitro and the renderer.

- scripts/configure-json.mjs: interactive prompt (JSON5 recommended),
  with --if-missing and --non-interactive flags for CI use
- package.json: yarn configure / prestart / prebuild hooks
- vite.config.mjs: reads .nitro-build.json (or NITRO_JSON_MODE env) and
  injects the compile-time constant __NITRO_JSON_MODE__ via define
- src/bootstrap.ts: routes client-mode.json parsing through the
  selected mode
- .gitignore: ignore the per-deployment .nitro-build.json
- README: full usage and override section
- public/configuration assets regenerated by the updated prebuild flow

The renderer side (@nitrots/utils JsonParser) is updated in the
companion Nitro_Render_V3 commit on the dev branch.
This commit is contained in:
medievalshell
2026-05-18 20:38:26 +02:00
parent b2318b9e7c
commit 2fded7bc79
8 changed files with 276 additions and 22 deletions
+31 -3
View File
@@ -1,6 +1,22 @@
import JSON5 from 'json5';
import { configFileUrl, getClientMode, installSecureFetch } from './secure-assets';
declare const __NITRO_JSON_MODE__: 'legacy' | 'json5' | 'auto' | undefined;
const resolveJsonMode = (): 'legacy' | 'json5' | 'auto' =>
{
try
{
if(typeof __NITRO_JSON_MODE__ !== 'undefined' && __NITRO_JSON_MODE__)
{
if(__NITRO_JSON_MODE__ === 'legacy' || __NITRO_JSON_MODE__ === 'json5' || __NITRO_JSON_MODE__ === 'auto') return __NITRO_JSON_MODE__;
}
}
catch {}
return 'auto';
};
const ensureMobileViewport = () =>
{
let viewport = document.querySelector<HTMLMetaElement>('meta[name="viewport"]');
@@ -76,16 +92,28 @@ const loadClientMode = async () =>
if(!response.ok) throw new Error(`HTTP ${ response.status }`);
const text = await response.text();
const mode = resolveJsonMode();
try
if(mode === 'legacy')
{
(window as any).__nitroClientMode = JSON.parse(text);
}
catch
else if(mode === 'json5')
{
(window as any).__nitroClientMode = JSON5.parse(text);
}
setBootDebug('boot: client-mode loaded');
else
{
try
{
(window as any).__nitroClientMode = JSON.parse(text);
}
catch
{
(window as any).__nitroClientMode = JSON5.parse(text);
}
}
setBootDebug(`boot: client-mode loaded (mode=${ mode })`);
}
catch(error)
{