mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
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:
@@ -44,6 +44,11 @@
|
||||
return new URL(".", source);
|
||||
};
|
||||
|
||||
const getDeployBase = () => {
|
||||
try { return new URL("..", getBase()); }
|
||||
catch { return new URL("/", location.href); }
|
||||
};
|
||||
|
||||
const withCacheBust = (url) => {
|
||||
url.searchParams.set("v", Date.now().toString(36));
|
||||
return url;
|
||||
@@ -71,9 +76,14 @@
|
||||
|
||||
const resolveAssetCandidates = (path) => {
|
||||
const base = getBase();
|
||||
const deploy = getDeployBase();
|
||||
const normalized = path.replace(/^\.\//, "");
|
||||
const file = normalized.split("/").pop();
|
||||
const relative = normalized.replace(/^\//, "");
|
||||
const urls = [
|
||||
new URL("src/assets/" + file, deploy),
|
||||
new URL("assets/" + file, deploy),
|
||||
new URL(relative, deploy),
|
||||
new URL("./src/assets/" + file, base),
|
||||
new URL("./assets/" + file, base),
|
||||
new URL("/src/assets/" + file, base.origin),
|
||||
@@ -205,7 +215,10 @@
|
||||
|
||||
const fetchManifest = async () => {
|
||||
const base = getBase();
|
||||
const deploy = getDeployBase();
|
||||
const candidates = [
|
||||
new URL(".vite/manifest.json", deploy),
|
||||
new URL("manifest.json", deploy),
|
||||
new URL(".vite/manifest.json", base.origin + "/"),
|
||||
new URL("manifest.json", base.origin + "/"),
|
||||
new URL(".vite/manifest.json", base),
|
||||
@@ -221,7 +234,11 @@
|
||||
const json = await response.json();
|
||||
if(json && typeof json === "object") {
|
||||
debug("loader: manifest from " + candidate.href);
|
||||
return { manifest: json, base: new URL(".", candidate.href) };
|
||||
let manifestBase = new URL(".", candidate.href);
|
||||
if(/\/\.vite\/manifest\.json$/.test(candidate.pathname)) {
|
||||
manifestBase = new URL("..", manifestBase);
|
||||
}
|
||||
return { manifest: json, base: manifestBase };
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
@@ -247,18 +264,24 @@
|
||||
const resolveManifestPath = (manifestBase, file) => {
|
||||
if(/^https?:\/\//i.test(file)) return file;
|
||||
if(file.startsWith("/")) return file;
|
||||
return new URL(file, manifestBase.origin + "/").pathname;
|
||||
return new URL(file, manifestBase).pathname;
|
||||
};
|
||||
|
||||
const isLoaderUrl = (href) => /(?:^|\/)bootstrap\.js(?:$|\?|#)/i.test(href) || /(?:^|\/)asset-loader\.js(?:$|\?|#)/i.test(href);
|
||||
|
||||
const fetchEntryFromIndexHtml = async () => {
|
||||
const base = getBase();
|
||||
const deploy = getDeployBase();
|
||||
const candidates = [
|
||||
new URL("index.html", deploy),
|
||||
new URL("./", deploy),
|
||||
new URL("/index.html", base.origin + "/"),
|
||||
new URL("/", base.origin + "/")
|
||||
];
|
||||
const seen = new Set();
|
||||
for(const candidate of candidates) {
|
||||
if(seen.has(candidate.href)) continue;
|
||||
seen.add(candidate.href);
|
||||
try {
|
||||
const response = await fetch(withCacheBust(new URL(candidate.href)), { cache: "no-store" });
|
||||
if(!response.ok) continue;
|
||||
|
||||
Reference in New Issue
Block a user