Skip to content

Commit e06f03a

Browse files
fix: add missing compile entry (denoland#3410)
Fixes denoland#3409
1 parent 7ce6aef commit e06f03a

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

docs/latest/deployment/deno-compile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ platform without requiring Deno to be installed.
1111
# Build your app first
1212
$ deno task build
1313
# Generate self-contained executable
14-
deno compile --include static --include _fresh --include deno.json -A my-app _fresh/compiled-entry.js
14+
deno compile --output my-app --include _fresh -A _fresh/compiled-entry.js
1515
```
1616

1717
The compiled entry supports two environment variables out of the box:

docs/latest/examples/migration-guide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ The `createHandler` function was often used to launch Fresh for tests. This can
283283
be now done via vite's `createBuilder` function. See the
284284
[testing page](/docs/testing) for more information.
285285

286+
## `deno compile`
287+
288+
If you're using `deno compile` to generate a binary out of the Fresh app be sure
289+
to [update the command](/docs/deployment/deno-compile) to generate the binary.
290+
286291
## Getting help
287292

288293
If you run into problems with upgrading your app, reach out to us by creating an

packages/fresh/src/dev/dev_build_cache.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,7 @@ export class DiskBuildCache<State> implements DevBuildCache<State> {
381381
}),
382382
);
383383

384-
await Deno.writeTextFile(
385-
path.join(outDir, "compiled-entry.js"),
386-
`import fetcher from "./server.js";
387-
388-
Deno.serve(
389-
{ port: Deno.env.get("PORT"), hostname: Deno.env.get("HOSTNAME") },
390-
fetcher.fetch
391-
);`,
392-
);
384+
await writeCompiledEntry(outDir);
393385
}
394386
}
395387

@@ -425,6 +417,18 @@ export interface PendingStaticFile {
425417
hash: string | null;
426418
}
427419

420+
export async function writeCompiledEntry(outDir: string) {
421+
await Deno.writeTextFile(
422+
path.join(outDir, "compiled-entry.js"),
423+
`import fetcher from "./server.js";
424+
425+
Deno.serve(
426+
{ port: Deno.env.get("PORT"), hostname: Deno.env.get("HOSTNAME") },
427+
fetcher.fetch
428+
);`,
429+
);
430+
}
431+
428432
export async function generateSnapshotServer(
429433
options: {
430434
outDir: string;

packages/fresh/src/internals_dev.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
type IslandModChunk,
88
type PendingStaticFile,
99
prepareStaticFile,
10+
writeCompiledEntry,
1011
} from "./dev/dev_build_cache.ts";
1112
export { specToName } from "./dev/builder.ts";
1213
export { pathToSpec, UniqueNamer } from "./utils.ts";

packages/plugin-vite/src/plugins/server_entry.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
generateServerEntry,
44
type PendingStaticFile,
55
prepareStaticFile,
6+
writeCompiledEntry,
67
} from "fresh/internal-dev";
78
import { pathWithRoot, type ResolvedFreshViteConfig } from "../utils.ts";
89
import * as path from "@std/path";
@@ -154,6 +155,8 @@ export default {
154155
};
155156
`,
156157
);
158+
159+
await writeCompiledEntry(outDir);
157160
},
158161
};
159162
}

packages/plugin-vite/tests/build_test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ Deno.test({
2727
sanitizeResources: false,
2828
});
2929

30+
Deno.test({
31+
name: "vite build - creates compiled entry",
32+
fn: async () => {
33+
const stat = await Deno.stat(
34+
path.join(viteResult.tmp, "_fresh", "compiled-entry.js"),
35+
);
36+
37+
expect(stat.isFile).toEqual(true);
38+
},
39+
sanitizeOps: false,
40+
sanitizeResources: false,
41+
});
42+
3043
Deno.test({
3144
name: "vite build - serves static files",
3245
fn: async () => {

0 commit comments

Comments
 (0)