@unhead/svelte 3.0.5 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import * as _unhead_bundler_framework from '@unhead/bundler/framework';
2
+ import { UnheadFrameworkOptions } from '@unhead/bundler/framework';
3
+ import { U as UnheadSvelteStreamingOptions } from './shared/svelte.CcJ2UT7H.mjs';
4
+ import 'unplugin';
5
+ import 'unhead/stream/unplugin';
6
+
7
+ type UnheadSvelteOptions = UnheadFrameworkOptions<UnheadSvelteStreamingOptions>;
8
+ /**
9
+ * Unified bundler plugin factory for `@unhead/svelte`. Returns an object
10
+ * with per-bundler dispatch methods (`vite`, `webpack`, `rspack`, `rollup`).
11
+ */
12
+ declare const Unhead: (options?: UnheadFrameworkOptions<UnheadSvelteStreamingOptions>) => _unhead_bundler_framework.UnheadBundlerFactory;
13
+
14
+ export { Unhead };
15
+ export type { UnheadSvelteOptions };
@@ -0,0 +1,15 @@
1
+ import * as _unhead_bundler_framework from '@unhead/bundler/framework';
2
+ import { UnheadFrameworkOptions } from '@unhead/bundler/framework';
3
+ import { U as UnheadSvelteStreamingOptions } from './shared/svelte.CcJ2UT7H.js';
4
+ import 'unplugin';
5
+ import 'unhead/stream/unplugin';
6
+
7
+ type UnheadSvelteOptions = UnheadFrameworkOptions<UnheadSvelteStreamingOptions>;
8
+ /**
9
+ * Unified bundler plugin factory for `@unhead/svelte`. Returns an object
10
+ * with per-bundler dispatch methods (`vite`, `webpack`, `rspack`, `rollup`).
11
+ */
12
+ declare const Unhead: (options?: UnheadFrameworkOptions<UnheadSvelteStreamingOptions>) => _unhead_bundler_framework.UnheadBundlerFactory;
13
+
14
+ export { Unhead };
15
+ export type { UnheadSvelteOptions };
@@ -0,0 +1,13 @@
1
+ import { createFrameworkPlugin } from '@unhead/bundler/framework';
2
+ import { u as unheadSvelteStreamingPlugin } from './shared/svelte.DyNDxHAA.mjs';
3
+ import 'magic-string';
4
+ import 'oxc-walker';
5
+ import 'unhead/stream/unplugin';
6
+ import 'unplugin';
7
+
8
+ const Unhead = createFrameworkPlugin({
9
+ framework: "@unhead/svelte",
10
+ streamingPlugin: unheadSvelteStreamingPlugin
11
+ });
12
+
13
+ export { Unhead };
@@ -0,0 +1,8 @@
1
+ import * as unplugin from 'unplugin';
2
+ import { StreamingPluginOptions } from 'unhead/stream/unplugin';
3
+
4
+ type UnheadSvelteStreamingOptions = Pick<StreamingPluginOptions, 'mode'>;
5
+ declare const unheadSvelteStreamingPlugin: unplugin.UnpluginInstance<UnheadSvelteStreamingOptions | undefined, boolean>;
6
+
7
+ export { unheadSvelteStreamingPlugin as u };
8
+ export type { UnheadSvelteStreamingOptions as U };
@@ -0,0 +1,8 @@
1
+ import * as unplugin from 'unplugin';
2
+ import { StreamingPluginOptions } from 'unhead/stream/unplugin';
3
+
4
+ type UnheadSvelteStreamingOptions = Pick<StreamingPluginOptions, 'mode'>;
5
+ declare const unheadSvelteStreamingPlugin: unplugin.UnpluginInstance<UnheadSvelteStreamingOptions | undefined, boolean>;
6
+
7
+ export { unheadSvelteStreamingPlugin as u };
8
+ export type { UnheadSvelteStreamingOptions as U };
@@ -0,0 +1,70 @@
1
+ import MagicString from 'magic-string';
2
+ import { parseAndWalk } from 'oxc-walker';
3
+ import { buildStreamingPluginOptions } from 'unhead/stream/unplugin';
4
+ import { createUnplugin } from 'unplugin';
5
+
6
+ const SCRIPT_CLOSE_RE = /<\/script>/;
7
+ const SCRIPT_RE = /<script[^>]*>/i;
8
+ const FILTER_RE = /\.svelte$/;
9
+ function transform(code, id, isSSR, s) {
10
+ if (!code.includes("useHead") && !code.includes("useSeoMeta") && !code.includes("useHeadSafe"))
11
+ return false;
12
+ const scriptCloseMatch = code.match(SCRIPT_CLOSE_RE);
13
+ if (!scriptCloseMatch)
14
+ return false;
15
+ const templateStart = scriptCloseMatch.index + scriptCloseMatch[0].length;
16
+ s.appendRight(templateStart, "\n{@html HeadStream()}");
17
+ const importPath = `@unhead/svelte/stream/${isSSR ? "server" : "client"}`;
18
+ const scriptMatch = code.match(SCRIPT_RE);
19
+ if (!scriptMatch)
20
+ return true;
21
+ const scriptEnd = scriptMatch.index + scriptMatch[0].length;
22
+ const scriptCloseIndex = code.indexOf("<\/script>", scriptEnd);
23
+ if (scriptCloseIndex === -1)
24
+ return true;
25
+ const scriptContent = code.slice(scriptEnd, scriptCloseIndex);
26
+ let existingImport = null;
27
+ parseAndWalk(scriptContent, id, {
28
+ parseOptions: { lang: "ts" },
29
+ enter(node) {
30
+ if (node.type === "ImportDeclaration" && node.source.value === importPath) {
31
+ existingImport = {
32
+ start: scriptEnd + node.start,
33
+ end: scriptEnd + node.end,
34
+ specifiers: node.specifiers?.map((spec) => spec.local?.name).filter(Boolean) || []
35
+ };
36
+ this.skip();
37
+ }
38
+ }
39
+ });
40
+ const foundImport = existingImport;
41
+ if (foundImport) {
42
+ if (!foundImport.specifiers.includes("HeadStream")) {
43
+ const inner = foundImport.specifiers.join(", ");
44
+ const newImports = inner ? `${inner}, HeadStream` : "HeadStream";
45
+ s.overwrite(foundImport.start, foundImport.end, `import { ${newImports} } from '${importPath}'`);
46
+ }
47
+ } else {
48
+ s.appendRight(scriptEnd, `
49
+ import { HeadStream } from '${importPath}'`);
50
+ }
51
+ return true;
52
+ }
53
+ const unheadSvelteStreamingPlugin = createUnplugin(
54
+ (options = {}) => buildStreamingPluginOptions({
55
+ framework: "@unhead/svelte",
56
+ filter: FILTER_RE,
57
+ mode: options.mode,
58
+ transform(code, id, opts) {
59
+ const s = new MagicString(code);
60
+ if (!transform(code, id, opts?.ssr ?? false, s))
61
+ return null;
62
+ return {
63
+ code: s.toString(),
64
+ map: s.generateMap({ includeContent: true, source: id })
65
+ };
66
+ }
67
+ })
68
+ );
69
+
70
+ export { unheadSvelteStreamingPlugin as u };
@@ -1,27 +1,14 @@
1
- import * as vite from 'vite';
2
- import { StreamingPluginOptions } from 'unhead/stream/vite';
1
+ import { Plugin } from 'vite';
2
+ import { U as UnheadSvelteStreamingOptions } from '../shared/svelte.CcJ2UT7H.mjs';
3
+ export { u as unheadSvelteStreamingPlugin } from '../shared/svelte.CcJ2UT7H.mjs';
4
+ import 'unplugin';
5
+ import 'unhead/stream/unplugin';
3
6
 
