@unhead/addons 2.0.0-alpha.9 → 2.0.0-beta.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/dist/shared/{addons.CmryBgzY.mjs → addons.DAcLivtz.mjs} +56 -22
- package/dist/vite.mjs +2 -2
- package/dist/webpack.mjs +2 -2
- package/package.json +9 -14
- package/dist/index.cjs +0 -16
- package/dist/index.d.cts +0 -18
- package/dist/shared/addons.By35C-fR.cjs +0 -232
- package/dist/shared/addons.ChoDmUFv.d.cts +0 -16
- package/dist/vite.cjs +0 -21
- package/dist/vite.d.cts +0 -8
- package/dist/webpack.cjs +0 -21
- package/dist/webpack.d.cts +0 -8
|
@@ -3,10 +3,10 @@ import { parseURL, parseQuery } from 'ufo';
|
|
|
3
3
|
import { createUnplugin } from 'unplugin';
|
|
4
4
|
import { transform } from 'unplugin-ast';
|
|
5
5
|
import { createContext, runInContext } from 'node:vm';
|
|
6
|
-
import { resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue } from '@unhead/shared';
|
|
7
6
|
import { walk } from 'estree-walker';
|
|
8
7
|
import MagicString from 'magic-string';
|
|
9
8
|
import { findStaticImports, parseStaticImport } from 'mlly';
|
|
9
|
+
import { resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue } from 'unhead/utils';
|
|
10
10
|
|
|
11
11
|
function RemoveFunctions(functionNames) {
|
|
12
12
|
return {
|
|
@@ -17,7 +17,7 @@ function RemoveFunctions(functionNames) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const TreeshakeServerComposables = createUnplugin((options = {}) => {
|
|
20
|
-
options.enabled = options.enabled !==
|
|
20
|
+
options.enabled = options.enabled !== void 0 ? options.enabled : true;
|
|
21
21
|
return {
|
|
22
22
|
name: "unhead:remove-server-composables",
|
|
23
23
|
enforce: "post",
|
|
@@ -78,6 +78,12 @@ const TreeshakeServerComposables = createUnplugin((options = {}) => {
|
|
|
78
78
|
|
|
79
79
|
const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
80
80
|
options.imports = options.imports || true;
|
|
81
|
+
function isValidPackage(s) {
|
|
82
|
+
if (s === "unhead" || s.startsWith("@unhead")) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return [...options.importPaths || []].includes(s);
|
|
86
|
+
}
|
|
81
87
|
return {
|
|
82
88
|
name: "unhead:use-seo-meta-transform",
|
|
83
89
|
enforce: "post",
|
|
@@ -99,8 +105,7 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
99
105
|
async transform(code, id) {
|
|
100
106
|
if (!code.includes("useSeoMeta") && !code.includes("useServerSeoMeta"))
|
|
101
107
|
return;
|
|
102
|
-
const
|
|
103
|
-
const statements = findStaticImports(code).filter((i) => packages.includes(i.specifier));
|
|
108
|
+
const statements = findStaticImports(code).filter((i) => isValidPackage(i.specifier));
|
|
104
109
|
const importNames = {};
|
|
105
110
|
for (const i of statements.flatMap((i2) => parseStaticImport(i2))) {
|
|
106
111
|
if (i.namedImports) {
|
|
@@ -112,26 +117,36 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
112
117
|
}
|
|
113
118
|
const ast = this.parse(code);
|
|
114
119
|
const s = new MagicString(code);
|
|
115
|
-
|
|
120
|
+
let replacementPayload;
|
|
121
|
+
let replaceCount = 0;
|
|
122
|
+
let totalCount = 0;
|
|
116
123
|
walk(ast, {
|
|
117
124
|
enter(_node) {
|
|
118
|
-
if (options.imports && _node.type === "ImportDeclaration" &&
|
|
125
|
+
if (options.imports && _node.type === "ImportDeclaration" && isValidPackage(_node.source.value)) {
|
|
119
126
|
const node = _node;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
)
|
|
127
|
+
const hasSeoMeta = node.specifiers.some(
|
|
128
|
+
(s2) => s2.type === "ImportSpecifier" && ["useSeoMeta", "useServerSeoMeta"].includes(s2.imported.name)
|
|
129
|
+
);
|
|
130
|
+
if (!hasSeoMeta) {
|
|
124
131
|
return;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
}
|
|
133
|
+
const toImport = /* @__PURE__ */ new Set();
|
|
134
|
+
node.specifiers.forEach((spec) => {
|
|
135
|
+
if (spec.type === "ImportSpecifier" && ["useSeoMeta", "useServerSeoMeta"].includes(spec.imported.name)) {
|
|
136
|
+
toImport.add(spec.imported.name.includes("Server") ? "useServerHead" : "useHead");
|
|
137
|
+
} else {
|
|
138
|
+
toImport.add(spec.imported.name);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (toImport.size) {
|
|
142
|
+
replacementPayload = (useSeoMeta = false) => [node.specifiers[0].start, node.specifiers[node.specifiers.length - 1].end, [...toImport, useSeoMeta ? "useSeoMeta" : false].filter(Boolean).join(", ")];
|
|
143
|
+
}
|
|
130
144
|
} else if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && Object.keys({
|
|
131
145
|
useSeoMeta: "useSeoMeta",
|
|
132
146
|
useServerSeoMeta: "useServerSeoMeta",
|
|
133
147
|
...importNames
|
|
134
148
|
}).includes(_node.callee.name)) {
|
|
149
|
+
replaceCount++;
|
|
135
150
|
const node = _node;
|
|
136
151
|
const calleeName = importNames[node.callee.name] || node.callee.name;
|
|
137
152
|
const properties = node.arguments[0].properties;
|
|
@@ -169,12 +184,30 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
169
184
|
if (output === false)
|
|
170
185
|
return;
|
|
171
186
|
const propertyKey = property.key;
|
|
172
|
-
|
|
187
|
+
let key = resolveMetaKeyType(propertyKey.name);
|
|
173
188
|
const keyValue = resolveMetaKeyValue(propertyKey.name);
|
|
174
|
-
|
|
189
|
+
let valueKey = "content";
|
|
190
|
+
if (keyValue === "charset") {
|
|
191
|
+
valueKey = "charset";
|
|
192
|
+
key = "charset";
|
|
193
|
+
}
|
|
175
194
|
let value = code.substring(property.value.start, property.value.end);
|
|
176
195
|
if (property.value.type === "ArrayExpression") {
|
|
177
|
-
output
|
|
196
|
+
if (output === false)
|
|
197
|
+
return;
|
|
198
|
+
const elements = property.value.elements;
|
|
199
|
+
if (!elements.length)
|
|
200
|
+
return;
|
|
201
|
+
const metaTags = elements.map((element) => {
|
|
202
|
+
if (element.type !== "ObjectExpression")
|
|
203
|
+
return ` { ${key}: '${keyValue}', ${valueKey}: ${code.substring(element.start, element.end)} },`;
|
|
204
|
+
return element.properties.map((p) => {
|
|
205
|
+
const propKey = p.key.name;
|
|
206
|
+
const propValue = code.substring(p.value.start, p.value.end);
|
|
207
|
+
return ` { ${key}: '${keyValue}:${propKey}', ${valueKey}: ${propValue} },`;
|
|
208
|
+
}).join("\n");
|
|
209
|
+
});
|
|
210
|
+
output.push(metaTags.join("\n"));
|
|
178
211
|
return;
|
|
179
212
|
} else if (property.value.type === "ObjectExpression") {
|
|
180
213
|
const isStatic = property.value.properties.every((p) => p.value.type === "Literal" && typeof p.value.value === "string");
|
|
@@ -205,14 +238,15 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
205
238
|
output.push("})");
|
|
206
239
|
s.overwrite(node.start, node.end, output.join("\n"));
|
|
207
240
|
}
|
|
241
|
+
} else if (_node.type === "Identifier" && ["useSeoMeta", "useServerSeoMeta"].includes(_node.name)) {
|
|
242
|
+
totalCount++;
|
|
208
243
|
}
|
|
209
244
|
}
|
|
210
245
|
});
|
|
211
246
|
if (s.hasChanged()) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
`);
|
|
247
|
+
if (replacementPayload) {
|
|
248
|
+
s.overwrite(...replacementPayload(replaceCount + 3 === totalCount));
|
|
249
|
+
}
|
|
216
250
|
return {
|
|
217
251
|
code: s.toString(),
|
|
218
252
|
map: s.generateMap({ includeContent: true, source: id })
|
package/dist/vite.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.
|
|
1
|
+
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.DAcLivtz.mjs';
|
|
2
2
|
import 'node:url';
|
|
3
3
|
import 'ufo';
|
|
4
4
|
import 'unplugin';
|
|
5
5
|
import 'unplugin-ast';
|
|
6
6
|
import 'node:vm';
|
|
7
|
-
import '@unhead/shared';
|
|
8
7
|
import 'estree-walker';
|
|
9
8
|
import 'magic-string';
|
|
10
9
|
import 'mlly';
|
|
10
|
+
import 'unhead/utils';
|
|
11
11
|
|
|
12
12
|
const vite = (options = {}) => {
|
|
13
13
|
return [
|
package/dist/webpack.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.
|
|
1
|
+
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.DAcLivtz.mjs';
|
|
2
2
|
import 'node:url';
|
|
3
3
|
import 'ufo';
|
|
4
4
|
import 'unplugin';
|
|
5
5
|
import 'unplugin-ast';
|
|
6
6
|
import 'node:vm';
|
|
7
|
-
import '@unhead/shared';
|
|
8
7
|
import 'estree-walker';
|
|
9
8
|
import 'magic-string';
|
|
10
9
|
import 'mlly';
|
|
10
|
+
import 'unhead/utils';
|
|
11
11
|
|
|
12
12
|
const webpack = (options = {}) => {
|
|
13
13
|
return [
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/addons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-beta.0",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -22,21 +22,18 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
|
-
"import": "./dist/index.mjs"
|
|
26
|
-
"require": "./dist/index.cjs"
|
|
25
|
+
"import": "./dist/index.mjs"
|
|
27
26
|
},
|
|
28
27
|
"./vite": {
|
|
29
28
|
"types": "./dist/vite.d.ts",
|
|
30
|
-
"import": "./dist/vite.mjs"
|
|
31
|
-
"require": "./dist/vite.cjs"
|
|
29
|
+
"import": "./dist/vite.mjs"
|
|
32
30
|
},
|
|
33
31
|
"./webpack": {
|
|
34
32
|
"types": "./dist/webpack.d.ts",
|
|
35
|
-
"import": "./dist/webpack.mjs"
|
|
36
|
-
"require": "./dist/webpack.cjs"
|
|
33
|
+
"import": "./dist/webpack.mjs"
|
|
37
34
|
}
|
|
38
35
|
},
|
|
39
|
-
"main": "dist/index.
|
|
36
|
+
"main": "dist/index.mjs",
|
|
40
37
|
"module": "dist/index.mjs",
|
|
41
38
|
"types": "dist/index.d.ts",
|
|
42
39
|
"typesVersions": {
|
|
@@ -53,7 +50,7 @@
|
|
|
53
50
|
"dist"
|
|
54
51
|
],
|
|
55
52
|
"peerDependencies": {
|
|
56
|
-
"unhead": "2.0.0-
|
|
53
|
+
"unhead": "2.0.0-beta.0"
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
56
|
"@rollup/pluginutils": "^5.1.4",
|
|
@@ -61,13 +58,11 @@
|
|
|
61
58
|
"magic-string": "^0.30.17",
|
|
62
59
|
"mlly": "^1.7.4",
|
|
63
60
|
"ufo": "^1.5.4",
|
|
64
|
-
"unplugin": "^2.
|
|
65
|
-
"unplugin-ast": "^0.
|
|
66
|
-
"@unhead/schema": "2.0.0-alpha.9",
|
|
67
|
-
"@unhead/shared": "2.0.0-alpha.9"
|
|
61
|
+
"unplugin": "^2.2.0",
|
|
62
|
+
"unplugin-ast": "^0.14.0"
|
|
68
63
|
},
|
|
69
64
|
"devDependencies": {
|
|
70
|
-
"@babel/types": "^7.26.
|
|
65
|
+
"@babel/types": "^7.26.9"
|
|
71
66
|
},
|
|
72
67
|
"scripts": {
|
|
73
68
|
"build": "unbuild .",
|
package/dist/index.cjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const plugins = require('unhead/plugins');
|
|
4
|
-
|
|
5
|
-
const DefaultCriticalTags = {
|
|
6
|
-
htmlAttrs: {
|
|
7
|
-
lang: "en"
|
|
8
|
-
},
|
|
9
|
-
meta: [
|
|
10
|
-
{ charset: "utf-8" },
|
|
11
|
-
{ name: "viewport", content: "width=device-width, initial-scale=1" }
|
|
12
|
-
]
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.InferSeoMetaPlugin = plugins.InferSeoMetaPlugin;
|
|
16
|
-
exports.DefaultCriticalTags = DefaultCriticalTags;
|
package/dist/index.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export { InferSeoMetaPlugin } from 'unhead/plugins';
|
|
2
|
-
|
|
3
|
-
declare const DefaultCriticalTags: {
|
|
4
|
-
htmlAttrs: {
|
|
5
|
-
lang: string;
|
|
6
|
-
};
|
|
7
|
-
meta: ({
|
|
8
|
-
charset: string;
|
|
9
|
-
name?: undefined;
|
|
10
|
-
content?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
name: string;
|
|
13
|
-
content: string;
|
|
14
|
-
charset?: undefined;
|
|
15
|
-
})[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { DefaultCriticalTags };
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_url = require('node:url');
|
|
4
|
-
const ufo = require('ufo');
|
|
5
|
-
const unplugin = require('unplugin');
|
|
6
|
-
const unpluginAst = require('unplugin-ast');
|
|
7
|
-
const node_vm = require('node:vm');
|
|
8
|
-
const shared = require('@unhead/shared');
|
|
9
|
-
const estreeWalker = require('estree-walker');
|
|
10
|
-
const MagicString = require('magic-string');
|
|
11
|
-
const mlly = require('mlly');
|
|
12
|
-
|
|
13
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
14
|
-
|
|
15
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
16
|
-
|
|
17
|
-
function RemoveFunctions(functionNames) {
|
|
18
|
-
return {
|
|
19
|
-
onNode: (node) => node.type === "CallExpression" && node.callee.type === "Identifier" && functionNames.includes(node.callee.name),
|
|
20
|
-
transform() {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const TreeshakeServerComposables = unplugin.createUnplugin((options = {}) => {
|
|
26
|
-
options.enabled = options.enabled !== undefined ? options.enabled : true;
|
|
27
|
-
return {
|
|
28
|
-
name: "unhead:remove-server-composables",
|
|
29
|
-
enforce: "post",
|
|
30
|
-
transformInclude(id) {
|
|
31
|
-
if (!options.enabled)
|
|
32
|
-
return false;
|
|
33
|
-
const { pathname, search } = ufo.parseURL(decodeURIComponent(node_url.pathToFileURL(id).href));
|
|
34
|
-
const { type } = ufo.parseQuery(search);
|
|
35
|
-
if (pathname.match(/[\\/]node_modules[\\/]/))
|
|
36
|
-
return false;
|
|
37
|
-
if (options.filter?.include?.some((pattern) => id.match(pattern)))
|
|
38
|
-
return true;
|
|
39
|
-
if (options.filter?.exclude?.some((pattern) => id.match(pattern)))
|
|
40
|
-
return false;
|
|
41
|
-
if (pathname.endsWith(".vue") && (type === "script" || !search))
|
|
42
|
-
return true;
|
|
43
|
-
if (pathname.match(/\.((c|m)?j|t)sx?$/g))
|
|
44
|
-
return true;
|
|
45
|
-
return false;
|
|
46
|
-
},
|
|
47
|
-
async transform(code, id) {
|
|
48
|
-
if (!code.includes("useServerHead") && !code.includes("useServerHeadSafe") && !code.includes("useServerSeoMeta") && !code.includes("useSchemaOrg")) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
let transformed;
|
|
52
|
-
try {
|
|
53
|
-
transformed = await unpluginAst.transform(code, id, {
|
|
54
|
-
parserOptions: {},
|
|
55
|
-
transformer: [
|
|
56
|
-
RemoveFunctions([
|
|
57
|
-
"useServerHead",
|
|
58
|
-
"useServerHeadSafe",
|
|
59
|
-
"useServerSeoMeta",
|
|
60
|
-
// plugins
|
|
61
|
-
"useSchemaOrg"
|
|
62
|
-
])
|
|
63
|
-
]
|
|
64
|
-
});
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
return transformed;
|
|
68
|
-
},
|
|
69
|
-
webpack(ctx) {
|
|
70
|
-
if (ctx.name === "server")
|
|
71
|
-
options.enabled = false;
|
|
72
|
-
},
|
|
73
|
-
vite: {
|
|
74
|
-
apply(config, env) {
|
|
75
|
-
if (env.ssrBuild || env.isSsrBuild) {
|
|
76
|
-
options.enabled = false;
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const UseSeoMetaTransform = unplugin.createUnplugin((options = {}) => {
|
|
86
|
-
options.imports = options.imports || true;
|
|
87
|
-
return {
|
|
88
|
-
name: "unhead:use-seo-meta-transform",
|
|
89
|
-
enforce: "post",
|
|
90
|
-
transformInclude(id) {
|
|
91
|
-
const { pathname, search } = ufo.parseURL(decodeURIComponent(node_url.pathToFileURL(id).href));
|
|
92
|
-
const { type } = ufo.parseQuery(search);
|
|
93
|
-
if (pathname.match(/[\\/]node_modules[\\/]/))
|
|
94
|
-
return false;
|
|
95
|
-
if (options.filter?.include?.some((pattern) => id.match(pattern)))
|
|
96
|
-
return true;
|
|
97
|
-
if (options.filter?.exclude?.some((pattern) => id.match(pattern)))
|
|
98
|
-
return false;
|
|
99
|
-
if (pathname.endsWith(".vue") && (type === "script" || !search))
|
|
100
|
-
return true;
|
|
101
|
-
if (pathname.match(/\.((c|m)?j|t)sx?$/g))
|
|
102
|
-
return true;
|
|
103
|
-
return false;
|
|
104
|
-
},
|
|
105
|
-
async transform(code, id) {
|
|
106
|
-
if (!code.includes("useSeoMeta") && !code.includes("useServerSeoMeta"))
|
|
107
|
-
return;
|
|
108
|
-
const packages = ["unhead", "@unhead/vue", "unhead"];
|
|
109
|
-
const statements = mlly.findStaticImports(code).filter((i) => packages.includes(i.specifier));
|
|
110
|
-
const importNames = {};
|
|
111
|
-
for (const i of statements.flatMap((i2) => mlly.parseStaticImport(i2))) {
|
|
112
|
-
if (i.namedImports) {
|
|
113
|
-
for (const key in i.namedImports) {
|
|
114
|
-
if (key === "useSeoMeta" || key === "useServerSeoMeta")
|
|
115
|
-
importNames[i.namedImports[key]] = key;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const ast = this.parse(code);
|
|
120
|
-
const s = new MagicString__default(code);
|
|
121
|
-
const extraImports = /* @__PURE__ */ new Set();
|
|
122
|
-
estreeWalker.walk(ast, {
|
|
123
|
-
enter(_node) {
|
|
124
|
-
if (options.imports && _node.type === "ImportDeclaration" && packages.includes(_node.source.value)) {
|
|
125
|
-
const node = _node;
|
|
126
|
-
if (
|
|
127
|
-
// @ts-expect-error untyped
|
|
128
|
-
!node.specifiers.some((s2) => s2.type === "ImportSpecifier" && ["useSeoMeta", "useServerSeoMeta"].includes(s2.imported?.name))
|
|
129
|
-
)
|
|
130
|
-
return;
|
|
131
|
-
const imports = Object.values(importNames);
|
|
132
|
-
if (!imports.includes("useHead"))
|
|
133
|
-
extraImports.add(`import { useHead } from '${node.source.value}'`);
|
|
134
|
-
if (!imports.includes("useServerHead") && imports.includes("useServerSeoMeta"))
|
|
135
|
-
extraImports.add(`import { useServerHead } from '${node.source.value}'`);
|
|
136
|
-
} else if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && Object.keys({
|
|
137
|
-
useSeoMeta: "useSeoMeta",
|
|
138
|
-
useServerSeoMeta: "useServerSeoMeta",
|
|
139
|
-
...importNames
|
|
140
|
-
}).includes(_node.callee.name)) {
|
|
141
|
-
const node = _node;
|
|
142
|
-
const calleeName = importNames[node.callee.name] || node.callee.name;
|
|
143
|
-
const properties = node.arguments[0].properties;
|
|
144
|
-
if (!properties)
|
|
145
|
-
return;
|
|
146
|
-
let output = [];
|
|
147
|
-
const title = properties.find((property) => property.key?.name === "title");
|
|
148
|
-
const titleTemplate = properties.find((property) => property.key?.name === "titleTemplate");
|
|
149
|
-
const meta = properties.filter((property) => property.key?.name !== "title" && property.key?.name !== "titleTemplate");
|
|
150
|
-
if (title || titleTemplate || calleeName === "useSeoMeta") {
|
|
151
|
-
output.push("useHead({");
|
|
152
|
-
if (title) {
|
|
153
|
-
output.push(` title: ${code.substring(title.value.start, title.value.end)},`);
|
|
154
|
-
}
|
|
155
|
-
if (titleTemplate) {
|
|
156
|
-
output.push(` titleTemplate: ${code.substring(titleTemplate.value.start, titleTemplate.value.end)},`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (calleeName === "useServerSeoMeta") {
|
|
160
|
-
if (output.length)
|
|
161
|
-
output.push("});");
|
|
162
|
-
output.push("useServerHead({");
|
|
163
|
-
}
|
|
164
|
-
if (meta.length)
|
|
165
|
-
output.push(" meta: [");
|
|
166
|
-
meta.forEach((property) => {
|
|
167
|
-
if (property.type === "SpreadElement") {
|
|
168
|
-
output = false;
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (property.key.type !== "Identifier" || !property.value) {
|
|
172
|
-
output = false;
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (output === false)
|
|
176
|
-
return;
|
|
177
|
-
const propertyKey = property.key;
|
|
178
|
-
const key = shared.resolveMetaKeyType(propertyKey.name);
|
|
179
|
-
const keyValue = shared.resolveMetaKeyValue(propertyKey.name);
|
|
180
|
-
const valueKey = key === "charset" ? "charset" : "content";
|
|
181
|
-
let value = code.substring(property.value.start, property.value.end);
|
|
182
|
-
if (property.value.type === "ArrayExpression") {
|
|
183
|
-
output = false;
|
|
184
|
-
return;
|
|
185
|
-
} else if (property.value.type === "ObjectExpression") {
|
|
186
|
-
const isStatic = property.value.properties.every((p) => p.value.type === "Literal" && typeof p.value.value === "string");
|
|
187
|
-
if (!isStatic) {
|
|
188
|
-
output = false;
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const context = node_vm.createContext({
|
|
192
|
-
resolvePackedMetaObjectValue: shared.resolvePackedMetaObjectValue
|
|
193
|
-
});
|
|
194
|
-
const start = property.value.start;
|
|
195
|
-
const end = property.value.end;
|
|
196
|
-
try {
|
|
197
|
-
value = JSON.stringify(node_vm.runInContext(`resolvePackedMetaObjectValue(${code.slice(start, end)})`, context));
|
|
198
|
-
} catch {
|
|
199
|
-
output = false;
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (valueKey === "charset")
|
|
204
|
-
output.push(` { ${key}: ${value} },`);
|
|
205
|
-
else
|
|
206
|
-
output.push(` { ${key}: '${keyValue}', ${valueKey}: ${value} },`);
|
|
207
|
-
});
|
|
208
|
-
if (output) {
|
|
209
|
-
if (meta.length)
|
|
210
|
-
output.push(" ]");
|
|
211
|
-
output.push("})");
|
|
212
|
-
s.overwrite(node.start, node.end, output.join("\n"));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
if (s.hasChanged()) {
|
|
218
|
-
const prependImports = [...extraImports];
|
|
219
|
-
if (prependImports.length)
|
|
220
|
-
s.prepend(`${prependImports.join("\n")}
|
|
221
|
-
`);
|
|
222
|
-
return {
|
|
223
|
-
code: s.toString(),
|
|
224
|
-
map: s.generateMap({ includeContent: true, source: id })
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
exports.TreeshakeServerComposables = TreeshakeServerComposables;
|
|
232
|
-
exports.UseSeoMetaTransform = UseSeoMetaTransform;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TreeshakeServerComposablesOptions } from '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
2
|
-
import { UseSeoMetaTransformOptions } from '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
3
|
-
|
|
4
|
-
interface BaseTransformerTypes {
|
|
5
|
-
sourcemap?: boolean;
|
|
6
|
-
filter?: {
|
|
7
|
-
exclude?: RegExp[];
|
|
8
|
-
include?: RegExp[];
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
interface UnpluginOptions extends BaseTransformerTypes {
|
|
12
|
-
treeshake?: TreeshakeServerComposablesOptions;
|
|
13
|
-
transformSeoMeta?: UseSeoMetaTransformOptions;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type { UnpluginOptions as U };
|
package/dist/vite.cjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const UseSeoMetaTransform = require('./shared/addons.By35C-fR.cjs');
|
|
4
|
-
require('node:url');
|
|
5
|
-
require('ufo');
|
|
6
|
-
require('unplugin');
|
|
7
|
-
require('unplugin-ast');
|
|
8
|
-
require('node:vm');
|
|
9
|
-
require('@unhead/shared');
|
|
10
|
-
require('estree-walker');
|
|
11
|
-
require('magic-string');
|
|
12
|
-
require('mlly');
|
|
13
|
-
|
|
14
|
-
const vite = (options = {}) => {
|
|
15
|
-
return [
|
|
16
|
-
UseSeoMetaTransform.TreeshakeServerComposables.vite({ filter: options.filter, sourcemap: options.sourcemap, ...options.treeshake }),
|
|
17
|
-
UseSeoMetaTransform.UseSeoMetaTransform.vite({ filter: options.filter, sourcemap: options.sourcemap, ...options.transformSeoMeta })
|
|
18
|
-
];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
module.exports = vite;
|
package/dist/vite.d.cts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.ChoDmUFv.cjs';
|
|
3
|
-
import '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
4
|
-
import '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
5
|
-
|
|
6
|
-
declare const _default: (options?: UnpluginOptions) => Plugin[];
|
|
7
|
-
|
|
8
|
-
export { UnpluginOptions, _default as default };
|
package/dist/webpack.cjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const UseSeoMetaTransform = require('./shared/addons.By35C-fR.cjs');
|
|
4
|
-
require('node:url');
|
|
5
|
-
require('ufo');
|
|
6
|
-
require('unplugin');
|
|
7
|
-
require('unplugin-ast');
|
|
8
|
-
require('node:vm');
|
|
9
|
-
require('@unhead/shared');
|
|
10
|
-
require('estree-walker');
|
|
11
|
-
require('magic-string');
|
|
12
|
-
require('mlly');
|
|
13
|
-
|
|
14
|
-
const webpack = (options = {}) => {
|
|
15
|
-
return [
|
|
16
|
-
UseSeoMetaTransform.TreeshakeServerComposables.webpack({ filter: options.filter, sourcemap: options.sourcemap, ...options.treeshake || {} }),
|
|
17
|
-
UseSeoMetaTransform.UseSeoMetaTransform.webpack({ filter: options.filter, sourcemap: options.sourcemap, ...options.transformSeoMeta || {} })
|
|
18
|
-
];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
module.exports = webpack;
|
package/dist/webpack.d.cts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as webpack from 'webpack';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.ChoDmUFv.cjs';
|
|
3
|
-
import '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
4
|
-
import '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
5
|
-
|
|
6
|
-
declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
|
|
7
|
-
|
|
8
|
-
export { UnpluginOptions, _default as default };
|