@unhead/bundler 3.0.4 → 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.
- package/README.md +0 -15
- package/dist/devtools-ui/200.html +1 -1
- package/dist/devtools-ui/404.html +1 -1
- package/dist/devtools-ui/_nuxt/C0eBIUCY.js +1 -0
- package/dist/devtools-ui/_nuxt/C6FB9XR7.js +1 -0
- package/dist/devtools-ui/_nuxt/{0Qa6s_Dg.js → CTIDChy9.js} +1 -1
- package/dist/devtools-ui/_nuxt/Cl48MOdR.js +1 -0
- package/dist/devtools-ui/_nuxt/D0h8RKZP.js +1 -0
- package/dist/devtools-ui/_nuxt/D1euPyWC.js +1 -0
- package/dist/devtools-ui/_nuxt/DH2dVWx3.js +1 -0
- package/dist/devtools-ui/_nuxt/DMn5FtwN.js +1 -0
- package/dist/devtools-ui/_nuxt/DQzShJ2s.js +1 -0
- package/dist/devtools-ui/_nuxt/DevtoolsTagTable.J276FsWb.css +1 -0
- package/dist/devtools-ui/_nuxt/Dy309ItU.js +1 -0
- package/dist/devtools-ui/_nuxt/KktNLKXM.js +1 -0
- package/dist/devtools-ui/_nuxt/LXzUJvwE.js +184 -0
- package/dist/devtools-ui/_nuxt/OQB3ITYU.js +1 -0
- package/dist/devtools-ui/_nuxt/S60UZsZE.js +1 -0
- package/dist/devtools-ui/_nuxt/{Bh8c0baD.js → UEnd3JDt.js} +1 -1
- package/dist/devtools-ui/_nuxt/{BjpL9Tvi.js → UKe4OZRP.js} +1 -1
- package/dist/devtools-ui/_nuxt/builds/latest.json +1 -1
- package/dist/devtools-ui/_nuxt/builds/meta/74bfd4ea-28e2-442f-93ba-55b766075483.json +1 -0
- package/dist/devtools-ui/_nuxt/e38X2hNB.js +1 -0
- package/dist/devtools-ui/_nuxt/entry.C0A6_lH-.css +1 -0
- package/dist/devtools-ui/_nuxt/error-404.DPPgd-2E.css +1 -0
- package/dist/devtools-ui/_nuxt/error-500.Df2YE7Su.css +1 -0
- package/dist/devtools-ui/_nuxt/sJqYz6RP.js +1 -0
- package/dist/devtools-ui/index.html +1 -1
- package/dist/framework.d.mts +72 -0
- package/dist/framework.d.ts +72 -0
- package/dist/framework.mjs +102 -0
- package/dist/minify/esbuild.d.mts +1 -1
- package/dist/minify/esbuild.d.ts +1 -1
- package/dist/minify/lightningcss.d.mts +1 -1
- package/dist/minify/lightningcss.d.ts +1 -1
- package/dist/minify/rolldown.d.mts +1 -1
- package/dist/minify/rolldown.d.ts +1 -1
- package/dist/shared/{bundler.BgFGu6g_.mjs → bundler.D9eYJXZg.mjs} +320 -5
- package/dist/shared/{bundler.BwKIGaKX.d.mts → bundler.LjD9SWtb.d.mts} +17 -2
- package/dist/shared/{bundler.BwKIGaKX.d.ts → bundler.LjD9SWtb.d.ts} +17 -2
- package/dist/vite.d.mts +10 -2
- package/dist/vite.d.ts +10 -2
- package/dist/vite.mjs +9 -244
- package/package.json +24 -12
- package/dist/devtools-ui/_nuxt/B2Jv09Lm.js +0 -1
- package/dist/devtools-ui/_nuxt/BFZZDhfF.js +0 -1
- package/dist/devtools-ui/_nuxt/BJQr0rHL.js +0 -1
- package/dist/devtools-ui/_nuxt/Bi7iarQE.js +0 -1
- package/dist/devtools-ui/_nuxt/BzyzpJpe.js +0 -1
- package/dist/devtools-ui/_nuxt/CQCCfgfs.js +0 -1
- package/dist/devtools-ui/_nuxt/CjvTvDUb.js +0 -1
- package/dist/devtools-ui/_nuxt/CyW9BsJI.js +0 -1
- package/dist/devtools-ui/_nuxt/DEZb6eJV.js +0 -1
- package/dist/devtools-ui/_nuxt/DbNB16xc.js +0 -1
- package/dist/devtools-ui/_nuxt/DevtoolsTagTable.Bi_gUiSE.css +0 -1
- package/dist/devtools-ui/_nuxt/Dk8INXUW.js +0 -1
- package/dist/devtools-ui/_nuxt/MzHi9Z_M.js +0 -1
- package/dist/devtools-ui/_nuxt/SqzsD7Ng.js +0 -1
- package/dist/devtools-ui/_nuxt/builds/meta/1507f341-05d3-41bb-970d-fba6ff77a58d.json +0 -1
- package/dist/devtools-ui/_nuxt/entry.clcQIxBm.css +0 -1
- package/dist/devtools-ui/_nuxt/error-404.BD1cQo3f.css +0 -1
- package/dist/devtools-ui/_nuxt/error-500.C6qGqSpk.css +0 -1
- package/dist/devtools-ui/_nuxt/lJJLnbTf.js +0 -181
- package/dist/webpack.d.mts +0 -5
- package/dist/webpack.d.ts +0 -5
- package/dist/webpack.mjs +0 -31
|
@@ -1,12 +1,321 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
4
|
import MagicString from 'magic-string';
|
|
5
|
+
import { parseAndWalk, ScopeTracker, walk, ScopeTrackerImport } from 'oxc-walker';
|
|
6
|
+
import { defineRpcFunction } from '@vitejs/devtools-kit';
|
|
3
7
|
import { parseSync } from 'oxc-parser';
|
|
4
|
-
import { ScopeTracker, walk, ScopeTrackerImport } from 'oxc-walker';
|
|
5
8
|
import { parseURL, parseQuery } from 'ufo';
|
|
6
9
|
import { createUnplugin } from 'unplugin';
|
|
7
10
|
import { createContext, runInContext } from 'node:vm';
|
|
8
11
|
import { resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue } from 'unhead/utils';
|
|
9
12
|
|
|
13
|
+
const getConfigRpc = defineRpcFunction({
|
|
14
|
+
name: "unhead:get-config",
|
|
15
|
+
type: "static",
|
|
16
|
+
setup: (ctx) => ({
|
|
17
|
+
handler: () => ({
|
|
18
|
+
cwd: ctx.cwd,
|
|
19
|
+
mode: ctx.mode
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
async function tryRequire() {
|
|
25
|
+
try {
|
|
26
|
+
const mod = await import('@unhead/cli');
|
|
27
|
+
return { runLint: mod.runLint };
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const runLintRpc = defineRpcFunction({
|
|
33
|
+
name: "unhead:run-lint",
|
|
34
|
+
type: "static",
|
|
35
|
+
setup: (ctx) => ({
|
|
36
|
+
handler: async (args = {}) => {
|
|
37
|
+
const lib = await tryRequire();
|
|
38
|
+
if (!lib) {
|
|
39
|
+
return {
|
|
40
|
+
available: false,
|
|
41
|
+
message: "Install @unhead/cli (and eslint as a peer) to enable in-devtools auditing."
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const start = Date.now();
|
|
45
|
+
const mode = args.mode === "migrate" ? "migrate" : "audit";
|
|
46
|
+
const cwd = ctx.cwd;
|
|
47
|
+
const { results, errorCount, warningCount, fixableErrorCount, fixableWarningCount } = await lib.runLint({
|
|
48
|
+
patterns: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx,vue,svelte}"],
|
|
49
|
+
mode,
|
|
50
|
+
cwd,
|
|
51
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/.output/**", "**/.nuxt/**"]
|
|
52
|
+
});
|
|
53
|
+
const files = results.map((r) => ({
|
|
54
|
+
filePath: r.filePath,
|
|
55
|
+
relativePath: relative(cwd, r.filePath),
|
|
56
|
+
errorCount: r.errorCount,
|
|
57
|
+
warningCount: r.warningCount,
|
|
58
|
+
fixableErrorCount: r.fixableErrorCount,
|
|
59
|
+
fixableWarningCount: r.fixableWarningCount,
|
|
60
|
+
fixed: typeof r.output === "string",
|
|
61
|
+
messages: (r.messages || []).map((m) => ({
|
|
62
|
+
ruleId: m.ruleId ?? null,
|
|
63
|
+
message: m.message,
|
|
64
|
+
severity: m.severity === 2 ? "error" : "warn",
|
|
65
|
+
line: m.line,
|
|
66
|
+
column: m.column,
|
|
67
|
+
endLine: m.endLine,
|
|
68
|
+
endColumn: m.endColumn,
|
|
69
|
+
// Only `fix` is auto-applied by `--fix`; suggestions are editor-only.
|
|
70
|
+
fixable: Boolean(m.fix)
|
|
71
|
+
}))
|
|
72
|
+
})).filter((f) => f.errorCount > 0 || f.warningCount > 0 || f.fixed);
|
|
73
|
+
const filesFixed = files.filter((f) => f.fixed).length;
|
|
74
|
+
return {
|
|
75
|
+
available: true,
|
|
76
|
+
mode,
|
|
77
|
+
files,
|
|
78
|
+
errorCount,
|
|
79
|
+
warningCount,
|
|
80
|
+
fixableErrorCount,
|
|
81
|
+
fixableWarningCount,
|
|
82
|
+
filesFixed,
|
|
83
|
+
durationMs: Date.now() - start
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const HEAD_COMPOSABLES = ["useHead", "useSeoMeta", "useHeadSafe", "useScript"];
|
|
90
|
+
const FILE_RE$1 = /\.(vue|tsx?|jsx?|svelte)$/;
|
|
91
|
+
const LEADING_SLASH_RE = /^\//;
|
|
92
|
+
const UNHEAD_VERSION_RE = /__UNHEAD_VERSION__ = ['"]'?["']/;
|
|
93
|
+
const UNHEAD_ICON = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 24 24'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' stop-color='%23FBBF24'/%3E%3Cstop offset='100%25' stop-color='%23f0db4f'/%3E%3C/linearGradient%3E%3Cmask id='m'%3E%3Crect width='100%25' height='100%25' fill='white'/%3E%3Cpath d='M12 32 L1 32 L15 15 Z' fill='black'/%3E%3C/mask%3E%3C/defs%3E%3Cpath fill='none' stroke='url(%23g)' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 4v14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V4' mask='url(%23m)'/%3E%3C/svg%3E`;
|
|
94
|
+
const DEVTOOLS_UI_ROUTE = "/__unhead/";
|
|
95
|
+
function transformSourceLocations(code, id, root) {
|
|
96
|
+
if (!HEAD_COMPOSABLES.some((c) => code.includes(c)))
|
|
97
|
+
return;
|
|
98
|
+
const s = new MagicString(code);
|
|
99
|
+
let transformed = false;
|
|
100
|
+
const relativePath = id.startsWith(root) ? id.slice(root.length).replace(LEADING_SLASH_RE, "") : id;
|
|
101
|
+
parseAndWalk(code, id, {
|
|
102
|
+
parseOptions: { lang: "ts" },
|
|
103
|
+
enter(node) {
|
|
104
|
+
if (node.type !== "CallExpression")
|
|
105
|
+
return;
|
|
106
|
+
const callee = node.callee;
|
|
107
|
+
if (!callee)
|
|
108
|
+
return;
|
|
109
|
+
const name = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && callee.property?.type === "Identifier" ? callee.property.name : null;
|
|
110
|
+
if (!name || !HEAD_COMPOSABLES.includes(name))
|
|
111
|
+
return;
|
|
112
|
+
const args = node.arguments;
|
|
113
|
+
if (!args || args.length === 0)
|
|
114
|
+
return;
|
|
115
|
+
const lineNumber = code.slice(0, node.start).split("\n").length;
|
|
116
|
+
const sourceValue = `${relativePath}:${lineNumber}`;
|
|
117
|
+
if (args.length === 1) {
|
|
118
|
+
const argEnd = args[0].end;
|
|
119
|
+
s.appendRight(argEnd, `, { _source: ${JSON.stringify(sourceValue)} }`);
|
|
120
|
+
transformed = true;
|
|
121
|
+
} else if (args.length >= 2 && args[1].type === "ObjectExpression") {
|
|
122
|
+
const objStart = args[1].start + 1;
|
|
123
|
+
s.appendRight(objStart, ` _source: ${JSON.stringify(sourceValue)},`);
|
|
124
|
+
transformed = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (!transformed)
|
|
129
|
+
return;
|
|
130
|
+
return {
|
|
131
|
+
code: s.toString(),
|
|
132
|
+
map: s.generateMap({ includeContent: true, source: id })
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function unheadDevtools(options) {
|
|
136
|
+
let root = "";
|
|
137
|
+
let enabled = false;
|
|
138
|
+
let bridgeCode;
|
|
139
|
+
let unheadVersion = "";
|
|
140
|
+
const pkgDir = fileURLToPath(new URL("..", import.meta.url));
|
|
141
|
+
const devtoolsUiDir = fileURLToPath(new URL("./devtools-ui", import.meta.url));
|
|
142
|
+
return {
|
|
143
|
+
name: "@unhead/devtools",
|
|
144
|
+
apply: "serve",
|
|
145
|
+
configResolved(config) {
|
|
146
|
+
root = config.root;
|
|
147
|
+
enabled = config.plugins.some((p) => p.name?.startsWith("vite:devtools"));
|
|
148
|
+
if (!enabled)
|
|
149
|
+
return;
|
|
150
|
+
if (options?._ctx) {
|
|
151
|
+
options._ctx.addRuntimePlugin({
|
|
152
|
+
import: { name: "devtoolsPlugin", source: "@unhead/bundler", as: "__unhead_devtoolsPlugin" },
|
|
153
|
+
client: "window.__unhead_devtools__=_h",
|
|
154
|
+
server: "_h.use(__unhead_devtoolsPlugin())"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const unheadPkg = resolve(pkgDir, "node_modules/unhead/package.json");
|
|
159
|
+
if (existsSync(unheadPkg))
|
|
160
|
+
unheadVersion = JSON.parse(readFileSync(unheadPkg, "utf-8")).version || "";
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
const bridgePath = resolve(pkgDir, "dist/devtools/bridge.mjs");
|
|
164
|
+
if (existsSync(bridgePath))
|
|
165
|
+
bridgeCode = readFileSync(bridgePath, "utf-8");
|
|
166
|
+
},
|
|
167
|
+
configureServer(server) {
|
|
168
|
+
if (!enabled)
|
|
169
|
+
return;
|
|
170
|
+
server.middlewares.use("/@unhead/bridge.mjs", async (_req, res) => {
|
|
171
|
+
const result = await server.transformRequest("/@unhead/bridge.mjs");
|
|
172
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
173
|
+
res.end(result?.code || 'console.warn("[unhead devtools] bridge not built")');
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
resolveId(id) {
|
|
177
|
+
if (!enabled)
|
|
178
|
+
return;
|
|
179
|
+
if (id === "/@unhead/bridge.mjs")
|
|
180
|
+
return id;
|
|
181
|
+
},
|
|
182
|
+
load(id) {
|
|
183
|
+
if (!enabled || id !== "/@unhead/bridge.mjs")
|
|
184
|
+
return;
|
|
185
|
+
if (!bridgeCode)
|
|
186
|
+
return 'console.warn("[unhead devtools] bridge not built")';
|
|
187
|
+
let code = bridgeCode;
|
|
188
|
+
if (unheadVersion)
|
|
189
|
+
code = code.replace(UNHEAD_VERSION_RE, `__UNHEAD_VERSION__ = '${unheadVersion}'`);
|
|
190
|
+
const kitClientPath = resolve(pkgDir, "node_modules/@vitejs/devtools-kit/dist/client.js");
|
|
191
|
+
if (existsSync(kitClientPath))
|
|
192
|
+
return code.replace(`'@vitejs/devtools-kit/client'`, `'${kitClientPath}'`);
|
|
193
|
+
return code;
|
|
194
|
+
},
|
|
195
|
+
transform: {
|
|
196
|
+
filter: { id: FILE_RE$1 },
|
|
197
|
+
handler(code, id) {
|
|
198
|
+
if (!enabled)
|
|
199
|
+
return;
|
|
200
|
+
return transformSourceLocations(code, id, root);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
transformIndexHtml: {
|
|
204
|
+
// Run before non-pre HTML transforms so the injected module import
|
|
205
|
+
// goes through the full Vite plugin pipeline.
|
|
206
|
+
order: "pre",
|
|
207
|
+
handler() {
|
|
208
|
+
if (!enabled)
|
|
209
|
+
return [];
|
|
210
|
+
return [{
|
|
211
|
+
tag: "script",
|
|
212
|
+
attrs: { type: "module" },
|
|
213
|
+
children: `import("/@unhead/bridge.mjs")`,
|
|
214
|
+
injectTo: "head"
|
|
215
|
+
}];
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
devtools: {
|
|
219
|
+
setup(ctx) {
|
|
220
|
+
if (existsSync(devtoolsUiDir)) {
|
|
221
|
+
ctx.views.hostStatic(DEVTOOLS_UI_ROUTE, devtoolsUiDir);
|
|
222
|
+
}
|
|
223
|
+
ctx.docks.register({
|
|
224
|
+
id: "unhead",
|
|
225
|
+
title: "Unhead",
|
|
226
|
+
icon: UNHEAD_ICON,
|
|
227
|
+
type: "iframe",
|
|
228
|
+
url: DEVTOOLS_UI_ROUTE
|
|
229
|
+
});
|
|
230
|
+
ctx.rpc.register(getConfigRpc);
|
|
231
|
+
ctx.rpc.register(runLintRpc);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const FILE_RE = /\.(vue|tsx?|jsx?|svelte)$/;
|
|
238
|
+
const UNHEAD_SOURCE_RE = /^(?:@unhead\/[^/]+|unhead)(?:\/[^?]*)?$/;
|
|
239
|
+
function createHeadTransformContext() {
|
|
240
|
+
const registrations = [];
|
|
241
|
+
return {
|
|
242
|
+
addRuntimePlugin(reg) {
|
|
243
|
+
registrations.push(reg);
|
|
244
|
+
},
|
|
245
|
+
getRegistrations() {
|
|
246
|
+
return registrations;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function CreateHeadTransform(ctx) {
|
|
251
|
+
let root = "";
|
|
252
|
+
return {
|
|
253
|
+
name: "@unhead/create-head-transform",
|
|
254
|
+
apply: "serve",
|
|
255
|
+
configResolved(config) {
|
|
256
|
+
root = config.root;
|
|
257
|
+
},
|
|
258
|
+
transform: {
|
|
259
|
+
filter: { id: FILE_RE },
|
|
260
|
+
handler(code, id) {
|
|
261
|
+
const registrations = ctx.getRegistrations();
|
|
262
|
+
if (!registrations.length)
|
|
263
|
+
return;
|
|
264
|
+
if (!code.includes("createHead"))
|
|
265
|
+
return;
|
|
266
|
+
const isServer = this.environment?.config?.consumer === "server";
|
|
267
|
+
const envRegistrations = registrations.filter((r) => isServer ? r.server : r.client);
|
|
268
|
+
if (!envRegistrations.length)
|
|
269
|
+
return;
|
|
270
|
+
const s = new MagicString(code);
|
|
271
|
+
let transformed = false;
|
|
272
|
+
const directCreateHeadNames = /* @__PURE__ */ new Set();
|
|
273
|
+
const namespaceNames = /* @__PURE__ */ new Set();
|
|
274
|
+
parseAndWalk(code, id, {
|
|
275
|
+
parseOptions: { lang: "ts" },
|
|
276
|
+
enter(node) {
|
|
277
|
+
if (node.type === "ImportDeclaration") {
|
|
278
|
+
const source = node.source?.value;
|
|
279
|
+
if (typeof source !== "string" || !UNHEAD_SOURCE_RE.test(source))
|
|
280
|
+
return;
|
|
281
|
+
for (const spec of node.specifiers || []) {
|
|
282
|
+
if (spec.type === "ImportSpecifier" && spec.imported?.name === "createHead")
|
|
283
|
+
directCreateHeadNames.add(spec.local.name);
|
|
284
|
+
else if (spec.type === "ImportNamespaceSpecifier")
|
|
285
|
+
namespaceNames.add(spec.local.name);
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (node.type !== "CallExpression")
|
|
290
|
+
return;
|
|
291
|
+
const callee = node.callee;
|
|
292
|
+
if (!callee)
|
|
293
|
+
return;
|
|
294
|
+
const isDirect = callee.type === "Identifier" && directCreateHeadNames.has(callee.name);
|
|
295
|
+
const isNamespaced = callee.type === "MemberExpression" && callee.object?.type === "Identifier" && namespaceNames.has(callee.object.name) && callee.property?.type === "Identifier" && callee.property.name === "createHead";
|
|
296
|
+
if (!isDirect && !isNamespaced)
|
|
297
|
+
return;
|
|
298
|
+
const statements = envRegistrations.map((r) => (isServer ? r.server : r.client).replace(/__ROOT__/g, JSON.stringify(root))).join(",");
|
|
299
|
+
s.prependLeft(node.start, `((_h)=>(${statements},_h))(`);
|
|
300
|
+
s.appendRight(node.end, `)`);
|
|
301
|
+
transformed = true;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
if (!transformed)
|
|
305
|
+
return;
|
|
306
|
+
for (const reg of envRegistrations) {
|
|
307
|
+
s.prepend(`import { ${reg.import.name} as ${reg.import.as} } from '${reg.import.source}';
|
|
308
|
+
`);
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
code: s.toString(),
|
|
312
|
+
map: s.generateMap({ includeContent: true, source: id })
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
10
319
|
const NODE_MODULES_RE$2 = /[\\/]node_modules[\\/]/;
|
|
11
320
|
const TRANSFORM_RE$2 = /\.(?:(?:c|m)?j|t)sx?$/;
|
|
12
321
|
const SKIP_JS_TYPES = /* @__PURE__ */ new Set(["application/json", "application/ld+json", "speculationrules", "importmap"]);
|
|
@@ -295,6 +604,7 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
295
604
|
const s = new MagicString(code);
|
|
296
605
|
const importRewrites = /* @__PURE__ */ new Map();
|
|
297
606
|
const valueReferenced = /* @__PURE__ */ new Set();
|
|
607
|
+
const untransformedCallees = /* @__PURE__ */ new Set();
|
|
298
608
|
walk(ast.program, {
|
|
299
609
|
scopeTracker,
|
|
300
610
|
enter(node, parent) {
|
|
@@ -322,8 +632,11 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
322
632
|
if (!SEO_META_NAMES.has(originalName))
|
|
323
633
|
return;
|
|
324
634
|
const properties = node.arguments[0]?.properties;
|
|
325
|
-
if (!properties)
|
|
635
|
+
if (!properties) {
|
|
636
|
+
if (importDecl)
|
|
637
|
+
untransformedCallees.add(originalName);
|
|
326
638
|
return;
|
|
639
|
+
}
|
|
327
640
|
let output = [];
|
|
328
641
|
const title = properties.find((property) => property.key?.name === "title");
|
|
329
642
|
const titleTemplate = properties.find((property) => property.key?.name === "titleTemplate");
|
|
@@ -422,6 +735,8 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
422
735
|
importRewrites.set(importDecl, /* @__PURE__ */ new Set());
|
|
423
736
|
importRewrites.get(importDecl).add(originalName);
|
|
424
737
|
}
|
|
738
|
+
} else if (importDecl) {
|
|
739
|
+
untransformedCallees.add(originalName);
|
|
425
740
|
}
|
|
426
741
|
}
|
|
427
742
|
});
|
|
@@ -434,7 +749,7 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
434
749
|
const importedName = spec.imported.name;
|
|
435
750
|
if (transformedNames.has(importedName)) {
|
|
436
751
|
newSpecifiers.add(importedName.includes("Server") ? "useServerHead" : "useHead");
|
|
437
|
-
if (valueReferenced.has(importedName))
|
|
752
|
+
if (valueReferenced.has(importedName) || untransformedCallees.has(importedName))
|
|
438
753
|
newSpecifiers.add(importedName);
|
|
439
754
|
} else {
|
|
440
755
|
newSpecifiers.add(importedName);
|
|
@@ -457,4 +772,4 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
457
772
|
};
|
|
458
773
|
});
|
|
459
774
|
|
|
460
|
-
export { MinifyTransform as M, SSRStaticReplace as S, TreeshakeServerComposables as T, UseSeoMetaTransform as U };
|
|
775
|
+
export { CreateHeadTransform as C, MinifyTransform as M, SSRStaticReplace as S, TreeshakeServerComposables as T, UseSeoMetaTransform as U, createHeadTransformContext as c, unheadDevtools as u };
|
|
@@ -51,10 +51,25 @@ interface VitePluginOptions extends UnpluginOptions {
|
|
|
51
51
|
devtools?: UnheadDevtoolsOptions | false;
|
|
52
52
|
/** Inject ValidatePlugin in dev to surface head tag warnings in the console. Enabled by default, set `false` to disable. */
|
|
53
53
|
validate?: boolean;
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
* @deprecated Pass via the `internal` second argument of `Unhead()` instead.
|
|
57
|
+
* Retained as a passthrough so existing framework wrappers keep working.
|
|
58
|
+
*/
|
|
55
59
|
_framework?: string;
|
|
56
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Internal extension carrying the framework package name (e.g. `@unhead/vue`)
|
|
63
|
+
* so the base bundler factory can import runtime plugins from the right path.
|
|
64
|
+
* Never exposed on public option types; framework wrappers pass this via
|
|
65
|
+
* the factory helpers in `./framework`.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
interface InternalFrameworkContext {
|
|
70
|
+
framework?: string;
|
|
71
|
+
}
|
|
57
72
|
interface UnheadDevtoolsOptions {
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
export type {
|
|
75
|
+
export type { InternalFrameworkContext as I, MinifyFn as M, VitePluginOptions as V };
|
|
@@ -51,10 +51,25 @@ interface VitePluginOptions extends UnpluginOptions {
|
|
|
51
51
|
devtools?: UnheadDevtoolsOptions | false;
|
|
52
52
|
/** Inject ValidatePlugin in dev to surface head tag warnings in the console. Enabled by default, set `false` to disable. */
|
|
53
53
|
validate?: boolean;
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
* @deprecated Pass via the `internal` second argument of `Unhead()` instead.
|
|
57
|
+
* Retained as a passthrough so existing framework wrappers keep working.
|
|
58
|
+
*/
|
|
55
59
|
_framework?: string;
|
|
56
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Internal extension carrying the framework package name (e.g. `@unhead/vue`)
|
|
63
|
+
* so the base bundler factory can import runtime plugins from the right path.
|
|
64
|
+
* Never exposed on public option types; framework wrappers pass this via
|
|
65
|
+
* the factory helpers in `./framework`.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
interface InternalFrameworkContext {
|
|
70
|
+
framework?: string;
|
|
71
|
+
}
|
|
57
72
|
interface UnheadDevtoolsOptions {
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
export type {
|
|
75
|
+
export type { InternalFrameworkContext as I, MinifyFn as M, VitePluginOptions as V };
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { V as VitePluginOptions } from './shared/bundler.
|
|
2
|
+
import { V as VitePluginOptions, I as InternalFrameworkContext } from './shared/bundler.LjD9SWtb.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Vite plugin factory that composes the core Unhead build-time transforms
|
|
6
|
+
* (tree-shake, seo-meta, minify, SSR static replace, devtools).
|
|
7
|
+
*
|
|
8
|
+
* Framework packages (e.g. `@unhead/vue/vite`) should not call this directly;
|
|
9
|
+
* use the `createFrameworkVitePlugin` helper in `./framework` which threads
|
|
10
|
+
* `_framework` correctly without exposing it on public options.
|
|
11
|
+
*/
|
|
12
|
+
declare function Unhead(options?: VitePluginOptions, internal?: InternalFrameworkContext): Plugin[];
|
|
5
13
|
|
|
6
14
|
export { Unhead, VitePluginOptions };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { V as VitePluginOptions } from './shared/bundler.
|
|
2
|
+
import { V as VitePluginOptions, I as InternalFrameworkContext } from './shared/bundler.LjD9SWtb.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Vite plugin factory that composes the core Unhead build-time transforms
|
|
6
|
+
* (tree-shake, seo-meta, minify, SSR static replace, devtools).
|
|
7
|
+
*
|
|
8
|
+
* Framework packages (e.g. `@unhead/vue/vite`) should not call this directly;
|
|
9
|
+
* use the `createFrameworkVitePlugin` helper in `./framework` which threads
|
|
10
|
+
* `_framework` correctly without exposing it on public options.
|
|
11
|
+
*/
|
|
12
|
+
declare function Unhead(options?: VitePluginOptions, internal?: InternalFrameworkContext): Plugin[];
|
|
5
13
|
|
|
6
14
|
export { Unhead, VitePluginOptions };
|