Skip to content

feat: allow initalizing with "src" dir#3420

Open
csvn wants to merge 1 commit into
freshframework:mainfrom
csvn:feat/init-src-dir
Open

feat: allow initalizing with "src" dir#3420
csvn wants to merge 1 commit into
freshframework:mainfrom
csvn:feat/init-src-dir

Conversation

@csvn
Copy link
Copy Markdown
Contributor

@csvn csvn commented Sep 12, 2025

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, the root property 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-dir option during init such that a project can be initialized with a src dir.

image

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",
Copy link
Copy Markdown
Contributor

@fry69 fry69 Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to put generated artifacts into the src/ folder? Even when those get gitignored, they do not belong there IMHO.

Copy link
Copy Markdown
Contributor

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/

Copy link
Copy Markdown
Contributor

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature! A few things I noticed:

  1. Bug: --watch paths not updated — The dev task generates:

    deno run -A --watch=static/,routes/ src/dev.ts
    

    But 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.

  2. Typo: "initalizing" → "initializing" in use-src-dir.md

  3. check task not updated: deno check might need the src dir path too, depending on how Fresh resolves it.

Copy link
Copy Markdown
Contributor

@lunadogbot lunadogbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants