chore: update to vite's hook filter (#3333)

Fixes https://github.com/denoland/fresh/issues/3331
This commit is contained in:
Marvin Hagemeister
2025-09-04 11:16:06 +02:00
committed by GitHub
parent baf774517b
commit b94aab2a1a
10 changed files with 432 additions and 418 deletions
@@ -19,25 +19,32 @@ export function clientEntryPlugin(options: ResolvedFreshViteConfig): Plugin {
configResolved(config) {
clientEntry = pathWithRoot(options.clientEntry, config.root);
},
resolveId(id) {
if (id === modName) {
return `\0${modName}`;
} else if (id === modNameUser) {
return clientEntry;
}
resolveId: {
filter: {
id: /(fresh:client-entry|fresh:client-entry-user)/,
},
handler(id) {
if (id === modName) {
return `\0${modName}`;
} else if (id === modNameUser) {
return clientEntry;
}
},
},
async load(id) {
if (id !== `\0${modName}`) return;
load: {
filter: {
id: /\0fresh:client-entry/,
},
async handler() {
let exists = false;
try {
const stat = await Deno.stat(clientEntry);
exists = stat.isFile;
} catch {
exists = false;
}
let exists = false;
try {
const stat = await Deno.stat(clientEntry);
exists = stat.isFile;
} catch {
exists = false;
}
return `
return `
${isDev ? 'import "preact/debug"' : ""}
export * from "fresh/runtime-client";
${exists ? `import "fresh:client-entry-user";` : ""}
@@ -52,6 +59,7 @@ if (import.meta.hot) {
});
}
`;
},
},
};
}