feat: allow initalizing with "src" dir#3420
Conversation
| 3. Update the `"start"` task in `deno.json` to the new `_fresh` location | ||
| ```diff | ||
| - "start": "deno serve -A _fresh/server.js", | ||
| + "start": "deno serve -A src/_fresh/server.js", |
There was a problem hiding this comment.
Is it a good idea to put generated artifacts into the src/ folder? Even when those get gitignored, they do not belong there IMHO.
marvinhagemeister
left a comment
There was a problem hiding this comment.
I like this a lot! Wondering if we can find a way to put the _fresh directory at the top. It feels wrong to put it into src/
bartlomieju
left a comment
There was a problem hiding this comment.
Nice feature! A few things I noticed:
-
Bug:
--watchpaths not updated — Thedevtask generates:deno run -A --watch=static/,routes/ src/dev.tsBut with a src dir, the watched paths should be
src/static/,src/routes/(or relative from the src dir), otherwise file watching won't work. -
Typo: "initalizing" → "initializing" in
use-src-dir.md -
checktask not updated:deno checkmight need the src dir path too, depending on how Fresh resolves it.
lunadogbot
left a comment
There was a problem hiding this comment.
The ubuntu-only CI failure is the typos check (.github/workflows/ci.yml runs crate-ci/typos only on ubuntu + v2.x) — "initalizing" appears in the PR title, in docs/latest/examples/use-src-dir.md:6, and in the --src-dir block of HELP_TEXT at packages/init/src/init.ts:65 if the help text is exercised. Fixing the spelling everywhere should turn that job green and resolves @bartlomieju's earlier typo nit.
Also worth a heads-up before rebasing: packages/init/src/init.ts on main moved nodeModulesDir from "auto" → "manual" after this branch was cut. The PR still writes "auto" at init.ts:576. Naive conflict resolution would silently revert main's change — preserve "manual" on rebase.
The --watch=static/,routes/ concern from the prior review is moot since --src-dir is Vite-only and Vite overrides dev/build to vite/vite build a few lines later.
- nit:
viteConfig += \root: "${src.slice(0, -1)}",\n`doesn't escape —--src-dir='a"b'produces invalid TS.JSON.stringify(src.slice(0, -1))` is the one-liner fix.
Holding approval until CI is green.
I have existing v1 Fresh projects that I was planning to upgrade to v2. But I was unsure about how to migrate, since I was using a
src/folder. By reading the source code, I found that with Vite, therootproperty can be used to select the root folder for all code.This PR re-introduces the docs example for how to use a "src" folder from Fresh v1, but also adds a
--src-diroption during init such that a project can be initialized with asrcdir.