4
7
  /**
5
- * Vite plugin for Svelte streaming SSR support.
6
- * Automatically injects HeadStream into Svelte components.
7
- *
8
- * @returns Vite plugin configuration object with:
9
- * - `name`: Plugin identifier
10
- * - `enforce`: Plugin execution order ('pre')
11
- * - `transform`: Transform hook for processing .svelte files
12
- *
13
- * @example
14
- * ```ts
15
- * // vite.config.ts
16
- * import { unheadSveltePlugin } from '@unhead/svelte/stream/vite'
17
- *
18
- * export default {
19
- * plugins: [
20
- * unheadSveltePlugin()
21
- * ]
22
- * }
23
- * ```
8
+ * @deprecated Use `Unhead({ streaming: true }).vite()` from `@unhead/svelte/bundler` instead.
9
+ * The `@unhead/svelte/stream/vite` subpath and `unheadSveltePlugin` export will be
10
+ * removed in a future major release.
24
11
  */
25
- declare function unheadSveltePlugin(options?: Pick<StreamingPluginOptions, 'mode'>): vite.Plugin<any>;
12
+ declare function unheadSveltePlugin(options?: UnheadSvelteStreamingOptions): Plugin;
26
13
 
27
- export { unheadSveltePlugin as default, unheadSveltePlugin };
14
+ export { UnheadSvelteStreamingOptions, unheadSveltePlugin as default, unheadSveltePlugin };
@@ -1,27 +1,14 @@
1
- import * as vite from 'vite';
2
- import { StreamingPluginOptions } from 'unhead/stream/vite';
1
+ import { Plugin } from 'vite';
2
+ import { U as UnheadSvelteStreamingOptions } from '../shared/svelte.CcJ2UT7H.js';
3
+ export { u as unheadSvelteStreamingPlugin } from '../shared/svelte.CcJ2UT7H.js';
4
+ import 'unplugin';
5
+ import 'unhead/stream/unplugin';
3
6
 
