Skip to content

chore(router): trim dependencies by inlining small single-use helpers - #8975

Open
gioboa wants to merge 1 commit into
QwikDev:mainfrom
gioboa:chore/router-trim-deps
Open

chore(router): trim dependencies by inlining small single-use helpers#8975
gioboa wants to merge 1 commit into
QwikDev:mainfrom
gioboa:chore/router-trim-deps

Conversation

@gioboa

@gioboa gioboa commented Aug 27, 2026

Copy link
Copy Markdown
Member

What

Several dependencies of @qwik.dev/router are used for a single function call. This PR replaces those with ~170 lines of tested, vendored code and removes dead dev-dependencies. It also bumps magic-string to the maintained v1 line.

Result: router goes from 26 → 17 direct dependencies. Every app installs 12 fewer packages and ~3MB less node_modules. No behavior changes, no client-bundle impact.

How

Each removed dependency was used for one small thing. Every vendored helper carries a // Minimal inlined replacement for \`` banner so future changes can be checked against the original package's behavior:

Removed Was used for Replaced by
marked (932KB) parsing menu.md remark-parse, already installed via @mdx-js/mdx
@azure/functions (472KB) 3 type imports minimal vendored types (same public API shape)
github-slugger heading anchor ids slugger.ts (~20 lines + tests)
estree-util-value-to-estree frontmatter → ESTree value-to-estree.ts (~50 lines + tests)
set-cookie-parser one parseString call parse-set-cookie.ts (~50 lines + tests)
hast-util-to-string, hast-util-heading-rank text/heading helpers hast-utils.ts (~20 lines)
kleur 5 color functions in SSG logs ansi-colors.ts (same NO_COLOR/TTY detection)
@types/mdx, mdast-util-mdx unused / type-only removed / moved to devDependencies

magic-string stays (per review) and is updated 0.30.21 → 1.2.3 across the workspace — v1 is the maintained line; its only breaking change is pure ESM, which matches how it's consumed here.

Dev-dependency cleanup: dropped uvu (asserts migrated to vitest), tsm (unused), @types/refractor (empty stub), @types/set-cookie-parser.

Verification

  • ✅ All router and qwik-vite unit tests pass, including 3 new suites for the vendored helpers
  • mdx, menu, ssg-snapshot, and resume e2e pass against a production build.coreSSG HTML output is byte-identical and apps resume correctly, so heading ids, menus, cookies, and manifest injection behave exactly as before
  • tsc.check clean, api.update regenerated, lib build clean, lint.syncpack clean

Kept on purpose

source-map, unified, vfile, unist-util-visit are directly imported but already installed via @mdx-js/mdx — removing them saves nothing and creates phantom deps. magic-string, mlly, yaml, csstype, launch-editor, and the remaining deps are real features, public-API types, or not worth the correctness risk.

Bigger wins (zod+valibot ~4.2MB, refractor+svgo ~4.5MB as optional peers) are possible but breaking — left for a separate discussion.

@gioboa
gioboa requested review from a team as code owners August 27, 2026 19:23
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 766741d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@qwik.dev/router Patch
@qwik.dev/core Patch
eslint-plugin-qwik Patch
@qwik.dev/devtools Patch
@qwik.dev/react Patch
@qwik.dev/utils Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@maiieul maiieul moved this to Waiting For Review in Qwik Development Aug 27, 2026
@gioboa
gioboa force-pushed the chore/router-trim-deps branch 2 times, most recently from a907dfd to 406fb4c Compare August 27, 2026 19:31
@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8975

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8975

@qwik.dev/utils

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/utils@8975

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8975

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8975

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8975

@qwik.dev/devtools

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/devtools@8975

commit: 766741d

@gioboa gioboa changed the title chore(router): drop eight dependencies by inlining small helpers chore(router): trim dependencies by inlining small single-use helpers Aug 27, 2026
@gioboa
gioboa force-pushed the chore/router-trim-deps branch 2 times, most recently from d12e906 to ec9aada Compare August 27, 2026 20:04
@gioboa
gioboa enabled auto-merge August 27, 2026 20:11
@gioboa
gioboa force-pushed the chore/router-trim-deps branch from ec9aada to b5fca24 Compare August 27, 2026 20:24
@gioboa gioboa changed the title chore(router): trim dependencies by inlining small single-use helpers chore: trim router and core dependencies by inlining small single-use helpers Aug 27, 2026

@maiieul maiieul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmm this looks good. Thanks @gioboa! Will make maintaining deps easier for sure 👍 Can you add a small comment on each vendor helper that says which vendor it was copied from? This way it reduces the likelihood for a future PR, especially with AI, to introduce a bug into those.

@gioboa

gioboa commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

Good idea @maiieul 👍

@gioboa
gioboa force-pushed the chore/router-trim-deps branch from b5fca24 to 630ca10 Compare August 28, 2026 17:40

@maiieul maiieul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

magic-string impl says "minimal replacement". Copied source code is good but half baked AI impl is risky. Let's remove it please.

@gioboa gioboa changed the title chore: trim router and core dependencies by inlining small single-use helpers chore(router): trim dependencies by inlining small single-use helpers Aug 29, 2026
@gioboa

gioboa commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

Fair enough 👍 Reverted the custom literal-replace helper — magic-string is back for the manifest injection, bumped to the maintained v1 line (1.2.3, pure-ESM only, no API change). PR description updated accordingly; the rest of the vendored helpers stay as reviewed.

- replace marked with remark-parse (already transitive via @mdx-js/mdx) for menu.md parsing
- inline hast-util-to-string, hast-util-heading-rank, and github-slugger equivalents
- inline set-cookie-parser's parseString in the azure-swa middleware
- vendor minimal Azure Functions v3 structural types, dropping @azure/functions
- inline kleur's ANSI color helpers for SSG logging
- remove unused @types/mdx and @types/set-cookie-parser
@gioboa
gioboa force-pushed the chore/router-trim-deps branch from 630ca10 to 766741d Compare August 29, 2026 19:58
@gioboa
gioboa requested a review from maiieul August 29, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting For Review

Development

Successfully merging this pull request may close these issues.

2 participants