Skip to content

Commit 75ba023

Browse files
authored
Merge branch 'main' into rename-FreshContext-req-to-request
2 parents e36edb1 + 1f3f0a4 commit 75ba023

28 files changed

Lines changed: 979 additions & 119 deletions

deno.lock

Lines changed: 88 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/fresh/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class App<State> {
330330
if (cmd.type !== CommandType.App && cmd.type !== CommandType.NotFound) {
331331
const clone = {
332332
...cmd,
333-
pattern: mergePath(path, cmd.pattern),
333+
pattern: mergePath(path, cmd.pattern, true),
334334
includeLastSegment: cmd.pattern === "/" || cmd.includeLastSegment,
335335
};
336336
this.#commands.push(clone);

packages/fresh/src/commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ function applyCommandsInner<State>(
273273
const routePath = mergePath(
274274
basePath,
275275
config?.routeOverride ?? pattern,
276+
false,
276277
);
277278

278279
let def: Route<State>;
@@ -304,6 +305,7 @@ function applyCommandsInner<State>(
304305
const routePath = toRoutePath(mergePath(
305306
basePath,
306307
route.config?.routeOverride ?? pattern,
308+
false,
307309
));
308310

309311
if (typeof route.handler === "function") {
@@ -333,7 +335,7 @@ function applyCommandsInner<State>(
333335

334336
result.push(...fns);
335337

336-
const resPath = toRoutePath(mergePath(basePath, pattern));
338+
const resPath = toRoutePath(mergePath(basePath, pattern, false));
337339
if (method === "ALL") {
338340
router.add("GET", resPath, result);
339341
router.add("DELETE", resPath, result);

packages/fresh/src/dev/builder_test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,42 @@ Deno.test({
389389
sanitizeResources: false,
390390
});
391391

392+
Deno.test({
393+
name: "Builder - dev server supports basePath",
394+
fn: async () => {
395+
const root = path.join(import.meta.dirname!, "..", "..");
396+
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
397+
const tmp = _tmp.dir;
398+
399+
const app = new App({ basePath: "/foo/bar" })
400+
.get("/", () => new Response("ok"))
401+
.get("/asdf", () => new Response("ok"));
402+
403+
const builder = new Builder({
404+
root: tmp,
405+
outDir: path.join(tmp, "dist"),
406+
});
407+
408+
const controller = new AbortController();
409+
let address;
410+
await builder.listen(() => Promise.resolve<App<unknown>>(app), {
411+
signal: controller.signal,
412+
onListen(addr) {
413+
address = `http://localhost:${addr.port}`;
414+
},
415+
});
416+
417+
const res = await fetch(`${address}/foo/bar/asdf`);
418+
419+
const text = await res.text();
420+
expect(text).toEqual("ok");
421+
422+
controller.abort();
423+
},
424+
sanitizeOps: false,
425+
sanitizeResources: false,
426+
});
427+
392428
Deno.test({
393429
name: "Builder - serves static files in subdir",
394430
fn: async () => {

packages/fresh/src/router.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,15 @@ export function patternToSegments(
284284
return out;
285285
}
286286

287-
export function mergePath(basePath: string, path: string): string {
287+
export function mergePath(
288+
basePath: string,
289+
path: string,
290+
isMounting: boolean,
291+
): string {
288292
if (basePath.endsWith("*")) basePath = basePath.slice(0, -1);
289293
if (basePath === "/") basePath = "";
290294

291-
if (path === "*") path = "";
295+
if (path === "*") path = isMounting ? "" : "/*";
292296
else if (path === "/*") path = "/*";
293297

294298
const s = (basePath !== "" && path === "/") ? "" : path;

packages/fresh/src/router_test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,22 @@ Deno.test("patternToSegments", () => {
155155
});
156156

157157
Deno.test("mergePath", () => {
158-
expect(mergePath("", "/foo")).toEqual("/foo");
159-
expect(mergePath("/", "/foo")).toEqual("/foo");
160-
expect(mergePath("/foo/bar", "/")).toEqual("/foo/bar");
161-
expect(mergePath("/foo/bar", "/baz")).toEqual("/foo/bar/baz");
162-
expect(mergePath("*", "/baz")).toEqual("/baz");
163-
expect(mergePath("/*", "/baz")).toEqual("/baz");
164-
expect(mergePath("/foo", "*")).toEqual("/foo");
165-
expect(mergePath("/foo", "/*")).toEqual("/foo/*");
158+
expect(mergePath("", "/foo", false)).toEqual("/foo");
159+
expect(mergePath("/", "/foo", false)).toEqual("/foo");
160+
expect(mergePath("/foo/bar", "/", false)).toEqual("/foo/bar");
161+
expect(mergePath("/foo/bar", "/baz", false)).toEqual("/foo/bar/baz");
162+
expect(mergePath("*", "/baz", false)).toEqual("/baz");
163+
expect(mergePath("/*", "/baz", false)).toEqual("/baz");
164+
expect(mergePath("/foo", "*", false)).toEqual("/foo/*");
165+
expect(mergePath("/foo", "/*", false)).toEqual("/foo/*");
166+
167+
// mounting
168+
expect(mergePath("", "/foo", true)).toEqual("/foo");
169+
expect(mergePath("/", "/foo", true)).toEqual("/foo");
170+
expect(mergePath("/foo/bar", "/", true)).toEqual("/foo/bar");
171+
expect(mergePath("/foo/bar", "/baz", true)).toEqual("/foo/bar/baz");
172+
expect(mergePath("*", "/baz", true)).toEqual("/baz");
173+
expect(mergePath("/*", "/baz", true)).toEqual("/baz");
174+
expect(mergePath("/foo", "*", true)).toEqual("/foo");
175+
expect(mergePath("/foo", "/*", true)).toEqual("/foo/*");
166176
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.value = "ok";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { value } from "../../fixtures/commonjs_mod.cjs";
2+
3+
export default function Page() {
4+
return <h1>{value}</h1>;
5+
}

packages/plugin-vite/deno.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "@fresh/plugin-vite",
3-
"version": "0.0.1",
3+
"version": "0.0.3",
44
"license": "MIT",
55
"exports": {
66
".": "./src/mod.ts"
77
},
8+
"publish": {
9+
"include": ["./src", "README.md"]
10+
},
811
"compilerOptions": {
912
"jsx": "precompile",
1013
"jsxImportSource": "preact"
@@ -16,8 +19,10 @@
1619
"demo:start": "cd demo && deno serve -A _fresh/server/server-entry.mjs"
1720
},
1821
"imports": {
22+
"@babel/core": "npm:@babel/core@^7.28.0",
1923
"@deno/loader": "jsr:@deno/loader@^0.3.2",
2024
"@prefresh/vite": "npm:@prefresh/vite@^2.4.8",
25+
"@types/babel__core": "npm:@types/babel__core@^7.20.5",
2126
"@types/node": "npm:@types/node@^24.1.0",
2227
"preact": "npm:preact@^10.26.9",
2328
"vite": "npm:vite@^7.0.6",

packages/plugin-vite/src/mod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { devServer } from "./plugins/dev_server.ts";
1212
import { buildIdPlugin } from "./plugins/build_id.ts";
1313
import { clientSnapshot } from "./plugins/client_snapshot.ts";
1414
import { serverSnapshot } from "./plugins/server_snapshot.ts";
15+
import { patches } from "./plugins/patches.ts";
1516

1617
export function fresh(config?: FreshViteConfig): Plugin[] {
1718
const fConfig: ResolvedFreshViteConfig = {
@@ -37,7 +38,6 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
3738
"react-dom": "preact/compat",
3839
react: "preact/compat",
3940
},
40-
noExternal: true,
4141
},
4242
optimizeDeps: {
4343
include: [
@@ -108,6 +108,7 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
108108
fConfig.routeDir = pathWithRoot(fConfig.routeDir, config.root);
109109
},
110110
},
111+
patches(),
111112
serverEntryPlugin(fConfig),
112113
...serverSnapshot(fConfig),
113114
clientEntryPlugin(),

0 commit comments

Comments
 (0)