4
7
  /**
5
- * Vite plugin for Svelte streaming SSR support.
6
- * Automatically injects HeadStream into Svelte components.
7
- *
8
- * @returns Vite plugin configuration object with:
9
- * - `name`: Plugin identifier
10
- * - `enforce`: Plugin execution order ('pre')
11
- * - `transform`: Transform hook for processing .svelte files
12
- *
13
- * @example
14
- * ```ts
15
- * // vite.config.ts
16
- * import { unheadSveltePlugin } from '@unhead/svelte/stream/vite'
17
- *
18
- * export default {
19
- * plugins: [
20
- * unheadSveltePlugin()
21
- * ]
22
- * }
23
- * ```
8
+ * @deprecated Use `Unhead({ streaming: true }).vite()` from `@unhead/svelte/bundler` instead.
9
+ * The `@unhead/svelte/stream/vite` subpath and `unheadSveltePlugin` export will be
10
+ * removed in a future major release.
24
11
  */
25
- declare function unheadSveltePlugin(options?: Pick<StreamingPluginOptions, 'mode'>): vite.Plugin<any>;
12
+ declare function unheadSveltePlugin(options?: UnheadSvelteStreamingOptions): Plugin;
26
13
 
27
- export { unheadSveltePlugin as default, unheadSveltePlugin };
14
+ export { UnheadSvelteStreamingOptions, unheadSveltePlugin as default, unheadSveltePlugin };
@@ -1,69 +1,11 @@
1
- import MagicString from 'magic-string';
2
- import { parseAndWalk } from 'oxc-walker';
3
- import { createStreamingPlugin } from 'unhead/stream/vite';
1
+ import { u as unheadSvelteStreamingPlugin } from '../shared/svelte.DyNDxHAA.mjs';
2
+ import 'magic-string';
3
+ import 'oxc-walker';
4
+ import 'unhead/stream/unplugin';
5
+ import 'unplugin';
4
6
 
5
- const SCRIPT_CLOSE_RE = /<\/script>/;
6
- const SCRIPT_RE = /<script[^>]*>/i;
7
- const FILTER_RE = /\.svelte$/;
8
- function transform(code, id, isSSR, s) {
9
- if (!code.includes("useHead") && !code.includes("useSeoMeta") && !code.includes("useHeadSafe"))
10
- return false;
11
- const scriptCloseMatch = code.match(SCRIPT_CLOSE_RE);
12
- if (!scriptCloseMatch)
13
- return false;
14
- const templateStart = scriptCloseMatch.index + scriptCloseMatch[0].length;
15
- s.appendRight(templateStart, "\n{@html HeadStream()}");
16
- const importPath = `@unhead/svelte/stream/${isSSR ? "server" : "client"}`;
17
- const scriptMatch = code.match(SCRIPT_RE);
18
- if (!scriptMatch)
19
- return true;
20
- const scriptEnd = scriptMatch.index + scriptMatch[0].length;
21
- const scriptCloseIndex = code.indexOf("<\/script>", scriptEnd);
22
- if (scriptCloseIndex === -1)
23
- return true;
24
- const scriptContent = code.slice(scriptEnd, scriptCloseIndex);
25
- let existingImport = null;
26
- parseAndWalk(scriptContent, id, {
27
- parseOptions: { lang: "ts" },
28
- enter(node) {
29
- if (node.type === "ImportDeclaration" && node.source.value === importPath) {
30
- existingImport = {
31
- start: scriptEnd + node.start,
32
- end: scriptEnd + node.end,
33
- specifiers: node.specifiers?.map((spec) => spec.local?.name).filter(Boolean) || []
34
- };
35
- this.skip();
36
- }
37
- }
38
- });
39
- const foundImport = existingImport;
40
- if (foundImport) {
41
- if (!foundImport.specifiers.includes("HeadStream")) {
42
- const inner = foundImport.specifiers.join(", ");
43
- const newImports = inner ? `${inner}, HeadStream` : "HeadStream";
44
- s.overwrite(foundImport.start, foundImport.end, `import { ${newImports} } from '${importPath}'`);
45
- }
46
- } else {
47
- s.appendRight(scriptEnd, `
48
- import { HeadStream } from '${importPath}'`);
49
- }
50
- return true;
51
- }
52
7
  function unheadSveltePlugin(options) {
53
- return createStreamingPlugin({
54
- framework: "@unhead/svelte",
55
- filter: FILTER_RE,
56
- mode: options?.mode,
57
- transform(code, id, opts) {
58
- const s = new MagicString(code);
59
- if (!transform(code, id, opts?.ssr ?? false, s))
60
- return null;
61
- return {
62
- code: s.toString(),
63
- map: s.generateMap({ includeContent: true, source: id })
64
- };
65
- }
66
- });
8
+ return unheadSvelteStreamingPlugin.vite(options);
67
9
  }
