Skip to content

Commit f1cf8ff

Browse files
major: build islands + scan routeDir without importing user code
This fixes a bunch of long standing issues in our tracker where a build wouldn't finish because of importing user code. It's common for backend apps to spawn some open ended tasks like subscribing to Deno KV or other things. This addresses another problem of having to set up ENV vars just for the build, even though they are technically not required to build islands. This also gives a roughly ~30% performance boost on cold starts.
1 parent 69af00e commit f1cf8ff

42 files changed

Lines changed: 1775 additions & 1671 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
".": "./src/mod.ts",
1515
"./runtime": "./src/runtime/shared.ts",
1616
"./dev": "./src/dev/mod.ts",
17-
"./compat": "./src/compat.ts"
17+
"./compat": "./src/compat.ts",
18+
"./do-not-use": "./src/internals.ts"
1819
},
1920
"tasks": {
2021
"test": "deno test -A --parallel",

init/src/init.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ ${GRADIENT_CSS}`;
349349
// Skip this and be silent if there is a network issue.
350350
}
351351

352-
const MAIN_TS = `import { App, fsRoutes, staticFiles } from "fresh";
352+
const MAIN_TS = `import { App, staticFiles } from "fresh";
353353
import { define, type State } from "./utils.ts";
354354
355355
export const app = new App<State>();
@@ -371,10 +371,8 @@ const exampleLoggerMiddleware = define.middleware((ctx) => {
371371
});
372372
app.use(exampleLoggerMiddleware);
373373
374-
await fsRoutes(app, {
375-
loadIsland: (path) => import(\`./islands/\${path}\`),
376-
loadRoute: (path) => import(\`./routes/\${path}\`),
377-
});
374+
// Include file-system based routes here
375+
app.fsRoutes();
378376
379377
if (import.meta.main) {
380378
await app.listen();
@@ -489,14 +487,13 @@ export default function Counter(props: CounterProps) {
489487
const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/
490488
${useTailwind ? `import { tailwind } from "@fresh/plugin-tailwind";\n` : ""}
491489
import { Builder } from "fresh/dev";
492-
import { app } from "./main.ts";
493490
494491
const builder = new Builder();
495-
${useTailwind ? "tailwind(builder, app);" : ""}
492+
${useTailwind ? "tailwind(builder);" : ""}
496493
if (Deno.args.includes("build")) {
497-
await builder.build(app);
494+
await builder.build();
498495
} else {
499-
await builder.listen(app);
496+
await builder.listen(() => import("./main.ts"));
500497
}`;
501498
await writeFile("dev.ts", DEV_TS);
502499

@@ -506,7 +503,7 @@ if (Deno.args.includes("build")) {
506503
check: "deno fmt --check . && deno lint . && deno check",
507504
dev: "deno run -A --watch=static/,routes/ dev.ts",
508505
build: "deno run -A dev.ts build",
509-
start: "deno run -A main.ts",
506+
start: "deno serve -A _fresh/server.js",
510507
update: "deno run -A -r jsr:@fresh/update .",
511508
},
512509
lint: {

init/src/init_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,5 @@ Deno.test("init - errors on missing build cache in prod", async () => {
240240
const { stderr } = getStdOutput(cp);
241241
expect(cp.code).toEqual(1);
242242

243-
expect(stderr).toMatch(/Found 1 islands, but did not/);
243+
expect(stderr).toMatch(/Module not found/);
244244
});

plugin-tailwindcss/src/mod.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import type { Builder } from "fresh/dev";
2-
import type { App } from "fresh";
32
import twPostcss from "@tailwindcss/postcss";
43
import postcss from "postcss";
54
import type { TailwindPluginOptions } from "./types.ts";
65

76
// Re-export types for public API
87
export type { TailwindPluginOptions } from "./types.ts";
98

10-
export function tailwind<T>(
9+
export function tailwind(
1110
builder: Builder,
12-
app: App<T>,
1311
options: TailwindPluginOptions = {},
1412
): void {
1513
const { exclude, ...tailwindOptions } = options;
1614
const instance = postcss(twPostcss({
17-
optimize: app.config.mode === "production",
15+
optimize: builder.config.mode === "production",
1816
...tailwindOptions,
1917
}));
2018

0 commit comments

Comments
 (0)