Commit 3a60751
authored
refactor(bundler)!: named Unhead export, ctx-based transforms, dev-mode validate (#733)
* refactor(bundler): named Unhead export, ctx-based transforms, dev-mode validate
Foundational changes that landed alongside the in-progress devtools work.
Splits the bundler refactor + DX improvements out from the devtools branch
so they can be reviewed and merged independently.
## Bundler
- BREAKING: `default` export → named `Unhead` export on `@unhead/bundler/{vite,webpack}`
and on every framework wrapper (`@unhead/{react,solid-js,svelte,vue}/vite`).
Existing imports must change from `import unhead from ...` to
`import { Unhead } from ...`.
- New `VitePluginOptions` interface (extends `UnpluginOptions`) with a
`validate` flag that injects `ValidatePlugin` in dev so head-tag warnings
surface in the console without manual setup. Internal `_framework` field
lets framework wrappers identify themselves to the runtime.
- New `CreateHeadTransform` + `createHeadTransformContext` foundation: a
single transform handles `createHead()` wrapping and lets other plugins
register runtime plugins via shared context.
- New `SSRStaticReplace` transform: replaces `head.ssr` with a static
boolean per environment so the dead branch tree-shakes cleanly.
- `UseSeoMetaTransform` now preserves the second argument (e.g.
`useSeoMeta(meta, { head })`) when rewriting to `useHead`.
- Tests: `createHeadTransform.test.ts` and updated `useSeoMetaTransform.test.ts`.
## Framework wrappers
- Vue / React / Solid / Svelte vite plugins updated for the named export
and forward `_framework` so the bundler can resolve framework-scoped
runtime plugins (`@unhead/vue/plugins`, etc.).
- `packages-aliased/addons` deprecation shim re-exports the new named export.
## Vue
- Re-exports `useServerHead`, `useServerHeadSafe`, `useServerSeoMeta` as
deprecated aliases for the non-`Server` variants (v2 compat).
- Re-exports `resolveUnrefHeadInput` from `utils` (v2 compat).
## Schema.org
- Exports `schemaAutoImports` from the package root so consumers can wire
it into `unplugin-auto-import` without reaching into subpaths.
## Docs
- Reorganises `1.guides/2.advanced/{vite-plugin,client-only-tags,extending-unhead}`
into a new `1.guides/build-plugins/` section: overview, tree-shaking,
seo-meta-transform, minify-transform.
- Migration guide moves out of `content/` to top-level `6.migration-guide/`.
- Adds `7.api/plugins.md` and updates `use-head` / `use-seo-meta` API pages.
## Examples
- `vite-ssr-vue-prerender`: switches to the named `Unhead` import.
* chore: dedupe pnpm lockfile to fix vite peer-dep duplication
Two [email protected] instances were resolved due to a peer-dep variation on
the bundler package's optional `esbuild` peer, causing TS to see two
incompatible Plugin types in the new bundler transforms. `pnpm update &&
pnpm dedupe` collapses them onto a single resolution and bumps vitest to
4.1.4.
* fix(bundler): scope createHead matching and restore SSR transform
Addresses CodeRabbit review feedback on #733.
- SSRStaticReplace: vite.apply now returns true so the plugin actually
runs during SSR builds (returning false disabled it entirely, so the
head.ssr static replacement never happened)
- CreateHeadTransform: scope createHead callsite matching to symbols
imported from unhead/@unhead modules; supports named, aliased, and
namespace imports; ignores shadowed locals and unrelated packages
- Tests: cover false-positive cases (non-Unhead packages, shadowed
locals) plus aliased and namespace imports
- Docs: rename unhead({...}) -> Unhead({...}) in build-plugins examples,
drop undocumented devtools option from overview, fix head.resolveTags()
to resolveTags(head) in plugins API page
- Migration guide: restore v3 content (was emptied in 66c387c) and add
@unhead/addons -> @unhead/bundler rename + named Unhead export sections
* docs: address coderabbit nits on v3 migration and plugins API
- v3.md: add blank line before ::tip closing marker (markdownlint MD031)
- plugins.md: hyphenate "hooks-based" compound adjective1 parent 9c83934 commit 3a60751
61 files changed
Lines changed: 3183 additions & 2916 deletions
File tree
- docs
- 0.angular/schema-org/guides/get-started
- 0.react/schema-org/guides/get-started
- 0.solid-js/schema-org/guides/get-started
- 0.svelte/schema-org/guides/get-started
- 0.typescript
- head/guides/0.get-started
- schema-org/guides/get-started
- 0.vue/schema-org/guides/0.get-started
- 6.migration-guide
- content/7.releases
- head
- 1.guides
- 0.get-started
- 1.core-concepts
- 2.advanced
- build-plugins
- plugins
- 7.api
- 0.get-started
- composables
- examples/vite-ssr-vue-prerender
- packages-aliased/addons/src
- packages
- bundler
- src/unplugin
- test
- react/src
- schema-org/src
- solid-js/src
- svelte/src
- vue/src
- test/exports
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
Whitespace-only changes.
Lines changed: 94 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
44 | 132 | | |
45 | 133 | | |
46 | 134 | | |
| |||
401 | 489 | | |
402 | 490 | | |
403 | 491 | | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
404 | 498 | | |
405 | 499 | | |
406 | 500 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
0 commit comments