Skip to content

refactor: extract template string code generation into entries/ modules#259

Open
yunus25jmi1 wants to merge 1 commit intocloudflare:mainfrom
yunus25jmi1:refactor/extract-entry-templates
Open

refactor: extract template string code generation into entries/ modules#259
yunus25jmi1 wants to merge 1 commit intocloudflare:mainfrom
yunus25jmi1:refactor/extract-entry-templates

Conversation

@yunus25jmi1
Copy link
Contributor

Summary

Extract the 5 template string code generation functions from \index.ts\ and \�pp-dev-server.ts\ into dedicated modules under \packages/vinext/src/entries/.

Changes

New files (\packages/vinext/src/entries/)

File Function Lines
\�pp-rsc-entry.ts\ \generateRscEntry()\ + \AppRouterConfig\ 2135
\�pp-ssr-entry.ts\ \generateSsrEntry()\ 410
\�pp-browser-entry.ts\ \generateBrowserEntry()\ 284
\pages-server-entry.ts\ \generateServerEntry()\ 857
\pages-client-entry.ts\ \generateClientEntry()\ 87

Modified files

  • **\�pp-dev-server.ts**: Replaced 3034 lines with a 12-line re-export barrel (maintains backward API compatibility)
  • **\index.ts**: Removed ~1238 lines of inline generators; imports from \�ntries/\ modules; call sites pass explicit params instead of relying on closure variables

Pages Router closure conversion

\generateServerEntry\ and \generateClientEntry\ were closures inside \�inext()\ that captured \pagesDir,
extConfig, and \middlewarePath. Converted to explicit function parameters.

Tests

  • **\ ests/entry-templates.test.ts**: 9 snapshot tests covering all 5 generators + the re-export barrel

Verification

  • Typecheck: pass
  • Lint: pass
  • Vitest: all tests pass (6 pre-existing failures unrelated to this change)

Closes #253

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@259

commit: 7e5db2b

@yunus25jmi1
Copy link
Contributor Author

@southpolesteve @threepointone @elithrar Kindly review the changes. The workflow is completely green. All checks are passed with 12 successful checks & 3 skipped.

@southpolesteve
Copy link
Collaborator

/bigbonk review please

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 5, 2026

@southpolesteve Bonk workflow was cancelled.

View workflow run · To retry, trigger Bonk again.

@yunus25jmi1 yunus25jmi1 force-pushed the refactor/extract-entry-templates branch 2 times, most recently from 13e1c39 to c9aedba Compare March 6, 2026 17:38
Extract 5 entry template generators from index.ts and app-dev-server.ts
into packages/vinext/src/entries/:

- app-rsc-entry.ts: generateRscEntry() + AppRouterConfig interface
- app-ssr-entry.ts: generateSsrEntry()
- app-browser-entry.ts: generateBrowserEntry()
- pages-server-entry.ts: generateServerEntry() (closure -> explicit params)
- pages-client-entry.ts: generateClientEntry() (closure -> explicit params)

app-dev-server.ts is now a thin re-export barrel (12 lines, was 3034).
index.ts reduced by ~1238 lines (2507, was 3745).

Snapshot tests added in tests/entry-templates.test.ts to guard against
template drift during future refactors.

Closes cloudflare#253
@yunus25jmi1 yunus25jmi1 force-pushed the refactor/extract-entry-templates branch from c9aedba to 1d34026 Compare March 8, 2026 07:43
@yunus25jmi1
Copy link
Contributor Author

@southpolesteve, @james-elicx review the changes.

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.

Refactor: Extract template string code generation from index.ts and app-dev-server.ts into separate modules

2 participants