diff --git a/docs/canary/deployment/deno-compile.md b/docs/canary/deployment/deno-compile.md new file mode 100644 index 00000000..9396bce5 --- /dev/null +++ b/docs/canary/deployment/deno-compile.md @@ -0,0 +1,20 @@ +--- +description: "Generate a self contained executable with deno compile." +--- + +You can create a self-contained executable out of your app with the +[`deno compile` command](https://docs.deno.com/runtime/reference/cli/compile/). +It will include all assets and dependencies. This executable can run on any +platform without requiring Deno to be installed. + +```sh +# Build your app first +$ deno task build +# Generate self-contained executable +deno compile --include static --include _fresh --include deno.json -A my-app _fresh/compiled-entry.js +``` + +The compiled entry supports two environment variables out of the box: + +- `PORT` to set the port number (`PORT=4000 my-app`) +- `HOSTNAME` to set the host name number (`HOSTNAME=0.0.0.0 my-app`) diff --git a/docs/toc.ts b/docs/toc.ts index be3a4bdd..f171a429 100644 --- a/docs/toc.ts +++ b/docs/toc.ts @@ -60,6 +60,7 @@ const toc: RawTableOfContents = { link: "canary", pages: [ ["deno-deploy", "Deno Deploy", "link:canary"], + ["deno-compile", "deno compile", "link:canary"], ["docker", "Docker", "link:canary"], ], }, diff --git a/init/src/init_test.ts b/init/src/init_test.ts index a5260756..e595e09e 100644 --- a/init/src/init_test.ts +++ b/init/src/init_test.ts @@ -181,8 +181,7 @@ Deno.test({ await patchProject(dir); await withChildProcessServer( - dir, - ["task", "dev"], + { cwd: dir, args: ["task", "dev"] }, async (address) => { await withBrowser(async (page) => { await page.goto(address); @@ -215,8 +214,7 @@ Deno.test("init - can start built project", async () => { }).output(); await withChildProcessServer( - dir, - ["task", "start"], + { cwd: dir, args: ["task", "start"] }, async (address) => { await withBrowser(async (page) => { await page.goto(address); diff --git a/src/dev/builder_test.ts b/src/dev/builder_test.ts index c8645666..d76e3d68 100644 --- a/src/dev/builder_test.ts +++ b/src/dev/builder_test.ts @@ -5,7 +5,10 @@ import { App } from "../app.ts"; import { DEV_ERROR_OVERLAY_URL } from "../constants.ts"; import { BUILD_ID } from "../runtime/build_id.ts"; import { withTmpDir, writeFiles } from "../test_utils.ts"; -import { withChildProcessServer } from "../../tests/test_utils.tsx"; +import { + getStdOutput, + withChildProcessServer, +} from "../../tests/test_utils.tsx"; Deno.test({ name: "Builder - chain onTransformStaticFile", @@ -299,8 +302,7 @@ export const app = new App().fsRoutes()`, let text = "fail"; await withChildProcessServer( - tmp, - ["serve", "-A", "dist/server.js"], + { cwd: tmp, args: ["serve", "-A", "dist/server.js"] }, async (address) => { const res = await fetch(`${address}/foo`); text = await res.text(); @@ -340,8 +342,7 @@ export const app = new App().fsRoutes()`, let text = "fail"; await withChildProcessServer( - tmp, - ["serve", "-A", "dist/server.js"], + { cwd: tmp, args: ["serve", "-A", "dist/server.js"] }, async (address) => { const res = await fetch(address); text = await res.text(); @@ -456,8 +457,7 @@ export const app = new App().fsRoutes()`, let text = "fail"; await withChildProcessServer( - tmp, - ["serve", "-A", "dist/server.js"], + { cwd: tmp, args: ["serve", "-A", "dist/server.js"] }, async (address) => { const res = await fetch(address); text = await res.text(); @@ -527,6 +527,85 @@ export const app = new App().fsRoutes()`, sanitizeResources: false, }); +Deno.test({ + name: "Builder - compile entry", + fn: async () => { + const root = path.join(import.meta.dirname!, "..", ".."); + await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); + await using _outDir = await withTmpDir(); + const tmp = _tmp.dir; + + await writeFiles(tmp, { + "deno.json": JSON.stringify({ + links: [path.relative(tmp, root)], + workspace: [], + compilerOptions: { + jsx: "react-jsx", + jsxImportSource: "preact", + }, + imports: { + "fresh": "jsr:@fresh/core@*", + "preact": "npm:preact@*", + "@preact/signals": "npm:@preact/signals@*", + }, + }), + "islands/Foo.tsx": `export const Foo = () =>