Skip to content

Commit d64758f

Browse files
committed
vite 8 compat manifest plugin
1 parent 926336c commit d64758f

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

packages/start/src/config/manifest.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,48 @@ export function manifest(start: SolidStartOptions): PluginOption {
4040
v => "isEntry" in v && v.isEntry,
4141
);
4242
if (!entry) throw new Error("No client entry found");
43-
clientViteManifest = JSON.parse(
44-
(globalThis.START_CLIENT_BUNDLE[".vite/manifest.json"] as any).source,
45-
);
43+
let viteStrVersion = (devServer?.config?.logger as any)?.config?.version;
44+
if (!viteStrVersion) {
45+
try {
46+
viteStrVersion = await import("vite").then(m => m.version);
47+
} catch (e) {
48+
// ignore
49+
}
50+
}
51+
52+
let rawManifest: string | undefined;
53+
54+
const viteMajor = parseInt(viteStrVersion!.split('.')[0], 10);
55+
56+
const manifestKey = Object.keys(globalThis.START_CLIENT_BUNDLE).find(k => k.endsWith("manifest.json"));
57+
if (manifestKey && viteMajor < 8) {
58+
const manifestAsset = globalThis.START_CLIENT_BUNDLE[manifestKey] as any;
59+
if (manifestAsset.type === "asset") {
60+
rawManifest = manifestAsset.source as string;
61+
} else if (manifestAsset.type === "chunk") {
62+
rawManifest = manifestAsset.code as string;
63+
} else if (typeof manifestAsset === "string") {
64+
rawManifest = manifestAsset;
65+
} else {
66+
rawManifest = manifestAsset.source || manifestAsset.code || JSON.stringify(manifestAsset);
67+
}
68+
} else {
69+
const fs = await import("node:fs");
70+
const path = await import("node:path");
71+
try {
72+
const appRoot = (start as any).appRoot || "./src";
73+
const manifestPath = path.resolve(appRoot, "..", ".solid-start/client/.vite/manifest.json");
74+
rawManifest = fs.readFileSync(manifestPath, "utf-8");
75+
} catch (e) {
76+
throw new Error(`Manifest asset not found in bundle and could not be read from disk. Keys: ${Object.keys(globalThis.START_CLIENT_BUNDLE).join(", ")}. Error: ${e}`);
77+
}
78+
}
79+
80+
if (!rawManifest) {
81+
throw new Error("Failed to extract or read raw manifest.");
82+
}
83+
84+
clientViteManifest = JSON.parse(rawManifest);
4685
}
4786
return `export const clientViteManifest = ${JSON.stringify(clientViteManifest)};`;
4887
} else if (id === `\0${VIRTUAL_MODULES.middleware}`) return "export default {};";

0 commit comments

Comments
 (0)