Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
uses: denoland/setup-deno@v2
with:
cache: true
deno-version: rc

- name: Build step
working-directory: ./www
Expand All @@ -32,5 +31,5 @@ jobs:
uses: denoland/deployctl@v1
with:
project: "fresh"
entrypoint: "./www/main.ts"
entrypoint: "./www/_fresh/server.js"
root: "."
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
".": "./src/mod.ts",
"./runtime": "./src/runtime/shared.ts",
"./dev": "./src/dev/mod.ts",
"./compat": "./src/compat.ts"
"./compat": "./src/compat.ts",
"./do-not-use": "./src/internals.ts"
},
"tasks": {
"test": "deno test -A --parallel",
Expand Down
2 changes: 1 addition & 1 deletion docs/canary/deployment/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To run Fresh in production mode, run the `start` task:
```sh Terminal
deno task start
# or
deno run -A main.ts
deno serve -A _fresh/server.js
```

Fresh will automatically pick up the optimized assets in the `_fresh` directory.
28 changes: 9 additions & 19 deletions docs/canary/examples/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,20 @@ The full `dev.ts` file for newly generated Fresh 2 projects looks like this:
```ts
import { Builder } from "fresh/dev";
import { tailwind } from "@fresh/plugin-tailwind";
import { app } from "./main.ts";

// Pass development only configuration here
const builder = new Builder({ target: "safari12" });

// Example: Enabling the tailwind plugin for Fresh
tailwind(builder, app);
tailwind(builder);

// Create optimized assets for the browser when
// running `deno run -A dev.ts build`
if (Deno.args.includes("build")) {
await builder.build(app);
await builder.build();
} else {
// ...otherwise start the development server
await builder.listen(app);
await builder.listen(() => import("./main.ts"));
}
```

Expand All @@ -82,18 +81,9 @@ import { App, fsRoutes, staticFiles } from "fresh";

export const app = new App()
// Add static file serving middleware
.use(staticFiles());

// Enable file-system based routing
await fsRoutes(app, {
loadIsland: (path) => import(`./islands/${path}`),
loadRoute: (path) => import(`./routes/${path}`),
});

// If this module is called directly, start the server
if (import.meta.main) {
await app.listen();
}
.use(staticFiles())
// Enable file-system based routing
.fsRoutes();
```

## Merging error pages
Expand Down Expand Up @@ -226,9 +216,9 @@ Same is true for handlers:

All the various context interfaces have been consolidated and simplified:

| Fresh 1.x | Fresh 2.x |
| --------------------------------------------- | -------------- |
| `AppContext`, `LayoutContext`, `RouteContext` | `FreshContext` |
| Fresh 1.x | Fresh 2.x |
| --------------------------------------------- | ------------------------------------------ |
| `AppContext`, `LayoutContext`, `RouteContext` | [`Context`](/docs/canary/concepts/context) |

### Context methods

Expand Down
10 changes: 0 additions & 10 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ import { DemoIsland } from "jsr:@fresh/examples/island";
export const app = new App({ root: import.meta.url })
.use(staticFiles());

// Register the island
app.island(
// Module specifier for esbuild, could also be a file path
"jsr:@fresh/examples/island",
// Name of the island
"DemoIsland",
// Island component function
DemoIsland,
);

// Use the island somewhere in your components
app.get("/", (ctx) => ctx.render(<DemoIsland />));

Expand Down
25 changes: 9 additions & 16 deletions init/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ ENV DENO_DEPLOYMENT_ID=\${GIT_REVISION}
WORKDIR /app

COPY . .
RUN deno cache main.ts
RUN deno cache _fresh/server.js

EXPOSE 8000

CMD ["run", "-A", "main.ts"]
CMD ["serve", "-A", "_fresh/server.js"]

`;
await writeFile("Dockerfile", DOCKERFILE_TEXT);
Expand Down Expand Up @@ -349,7 +349,7 @@ ${GRADIENT_CSS}`;
// Skip this and be silent if there is a network issue.
}

const MAIN_TS = `import { App, fsRoutes, staticFiles } from "fresh";
const MAIN_TS = `import { App, staticFiles } from "fresh";
import { define, type State } from "./utils.ts";

export const app = new App<State>();
Expand All @@ -371,14 +371,8 @@ const exampleLoggerMiddleware = define.middleware((ctx) => {
});
app.use(exampleLoggerMiddleware);

await fsRoutes(app, {
loadIsland: (path) => import(\`./islands/\${path}\`),
loadRoute: (path) => import(\`./routes/\${path}\`),
});

if (import.meta.main) {
await app.listen();
}`;
// Include file-system based routes here
app.fsRoutes();`;
await writeFile("main.ts", MAIN_TS);

const COMPONENTS_BUTTON_TSX =
Expand Down Expand Up @@ -489,14 +483,13 @@ export default function Counter(props: CounterProps) {
const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/
${useTailwind ? `import { tailwind } from "@fresh/plugin-tailwind";\n` : ""}
import { Builder } from "fresh/dev";
import { app } from "./main.ts";

const builder = new Builder();
${useTailwind ? "tailwind(builder, app);" : ""}
${useTailwind ? "tailwind(builder);" : ""}
if (Deno.args.includes("build")) {
await builder.build(app);
await builder.build();
} else {
await builder.listen(app);
await builder.listen(() => import("./main.ts"));
}`;
await writeFile("dev.ts", DEV_TS);

Expand All @@ -506,7 +499,7 @@ if (Deno.args.includes("build")) {
check: "deno fmt --check . && deno lint . && deno check",
dev: "deno run -A --watch=static/,routes/ dev.ts",
build: "deno run -A dev.ts build",
start: "deno run -A main.ts",
start: "deno serve -A _fresh/server.js",
update: "deno run -A -r jsr:@fresh/update .",
},
lint: {
Expand Down
43 changes: 23 additions & 20 deletions init/src/init_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,31 @@ Deno.test({
},
});

Deno.test("init with tailwind - fmt, lint, and type check project", async () => {
await using tmp = await withTmpDir();
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm({
[CONFIRM_TAILWIND_MESSAGE]: true,
});
Deno.test(
"init with tailwind - fmt, lint, and type check project",
async () => {
await using tmp = await withTmpDir();
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm({
[CONFIRM_TAILWIND_MESSAGE]: true,
});

await initProject(dir, [], {});
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");
await initProject(dir, [], {});
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");

await patchProject(dir);
await patchProject(dir);

const check = await new Deno.Command(Deno.execPath(), {
args: ["task", "check"],
cwd: dir,
stderr: "inherit",
stdout: "inherit",
}).output();
expect(check.code).toEqual(0);
});
const check = await new Deno.Command(Deno.execPath(), {
args: ["task", "check"],
cwd: dir,
stderr: "inherit",
stdout: "inherit",
}).output();
expect(check.code).toEqual(0);
},
);

Deno.test("init - can start dev server", async () => {
await using tmp = await withTmpDir();
Expand Down Expand Up @@ -240,5 +243,5 @@ Deno.test("init - errors on missing build cache in prod", async () => {
const { stderr } = getStdOutput(cp);
expect(cp.code).toEqual(1);

expect(stderr).toMatch(/Found 1 islands, but did not/);
expect(stderr).toMatch(/Module not found/);
});
6 changes: 2 additions & 4 deletions plugin-tailwindcss/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import type { Builder } from "fresh/dev";
import type { App } from "fresh";
import twPostcss from "@tailwindcss/postcss";
import postcss from "postcss";
import type { TailwindPluginOptions } from "./types.ts";

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

export function tailwind<T>(
export function tailwind(
builder: Builder,
app: App<T>,
options: TailwindPluginOptions = {},
): void {
const { exclude, ...tailwindOptions } = options;
const instance = postcss(twPostcss({
optimize: app.config.mode === "production",
optimize: builder.config.mode === "production",
...tailwindOptions,
}));

Expand Down
Loading
Loading