chore: restructure repository into packages/ folder (#3197)

We're having a growing number of packages in this repository. This PR
moves them into a `packages/` directory like it's commonly done in other
projects.
This commit is contained in:
Marvin Hagemeister
2025-08-06 15:52:45 +02:00
committed by GitHub
parent 27e407a1e3
commit 815b1940e3
184 changed files with 94 additions and 82 deletions
@@ -0,0 +1,79 @@
import type { Plugin } from "vite";
import { nodeToRequest, responseToNode } from "../request.ts";
import * as path from "@std/path";
import { pathWithRoot } from "../utils.ts";
export function devServer(): Plugin[] {
let publicDir = "";
return [
{
name: "fresh:dev_server",
configResolved(cfg) {
publicDir = pathWithRoot(cfg.publicDir, cfg.root);
},
configureServer(server) {
const IGNORE_URLS = /^\/(@(vite|fs|id)|\.vite)\//;
server.middlewares.use(async (nodeReq, nodeRes, next) => {
const serverCfg = server.config.server;
const protocol = serverCfg.https ? "https" : "http";
const host = serverCfg.host ? serverCfg.host : "localhost";
const port = serverCfg.port;
const url = new URL(
`${protocol}://${host}:${port}${nodeReq.url ?? "/"}`,
);
// Check if it's a vite url
if (
IGNORE_URLS.test(url.pathname) ||
server.environments.client.moduleGraph.urlToModuleMap.has(
url.pathname,
)
) {
return next();
}
// Check if it's a static file first
// FIXME: Should this still go through fresh?
if (url.pathname !== "/") {
try {
await Deno.stat(path.join(publicDir, url.pathname));
return next();
} catch (err) {
if (!(err instanceof Deno.errors.NotFound)) {
return next(err);
}
}
}
const mod = await server.ssrLoadModule("fresh:server_entry");
try {
const req = nodeToRequest(nodeReq, url);
const res = await mod.default.fetch(req);
await responseToNode(res, nodeRes);
return nodeRes;
} catch (err) {
return next(err);
}
});
},
},
{
name: "fresh:server_hmr",
applyToEnvironment(env) {
return env.name === "ssr";
},
hotUpdate(options) {
const clientMod = options.server.environments.client.moduleGraph
.getModulesByFile(options.file);
if (clientMod === undefined) {
options.server.hot.send("fresh:reload");
}
},
},
];
}