From 99eb5435bbac3c94a78f7d8866b8810e9a938673 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 29 Dec 2023 20:47:15 +1100 Subject: [PATCH] refactor: use `--env` CLI arg (#2204) This change replaces the use of the Standard Library's `dotenv.load()` with the native `--env` CLI flag. The benefits include: * One less dependency * More obvious consumption of the `.env` file in the CLI output --- demo/deno.json | 2 +- docs/latest/examples/changing-the-src-dir.md | 4 ++-- docs/latest/examples/using-twind-v1.md | 2 -- init.ts | 6 +----- tests/fixture_base_path/deno.json | 2 +- tests/fixture_island_nesting/deno.json | 2 +- tests/fixture_partials/deno.json | 2 +- tests/fixture_route_analysis/deno.json | 2 +- tests/fixture_route_analysis/main.ts | 2 -- tests/fixture_server_components/deno.json | 2 +- tests/fixture_twind_app/deno.json | 2 +- tests/fixture_twind_hydrate/deno.json | 2 +- tests/init_test.ts | 4 ++-- www/deno.json | 2 +- 14 files changed, 14 insertions(+), 22 deletions(-) diff --git a/demo/deno.json b/demo/deno.json index bb206679..2968f465 100644 --- a/demo/deno.json +++ b/demo/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../", diff --git a/docs/latest/examples/changing-the-src-dir.md b/docs/latest/examples/changing-the-src-dir.md index a85dea6e..0f7160b2 100644 --- a/docs/latest/examples/changing-the-src-dir.md +++ b/docs/latest/examples/changing-the-src-dir.md @@ -44,8 +44,8 @@ Here's what the diff of `deno.json` looks like: { "lock": false, "tasks": { -- "start": "deno run -A --watch=static/,routes/ dev.ts" -+ "start": "deno run -A --watch=src/static/,src/routes/ src/dev.ts" +- "start": "deno run -A --watch=static/,routes/ --env dev.ts" ++ "start": "deno run -A --watch=src/static/,src/routes/ --env src/dev.ts" }, "imports": { "$fresh/": "file:///Users/reed/code/fresh/", diff --git a/docs/latest/examples/using-twind-v1.md b/docs/latest/examples/using-twind-v1.md index 2aad8898..fbe1722a 100644 --- a/docs/latest/examples/using-twind-v1.md +++ b/docs/latest/examples/using-twind-v1.md @@ -13,8 +13,6 @@ you'll end up with a `main.ts` like the following: /// /// -import "$std/dotenv/load.ts"; - import { start } from "$fresh/server.ts"; import manifest from "./fresh.gen.ts"; import config from "./fresh.config.ts"; diff --git a/init.ts b/init.ts index 56035e96..1c10160b 100644 --- a/init.ts +++ b/init.ts @@ -523,8 +523,6 @@ let MAIN_TS = `/// /// /// -import "$std/dotenv/load.ts"; - import { start } from "$fresh/server.ts"; import manifest from "./fresh.gen.ts"; import config from "./fresh.config.ts"; @@ -540,8 +538,6 @@ const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/ import dev from "$fresh/dev.ts"; import config from "./fresh.config.ts"; -import "$std/dotenv/load.ts"; - await dev(import.meta.url, "./main.ts", config); `; const DEV_TS_PATH = join(resolvedDirectory, "dev.ts"); @@ -559,7 +555,7 @@ const config = { "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", cli: "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -", manifest: "deno task cli manifest $(pwd)", - start: "deno run -A --watch=static/,routes/ dev.ts", + start: "deno run -A --watch=static/,routes/ --env dev.ts", build: "deno run -A dev.ts build", preview: "deno run -A main.ts", update: "deno run -A -r https://fresh.deno.dev/update .", diff --git a/tests/fixture_base_path/deno.json b/tests/fixture_base_path/deno.json index 7802f6a0..a70ad781 100644 --- a/tests/fixture_base_path/deno.json +++ b/tests/fixture_base_path/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../../", diff --git a/tests/fixture_island_nesting/deno.json b/tests/fixture_island_nesting/deno.json index 752aae1f..583ebf6e 100644 --- a/tests/fixture_island_nesting/deno.json +++ b/tests/fixture_island_nesting/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../../", diff --git a/tests/fixture_partials/deno.json b/tests/fixture_partials/deno.json index c4df0177..13762141 100644 --- a/tests/fixture_partials/deno.json +++ b/tests/fixture_partials/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../../", diff --git a/tests/fixture_route_analysis/deno.json b/tests/fixture_route_analysis/deno.json index 4ec11b09..a5043503 100644 --- a/tests/fixture_route_analysis/deno.json +++ b/tests/fixture_route_analysis/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts", + "start": "deno run -A --watch=static/,routes/ --env dev.ts", "update": "deno run -A -r https://fresh.deno.dev/update ." }, "imports": { diff --git a/tests/fixture_route_analysis/main.ts b/tests/fixture_route_analysis/main.ts index 8ef5d924..dedce9cb 100644 --- a/tests/fixture_route_analysis/main.ts +++ b/tests/fixture_route_analysis/main.ts @@ -4,8 +4,6 @@ /// /// -import "$std/dotenv/load.ts"; - import { start } from "$fresh/server.ts"; import manifest from "./fresh.gen.ts"; diff --git a/tests/fixture_server_components/deno.json b/tests/fixture_server_components/deno.json index 6f39b459..ee5b70cb 100644 --- a/tests/fixture_server_components/deno.json +++ b/tests/fixture_server_components/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../../", diff --git a/tests/fixture_twind_app/deno.json b/tests/fixture_twind_app/deno.json index 6f39b459..ee5b70cb 100644 --- a/tests/fixture_twind_app/deno.json +++ b/tests/fixture_twind_app/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../../", diff --git a/tests/fixture_twind_hydrate/deno.json b/tests/fixture_twind_hydrate/deno.json index 81c87e73..d01fbf1a 100644 --- a/tests/fixture_twind_hydrate/deno.json +++ b/tests/fixture_twind_hydrate/deno.json @@ -1,7 +1,7 @@ { "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/ dev.ts" + "start": "deno run -A --watch=static/,routes/ --env dev.ts" }, "imports": { "$fresh/": "../../", diff --git a/tests/init_test.ts b/tests/init_test.ts index 4b6f9be0..bf0be9b0 100644 --- a/tests/init_test.ts +++ b/tests/init_test.ts @@ -406,7 +406,7 @@ Deno.test({ await t.step("start up the server", async () => { const { serverProcess, lines, address } = await startFreshServer({ - args: ["run", "-A", "--no-check", "dev.ts"], + args: ["run", "-A", "--no-check", "--env", "dev.ts"], cwd: tmpDirName, }); @@ -433,7 +433,7 @@ Deno.test({ }).output(); const { serverProcess, lines, address, output } = await startFreshServer({ - args: ["run", "-A", "--no-check", "main.ts"], + args: ["run", "-A", "--no-check", "--env", "main.ts"], cwd: tmpDirName, }); diff --git a/www/deno.json b/www/deno.json index 0a2b7cf6..309b1632 100644 --- a/www/deno.json +++ b/www/deno.json @@ -2,7 +2,7 @@ "lock": false, "nodeModulesDir": true, "tasks": { - "start": "deno run -A --watch=static/,routes/,../src,../docs dev.ts", + "start": "deno run -A --watch=static/,routes/,../src,../docs --env dev.ts", "build": "deno run -A dev.ts build", "preview": "deno run -A main.ts" },