68
10
 
69
- export { unheadSveltePlugin as default, unheadSveltePlugin };
11
+ export { unheadSveltePlugin as default, unheadSveltePlugin, unheadSvelteStreamingPlugin };
package/dist/vite.d.mts CHANGED
@@ -1,33 +1,17 @@
1
- import { VitePluginOptions } from '@unhead/bundler/vite';
2
- import { StreamingPluginOptions } from 'unhead/stream/vite';
3
1
  import { Plugin } from 'vite';
2
+ import { UnheadSvelteOptions } from './bundler.mjs';
3
+ import '@unhead/bundler/framework';
4
+ import './shared/svelte.CcJ2UT7H.mjs';
5
+ import 'unplugin';
6
+ import 'unhead/stream/unplugin';
4
7
 
5
- interface UnheadSvelteViteOptions extends VitePluginOptions {
6
- /**
7
- * Enable streaming SSR support.
8
- * Set to `true` or a config object to enable.
9
- * @default false
10
- */
11
- streaming?: true | Pick<StreamingPluginOptions, 'mode'> | false;
12
- }
8
+ type UnheadSvelteViteOptions = UnheadSvelteOptions;
13
9
  /**
14
- * Unified Vite plugin for `@unhead/svelte`.
15
- *
16
- * Combines build optimizations (tree-shaking, useSeoMeta transform, minification)
17
- * with streaming SSR support into a single plugin.
18
- *
19
- * @example
20
- * ```ts
21
- * // vite.config.ts
22
- * import { svelte } from '@sveltejs/vite-plugin-svelte'
23
- * import { Unhead } from '@unhead/svelte/vite'
24
- *
25
- * export default defineConfig({
26
- * plugins: [Unhead(), svelte()],
27
- * })
28
- * ```
10
+ * Vite plugin for `@unhead/svelte`. Kept for backwards compatibility;
11
+ * prefer the unified `@unhead/svelte/bundler` entry which dispatches to
12
+ * all bundlers.
29
13
  */
30
- declare function Unhead(options?: UnheadSvelteViteOptions): Plugin[];
14
+ declare function Unhead(options?: UnheadSvelteOptions): Plugin[];
31
15
 
32
16
  export { Unhead };
33
17
  export type { UnheadSvelteViteOptions };
package/dist/vite.d.ts CHANGED
@@ -1,33 +1,17 @@
1
- import { VitePluginOptions } from '@unhead/bundler/vite';
2
- import { StreamingPluginOptions } from 'unhead/stream/vite';
3
1
  import { Plugin } from 'vite';
2
+ import { UnheadSvelteOptions } from './bundler.js';
3
+ import '@unhead/bundler/framework';
4
+ import './shared/svelte.CcJ2UT7H.js';
5
+ import 'unplugin';
6
+ import 'unhead/stream/unplugin';
4
7
 
5
- interface UnheadSvelteViteOptions extends VitePluginOptions {
6
- /**
7
- * Enable streaming SSR support.
8
- * Set to `true` or a config object to enable.
9
- * @default false
10
- */
11
- streaming?: true | Pick<StreamingPluginOptions, 'mode'> | false;
12
- }
8
+ type UnheadSvelteViteOptions = UnheadSvelteOptions;
13
9
  /**
14
- * Unified Vite plugin for `@unhead/svelte`.
15
- *
16
- * Combines build optimizations (tree-shaking, useSeoMeta transform, minification)
17
- * with streaming SSR support into a single plugin.
18
- *
19
- * @example
20
- * ```ts
21
- * // vite.config.ts
22
- * import { svelte } from '@sveltejs/vite-plugin-svelte'
23
- * import { Unhead } from '@unhead/svelte/vite'
24
- *
25
- * export default defineConfig({
26
- * plugins: [Unhead(), svelte()],
27
- * })
28
- * ```
10
+ * Vite plugin for `@unhead/svelte`. Kept for backwards compatibility;
11
+ * prefer the unified `@unhead/svelte/bundler` entry which dispatches to
12
+ * all bundlers.
29
13
  */
30
- declare function Unhead(options?: UnheadSvelteViteOptions): Plugin[];
14
+ declare function Unhead(options?: UnheadSvelteOptions): Plugin[];
31
15
 
32
16
  export { Unhead };
33
17
  export type { UnheadSvelteViteOptions };
package/dist/vite.mjs CHANGED
@@ -1,16 +1,13 @@
1
- import { Unhead as Unhead$1 } from '@unhead/bundler/vite';
2
- import unheadSveltePlugin from './stream/vite.mjs';
1
+ import { Unhead as Unhead$1 } from './bundler.mjs';
2
+ import '@unhead/bundler/framework';
3
+ import './shared/svelte.DyNDxHAA.mjs';
3
4
  import 'magic-string';
4
5
  import 'oxc-walker';
5
- import 'unhead/stream/vite';
6
+ import 'unhead/stream/unplugin';
7
+ import 'unplugin';
6
8
 
7
9
  function Unhead(options = {}) {
8
- const plugins = [...Unhead$1({ ...options, _framework: "@unhead/svelte" })];
9
- if (options.streaming) {
10
- const streamingOpts = typeof options.streaming === "object" ? options.streaming : void 0;
11
- plugins.push(unheadSveltePlugin(streamingOpts));
12
- }
13
- return plugins;
10
+ return Unhead$1(options).vite();
14
11
  }
15
12
 
16
13
  export { Unhead };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/svelte",
3
3
  "type": "module",
4
- "version": "3.0.5",
4
+ "version": "3.1.0",
5
5
  "description": "Full-stack <head> manager built for Svelte.",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
@@ -45,6 +45,10 @@
45
45
  "types": "./dist/plugins.d.ts",
46
46
  "default": "./dist/plugins.mjs"
47
47
  },
48
+ "./bundler": {
49
+ "types": "./dist/bundler.d.ts",
50
+ "default": "./dist/bundler.mjs"
51
+ },
48
52
  "./vite": {
49
53
  "types": "./dist/vite.d.ts",
50
54
  "default": "./dist/vite.mjs"
@@ -77,6 +81,9 @@
77
81
  "utils": [
78
82
  "dist/utils"
79
83
  ],
84
+ "bundler": [
85
+ "dist/bundler"
86
+ ],
80
87
  "vite": [
81
88
  "dist/vite"
82
89
  ],
@@ -91,11 +98,15 @@
91
98
  ],
92
99
  "peerDependencies": {
93
100
  "svelte": ">=5.38.0",
94
- "vite": ">=6.4.2"
101
+ "vite": ">=6.4.2",
102
+ "webpack": ">=5.0.0"
95
103
  },
96
104
  "peerDependenciesMeta": {
97
105
  "vite": {
98
106
  "optional": true
107
+ },
108
+ "webpack": {
109
+ "optional": true
99
110
  }
100
111
  },
101
112
  "build": {
@@ -106,14 +117,15 @@
106
117
  "dependencies": {
107
118
  "magic-string": "^0.30.21",
108
119
  "oxc-walker": "^0.7.0",
109
- "unhead": "3.0.5",
110
- "@unhead/bundler": "3.0.5"
120
+ "unplugin": "^3.0.0",
121
+ "@unhead/bundler": "3.1.0",
122
+ "unhead": "3.1.0"
111
123
  },
112
124
  "devDependencies": {
113
125
  "@sveltejs/vite-plugin-svelte": "^7.0.0",
114
126
  "@testing-library/svelte": "^5.3.1",
115
- "svelte": "^5.55.4",
116
- "vite": "^8.0.9"
127
+ "svelte": "^5.55.5",
128
+ "vite": "^8.0.10"
117
129
  },
118
130
  "scripts": {
119
131
  "build": "unbuild .",