@unhead/addons 1.11.14 → 2.0.0-alpha.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/index.cjs +2 -67
- package/dist/index.d.cts +2 -24
- package/dist/index.d.mts +2 -24
- package/dist/index.d.ts +2 -24
- package/dist/index.mjs +2 -67
- package/dist/shared/{addons.ec57f468.cjs → addons.By35C-fR.cjs} +4 -235
- package/dist/shared/{addons.c17a6ac5.mjs → addons.CmryBgzY.mjs} +3 -234
- package/dist/vite.cjs +2 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.mjs +2 -1
- package/dist/webpack.cjs +2 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.mjs +2 -1
- package/package.json +14 -12
- /package/dist/shared/{addons.0f7fef83.d.cts → addons.Bh7ZeIPm.d.cts} +0 -0
- /package/dist/shared/{addons.0f7fef83.d.mts → addons.Bh7ZeIPm.d.mts} +0 -0
- /package/dist/shared/{addons.0f7fef83.d.ts → addons.Bh7ZeIPm.d.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const plugins = require('unhead/plugins');
|
|
4
4
|
|
|
5
5
|
const DefaultCriticalTags = {
|
|
6
6
|
htmlAttrs: {
|
|
@@ -12,70 +12,5 @@ const DefaultCriticalTags = {
|
|
|
12
12
|
]
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
function InferSeoMetaPlugin(options = {}) {
|
|
17
|
-
return shared.defineHeadPlugin({
|
|
18
|
-
hooks: {
|
|
19
|
-
entries: {
|
|
20
|
-
resolve({ entries }) {
|
|
21
|
-
let titleTemplate = null;
|
|
22
|
-
let lastWeight = 999;
|
|
23
|
-
for (const entry of entries) {
|
|
24
|
-
const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
|
|
25
|
-
const input = entry[inputKey];
|
|
26
|
-
const weight = (typeof input.titleTemplate === "object" ? input.titleTemplate?.tagPriority : false) || entry.tagPriority || 100;
|
|
27
|
-
if (input.titleTemplate !== void 0 && weight <= lastWeight) {
|
|
28
|
-
titleTemplate = input.titleTemplate;
|
|
29
|
-
lastWeight = weight;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const entry of entries) {
|
|
33
|
-
const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
|
|
34
|
-
const input = entry[inputKey];
|
|
35
|
-
const resolvedMeta = input.meta || [];
|
|
36
|
-
titleTemplate = shared.resolveTitleTemplate(titleTemplate, input.title);
|
|
37
|
-
const title = input.title;
|
|
38
|
-
const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
|
|
39
|
-
const hasOgTitle = resolvedMeta.some((meta) => meta.property === "og:title");
|
|
40
|
-
const hasOgImage = resolvedMeta.some((meta) => meta.property === "og:image");
|
|
41
|
-
const hasTwitterCard = resolvedMeta.some((meta) => meta.name === "twitter:card");
|
|
42
|
-
const hasOgDescription = resolvedMeta.some((meta) => meta.property === "og:description");
|
|
43
|
-
entry[inputKey].meta = input.meta || [];
|
|
44
|
-
if (!hasOgTitle && (input.titleTemplate || input.title)) {
|
|
45
|
-
let newOgTitle = options?.ogTitle || titleTemplate || input.title;
|
|
46
|
-
if (typeof newOgTitle === "function")
|
|
47
|
-
newOgTitle = newOgTitle(title);
|
|
48
|
-
if (newOgTitle) {
|
|
49
|
-
entry[inputKey].meta.push({
|
|
50
|
-
property: "og:title",
|
|
51
|
-
// have the og:title be removed if we don't have a title
|
|
52
|
-
content: String(newOgTitle)
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (description && !hasOgDescription) {
|
|
57
|
-
let newOgDescription = options?.ogDescription || description;
|
|
58
|
-
if (typeof newOgDescription === "function")
|
|
59
|
-
newOgDescription = newOgDescription(title);
|
|
60
|
-
if (newOgDescription) {
|
|
61
|
-
entry[inputKey].meta.push({
|
|
62
|
-
property: "og:description",
|
|
63
|
-
content: String(newOgDescription)
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (hasOgImage && !hasTwitterCard) {
|
|
68
|
-
entry[inputKey].meta.push({
|
|
69
|
-
name: "twitter:card",
|
|
70
|
-
content: options?.twitterCard || "summary_large_image"
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
15
|
+
exports.InferSeoMetaPlugin = plugins.InferSeoMetaPlugin;
|
|
80
16
|
exports.DefaultCriticalTags = DefaultCriticalTags;
|
|
81
|
-
exports.InferSeoMetaPlugin = InferSeoMetaPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { InferSeoMetaPlugin } from 'unhead/plugins';
|
|
2
2
|
|
|
3
3
|
declare const DefaultCriticalTags: {
|
|
4
4
|
htmlAttrs: {
|
|
@@ -15,26 +15,4 @@ declare const DefaultCriticalTags: {
|
|
|
15
15
|
})[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Transform the og title.
|
|
21
|
-
*
|
|
22
|
-
* @param title
|
|
23
|
-
*/
|
|
24
|
-
ogTitle?: ((title: string) => string);
|
|
25
|
-
/**
|
|
26
|
-
* Transform the og description.
|
|
27
|
-
*
|
|
28
|
-
* @param title
|
|
29
|
-
*/
|
|
30
|
-
ogDescription?: ((description: string) => string);
|
|
31
|
-
/**
|
|
32
|
-
* The twitter card to use.
|
|
33
|
-
*
|
|
34
|
-
* @default 'summary_large_image'
|
|
35
|
-
*/
|
|
36
|
-
twitterCard?: false | 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
37
|
-
}
|
|
38
|
-
declare function InferSeoMetaPlugin(options?: InferSeoMetaPluginOptions): _unhead_schema.HeadPluginInput;
|
|
39
|
-
|
|
40
|
-
export { DefaultCriticalTags, InferSeoMetaPlugin, type InferSeoMetaPluginOptions };
|
|
18
|
+
export { DefaultCriticalTags };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { InferSeoMetaPlugin } from 'unhead/plugins';
|
|
2
2
|
|
|
3
3
|
declare const DefaultCriticalTags: {
|
|
4
4
|
htmlAttrs: {
|
|
@@ -15,26 +15,4 @@ declare const DefaultCriticalTags: {
|
|
|
15
15
|
})[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Transform the og title.
|
|
21
|
-
*
|
|
22
|
-
* @param title
|
|
23
|
-
*/
|
|
24
|
-
ogTitle?: ((title: string) => string);
|
|
25
|
-
/**
|
|
26
|
-
* Transform the og description.
|
|
27
|
-
*
|
|
28
|
-
* @param title
|
|
29
|
-
*/
|
|
30
|
-
ogDescription?: ((description: string) => string);
|
|
31
|
-
/**
|
|
32
|
-
* The twitter card to use.
|
|
33
|
-
*
|
|
34
|
-
* @default 'summary_large_image'
|
|
35
|
-
*/
|
|
36
|
-
twitterCard?: false | 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
37
|
-
}
|
|
38
|
-
declare function InferSeoMetaPlugin(options?: InferSeoMetaPluginOptions): _unhead_schema.HeadPluginInput;
|
|
39
|
-
|
|
40
|
-
export { DefaultCriticalTags, InferSeoMetaPlugin, type InferSeoMetaPluginOptions };
|
|
18
|
+
export { DefaultCriticalTags };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { InferSeoMetaPlugin } from 'unhead/plugins';
|
|
2
2
|
|
|
3
3
|
declare const DefaultCriticalTags: {
|
|
4
4
|
htmlAttrs: {
|
|
@@ -15,26 +15,4 @@ declare const DefaultCriticalTags: {
|
|
|
15
15
|
})[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Transform the og title.
|
|
21
|
-
*
|
|
22
|
-
* @param title
|
|
23
|
-
*/
|
|
24
|
-
ogTitle?: ((title: string) => string);
|
|
25
|
-
/**
|
|
26
|
-
* Transform the og description.
|
|
27
|
-
*
|
|
28
|
-
* @param title
|
|
29
|
-
*/
|
|
30
|
-
ogDescription?: ((description: string) => string);
|
|
31
|
-
/**
|
|
32
|
-
* The twitter card to use.
|
|
33
|
-
*
|
|
34
|
-
* @default 'summary_large_image'
|
|
35
|
-
*/
|
|
36
|
-
twitterCard?: false | 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
37
|
-
}
|
|
38
|
-
declare function InferSeoMetaPlugin(options?: InferSeoMetaPluginOptions): _unhead_schema.HeadPluginInput;
|
|
39
|
-
|
|
40
|
-
export { DefaultCriticalTags, InferSeoMetaPlugin, type InferSeoMetaPluginOptions };
|
|
18
|
+
export { DefaultCriticalTags };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { InferSeoMetaPlugin } from 'unhead/plugins';
|
|
2
2
|
|
|
3
3
|
const DefaultCriticalTags = {
|
|
4
4
|
htmlAttrs: {
|
|
@@ -10,69 +10,4 @@ const DefaultCriticalTags = {
|
|
|
10
10
|
]
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
function InferSeoMetaPlugin(options = {}) {
|
|
15
|
-
return defineHeadPlugin({
|
|
16
|
-
hooks: {
|
|
17
|
-
entries: {
|
|
18
|
-
resolve({ entries }) {
|
|
19
|
-
let titleTemplate = null;
|
|
20
|
-
let lastWeight = 999;
|
|
21
|
-
for (const entry of entries) {
|
|
22
|
-
const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
|
|
23
|
-
const input = entry[inputKey];
|
|
24
|
-
const weight = (typeof input.titleTemplate === "object" ? input.titleTemplate?.tagPriority : false) || entry.tagPriority || 100;
|
|
25
|
-
if (input.titleTemplate !== void 0 && weight <= lastWeight) {
|
|
26
|
-
titleTemplate = input.titleTemplate;
|
|
27
|
-
lastWeight = weight;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
const inputKey = entry.resolvedInput ? "resolvedInput" : "input";
|
|
32
|
-
const input = entry[inputKey];
|
|
33
|
-
const resolvedMeta = input.meta || [];
|
|
34
|
-
titleTemplate = resolveTitleTemplate(titleTemplate, input.title);
|
|
35
|
-
const title = input.title;
|
|
36
|
-
const description = resolvedMeta.find((meta) => meta.name === "description")?.content;
|
|
37
|
-
const hasOgTitle = resolvedMeta.some((meta) => meta.property === "og:title");
|
|
38
|
-
const hasOgImage = resolvedMeta.some((meta) => meta.property === "og:image");
|
|
39
|
-
const hasTwitterCard = resolvedMeta.some((meta) => meta.name === "twitter:card");
|
|
40
|
-
const hasOgDescription = resolvedMeta.some((meta) => meta.property === "og:description");
|
|
41
|
-
entry[inputKey].meta = input.meta || [];
|
|
42
|
-
if (!hasOgTitle && (input.titleTemplate || input.title)) {
|
|
43
|
-
let newOgTitle = options?.ogTitle || titleTemplate || input.title;
|
|
44
|
-
if (typeof newOgTitle === "function")
|
|
45
|
-
newOgTitle = newOgTitle(title);
|
|
46
|
-
if (newOgTitle) {
|
|
47
|
-
entry[inputKey].meta.push({
|
|
48
|
-
property: "og:title",
|
|
49
|
-
// have the og:title be removed if we don't have a title
|
|
50
|
-
content: String(newOgTitle)
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (description && !hasOgDescription) {
|
|
55
|
-
let newOgDescription = options?.ogDescription || description;
|
|
56
|
-
if (typeof newOgDescription === "function")
|
|
57
|
-
newOgDescription = newOgDescription(title);
|
|
58
|
-
if (newOgDescription) {
|
|
59
|
-
entry[inputKey].meta.push({
|
|
60
|
-
property: "og:description",
|
|
61
|
-
content: String(newOgDescription)
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (hasOgImage && !hasTwitterCard) {
|
|
66
|
-
entry[inputKey].meta.push({
|
|
67
|
-
name: "twitter:card",
|
|
68
|
-
content: options?.twitterCard || "summary_large_image"
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export { DefaultCriticalTags, InferSeoMetaPlugin };
|
|
13
|
+
export { DefaultCriticalTags };
|
|
@@ -6,6 +6,7 @@ const unplugin = require('unplugin');
|
|
|
6
6
|
const unpluginAst = require('unplugin-ast');
|
|
7
7
|
const node_vm = require('node:vm');
|
|
8
8
|
const shared = require('@unhead/shared');
|
|
9
|
+
const estreeWalker = require('estree-walker');
|
|
9
10
|
const MagicString = require('magic-string');
|
|
10
11
|
const mlly = require('mlly');
|
|
11
12
|
|
|
@@ -22,7 +23,7 @@ function RemoveFunctions(functionNames) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
const TreeshakeServerComposables = unplugin.createUnplugin((options = {}) => {
|
|
25
|
-
options.enabled = options.enabled !==
|
|
26
|
+
options.enabled = options.enabled !== undefined ? options.enabled : true;
|
|
26
27
|
return {
|
|
27
28
|
name: "unhead:remove-server-composables",
|
|
28
29
|
enforce: "post",
|
|
@@ -61,7 +62,7 @@ const TreeshakeServerComposables = unplugin.createUnplugin((options = {}) => {
|
|
|
61
62
|
])
|
|
62
63
|
]
|
|
63
64
|
});
|
|
64
|
-
} catch
|
|
65
|
+
} catch {
|
|
65
66
|
}
|
|
66
67
|
return transformed;
|
|
67
68
|
},
|
|
@@ -81,238 +82,6 @@ const TreeshakeServerComposables = unplugin.createUnplugin((options = {}) => {
|
|
|
81
82
|
};
|
|
82
83
|
});
|
|
83
84
|
|
|
84
|
-
/**
|
|
85
|
-
* @typedef { import('estree').Node} Node
|
|
86
|
-
* @typedef {{
|
|
87
|
-
* skip: () => void;
|
|
88
|
-
* remove: () => void;
|
|
89
|
-
* replace: (node: Node) => void;
|
|
90
|
-
* }} WalkerContext
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
class WalkerBase {
|
|
94
|
-
constructor() {
|
|
95
|
-
/** @type {boolean} */
|
|
96
|
-
this.should_skip = false;
|
|
97
|
-
|
|
98
|
-
/** @type {boolean} */
|
|
99
|
-
this.should_remove = false;
|
|
100
|
-
|
|
101
|
-
/** @type {Node | null} */
|
|
102
|
-
this.replacement = null;
|
|
103
|
-
|
|
104
|
-
/** @type {WalkerContext} */
|
|
105
|
-
this.context = {
|
|
106
|
-
skip: () => (this.should_skip = true),
|
|
107
|
-
remove: () => (this.should_remove = true),
|
|
108
|
-
replace: (node) => (this.replacement = node)
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @template {Node} Parent
|
|
114
|
-
* @param {Parent | null | undefined} parent
|
|
115
|
-
* @param {keyof Parent | null | undefined} prop
|
|
116
|
-
* @param {number | null | undefined} index
|
|
117
|
-
* @param {Node} node
|
|
118
|
-
*/
|
|
119
|
-
replace(parent, prop, index, node) {
|
|
120
|
-
if (parent && prop) {
|
|
121
|
-
if (index != null) {
|
|
122
|
-
/** @type {Array<Node>} */ (parent[prop])[index] = node;
|
|
123
|
-
} else {
|
|
124
|
-
/** @type {Node} */ (parent[prop]) = node;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* @template {Node} Parent
|
|
131
|
-
* @param {Parent | null | undefined} parent
|
|
132
|
-
* @param {keyof Parent | null | undefined} prop
|
|
133
|
-
* @param {number | null | undefined} index
|
|
134
|
-
*/
|
|
135
|
-
remove(parent, prop, index) {
|
|
136
|
-
if (parent && prop) {
|
|
137
|
-
if (index !== null && index !== undefined) {
|
|
138
|
-
/** @type {Array<Node>} */ (parent[prop]).splice(index, 1);
|
|
139
|
-
} else {
|
|
140
|
-
delete parent[prop];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @typedef { import('estree').Node} Node
|
|
148
|
-
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
|
149
|
-
* @typedef {(
|
|
150
|
-
* this: WalkerContext,
|
|
151
|
-
* node: Node,
|
|
152
|
-
* parent: Node | null,
|
|
153
|
-
* key: string | number | symbol | null | undefined,
|
|
154
|
-
* index: number | null | undefined
|
|
155
|
-
* ) => void} SyncHandler
|
|
156
|
-
*/
|
|
157
|
-
|
|
158
|
-
class SyncWalker extends WalkerBase {
|
|
159
|
-
/**
|
|
160
|
-
*
|
|
161
|
-
* @param {SyncHandler} [enter]
|
|
162
|
-
* @param {SyncHandler} [leave]
|
|
163
|
-
*/
|
|
164
|
-
constructor(enter, leave) {
|
|
165
|
-
super();
|
|
166
|
-
|
|
167
|
-
/** @type {boolean} */
|
|
168
|
-
this.should_skip = false;
|
|
169
|
-
|
|
170
|
-
/** @type {boolean} */
|
|
171
|
-
this.should_remove = false;
|
|
172
|
-
|
|
173
|
-
/** @type {Node | null} */
|
|
174
|
-
this.replacement = null;
|
|
175
|
-
|
|
176
|
-
/** @type {WalkerContext} */
|
|
177
|
-
this.context = {
|
|
178
|
-
skip: () => (this.should_skip = true),
|
|
179
|
-
remove: () => (this.should_remove = true),
|
|
180
|
-
replace: (node) => (this.replacement = node)
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/** @type {SyncHandler | undefined} */
|
|
184
|
-
this.enter = enter;
|
|
185
|
-
|
|
186
|
-
/** @type {SyncHandler | undefined} */
|
|
187
|
-
this.leave = leave;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @template {Node} Parent
|
|
192
|
-
* @param {Node} node
|
|
193
|
-
* @param {Parent | null} parent
|
|
194
|
-
* @param {keyof Parent} [prop]
|
|
195
|
-
* @param {number | null} [index]
|
|
196
|
-
* @returns {Node | null}
|
|
197
|
-
*/
|
|
198
|
-
visit(node, parent, prop, index) {
|
|
199
|
-
if (node) {
|
|
200
|
-
if (this.enter) {
|
|
201
|
-
const _should_skip = this.should_skip;
|
|
202
|
-
const _should_remove = this.should_remove;
|
|
203
|
-
const _replacement = this.replacement;
|
|
204
|
-
this.should_skip = false;
|
|
205
|
-
this.should_remove = false;
|
|
206
|
-
this.replacement = null;
|
|
207
|
-
|
|
208
|
-
this.enter.call(this.context, node, parent, prop, index);
|
|
209
|
-
|
|
210
|
-
if (this.replacement) {
|
|
211
|
-
node = this.replacement;
|
|
212
|
-
this.replace(parent, prop, index, node);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (this.should_remove) {
|
|
216
|
-
this.remove(parent, prop, index);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const skipped = this.should_skip;
|
|
220
|
-
const removed = this.should_remove;
|
|
221
|
-
|
|
222
|
-
this.should_skip = _should_skip;
|
|
223
|
-
this.should_remove = _should_remove;
|
|
224
|
-
this.replacement = _replacement;
|
|
225
|
-
|
|
226
|
-
if (skipped) return node;
|
|
227
|
-
if (removed) return null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** @type {keyof Node} */
|
|
231
|
-
let key;
|
|
232
|
-
|
|
233
|
-
for (key in node) {
|
|
234
|
-
/** @type {unknown} */
|
|
235
|
-
const value = node[key];
|
|
236
|
-
|
|
237
|
-
if (value && typeof value === 'object') {
|
|
238
|
-
if (Array.isArray(value)) {
|
|
239
|
-
const nodes = /** @type {Array<unknown>} */ (value);
|
|
240
|
-
for (let i = 0; i < nodes.length; i += 1) {
|
|
241
|
-
const item = nodes[i];
|
|
242
|
-
if (isNode(item)) {
|
|
243
|
-
if (!this.visit(item, node, key, i)) {
|
|
244
|
-
// removed
|
|
245
|
-
i--;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
} else if (isNode(value)) {
|
|
250
|
-
this.visit(value, node, key, null);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (this.leave) {
|
|
256
|
-
const _replacement = this.replacement;
|
|
257
|
-
const _should_remove = this.should_remove;
|
|
258
|
-
this.replacement = null;
|
|
259
|
-
this.should_remove = false;
|
|
260
|
-
|
|
261
|
-
this.leave.call(this.context, node, parent, prop, index);
|
|
262
|
-
|
|
263
|
-
if (this.replacement) {
|
|
264
|
-
node = this.replacement;
|
|
265
|
-
this.replace(parent, prop, index, node);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (this.should_remove) {
|
|
269
|
-
this.remove(parent, prop, index);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const removed = this.should_remove;
|
|
273
|
-
|
|
274
|
-
this.replacement = _replacement;
|
|
275
|
-
this.should_remove = _should_remove;
|
|
276
|
-
|
|
277
|
-
if (removed) return null;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return node;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Ducktype a node.
|
|
287
|
-
*
|
|
288
|
-
* @param {unknown} value
|
|
289
|
-
* @returns {value is Node}
|
|
290
|
-
*/
|
|
291
|
-
function isNode(value) {
|
|
292
|
-
return (
|
|
293
|
-
value !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* @typedef {import('estree').Node} Node
|
|
299
|
-
* @typedef {import('./sync.js').SyncHandler} SyncHandler
|
|
300
|
-
* @typedef {import('./async.js').AsyncHandler} AsyncHandler
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @param {Node} ast
|
|
305
|
-
* @param {{
|
|
306
|
-
* enter?: SyncHandler
|
|
307
|
-
* leave?: SyncHandler
|
|
308
|
-
* }} walker
|
|
309
|
-
* @returns {Node | null}
|
|
310
|
-
*/
|
|
311
|
-
function walk(ast, { enter, leave }) {
|
|
312
|
-
const instance = new SyncWalker(enter, leave);
|
|
313
|
-
return instance.visit(ast, null);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
85
|
const UseSeoMetaTransform = unplugin.createUnplugin((options = {}) => {
|
|
317
86
|
options.imports = options.imports || true;
|
|
318
87
|
return {
|
|
@@ -350,7 +119,7 @@ const UseSeoMetaTransform = unplugin.createUnplugin((options = {}) => {
|
|
|
350
119
|
const ast = this.parse(code);
|
|
351
120
|
const s = new MagicString__default(code);
|
|
352
121
|
const extraImports = /* @__PURE__ */ new Set();
|
|
353
|
-
walk(ast, {
|
|
122
|
+
estreeWalker.walk(ast, {
|
|
354
123
|
enter(_node) {
|
|
355
124
|
if (options.imports && _node.type === "ImportDeclaration" && packages.includes(_node.source.value)) {
|
|
356
125
|
const node = _node;
|
|
@@ -4,6 +4,7 @@ import { createUnplugin } from 'unplugin';
|
|
|
4
4
|
import { transform } from 'unplugin-ast';
|
|
5
5
|
import { createContext, runInContext } from 'node:vm';
|
|
6
6
|
import { resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue } from '@unhead/shared';
|
|
7
|
+
import { walk } from 'estree-walker';
|
|
7
8
|
import MagicString from 'magic-string';
|
|
8
9
|
import { findStaticImports, parseStaticImport } from 'mlly';
|
|
9
10
|
|
|
@@ -16,7 +17,7 @@ function RemoveFunctions(functionNames) {
|
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
const TreeshakeServerComposables = createUnplugin((options = {}) => {
|
|
19
|
-
options.enabled = options.enabled !==
|
|
20
|
+
options.enabled = options.enabled !== undefined ? options.enabled : true;
|
|
20
21
|
return {
|
|
21
22
|
name: "unhead:remove-server-composables",
|
|
22
23
|
enforce: "post",
|
|
@@ -55,7 +56,7 @@ const TreeshakeServerComposables = createUnplugin((options = {}) => {
|
|
|
55
56
|
])
|
|
56
57
|
]
|
|
57
58
|
});
|
|
58
|
-
} catch
|
|
59
|
+
} catch {
|
|
59
60
|
}
|
|
60
61
|
return transformed;
|
|
61
62
|
},
|
|
@@ -75,238 +76,6 @@ const TreeshakeServerComposables = createUnplugin((options = {}) => {
|
|
|
75
76
|
};
|
|
76
77
|
});
|
|
77
78
|
|
|
78
|
-
/**
|
|
79
|
-
* @typedef { import('estree').Node} Node
|
|
80
|
-
* @typedef {{
|
|
81
|
-
* skip: () => void;
|
|
82
|
-
* remove: () => void;
|
|
83
|
-
* replace: (node: Node) => void;
|
|
84
|
-
* }} WalkerContext
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
class WalkerBase {
|
|
88
|
-
constructor() {
|
|
89
|
-
/** @type {boolean} */
|
|
90
|
-
this.should_skip = false;
|
|
91
|
-
|
|
92
|
-
/** @type {boolean} */
|
|
93
|
-
this.should_remove = false;
|
|
94
|
-
|
|
95
|
-
/** @type {Node | null} */
|
|
96
|
-
this.replacement = null;
|
|
97
|
-
|
|
98
|
-
/** @type {WalkerContext} */
|
|
99
|
-
this.context = {
|
|
100
|
-
skip: () => (this.should_skip = true),
|
|
101
|
-
remove: () => (this.should_remove = true),
|
|
102
|
-
replace: (node) => (this.replacement = node)
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* @template {Node} Parent
|
|
108
|
-
* @param {Parent | null | undefined} parent
|
|
109
|
-
* @param {keyof Parent | null | undefined} prop
|
|
110
|
-
* @param {number | null | undefined} index
|
|
111
|
-
* @param {Node} node
|
|
112
|
-
*/
|
|
113
|
-
replace(parent, prop, index, node) {
|
|
114
|
-
if (parent && prop) {
|
|
115
|
-
if (index != null) {
|
|
116
|
-
/** @type {Array<Node>} */ (parent[prop])[index] = node;
|
|
117
|
-
} else {
|
|
118
|
-
/** @type {Node} */ (parent[prop]) = node;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* @template {Node} Parent
|
|
125
|
-
* @param {Parent | null | undefined} parent
|
|
126
|
-
* @param {keyof Parent | null | undefined} prop
|
|
127
|
-
* @param {number | null | undefined} index
|
|
128
|
-
*/
|
|
129
|
-
remove(parent, prop, index) {
|
|
130
|
-
if (parent && prop) {
|
|
131
|
-
if (index !== null && index !== undefined) {
|
|
132
|
-
/** @type {Array<Node>} */ (parent[prop]).splice(index, 1);
|
|
133
|
-
} else {
|
|
134
|
-
delete parent[prop];
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @typedef { import('estree').Node} Node
|
|
142
|
-
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
|
143
|
-
* @typedef {(
|
|
144
|
-
* this: WalkerContext,
|
|
145
|
-
* node: Node,
|
|
146
|
-
* parent: Node | null,
|
|
147
|
-
* key: string | number | symbol | null | undefined,
|
|
148
|
-
* index: number | null | undefined
|
|
149
|
-
* ) => void} SyncHandler
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
class SyncWalker extends WalkerBase {
|
|
153
|
-
/**
|
|
154
|
-
*
|
|
155
|
-
* @param {SyncHandler} [enter]
|
|
156
|
-
* @param {SyncHandler} [leave]
|
|
157
|
-
*/
|
|
158
|
-
constructor(enter, leave) {
|
|
159
|
-
super();
|
|
160
|
-
|
|
161
|
-
/** @type {boolean} */
|
|
162
|
-
this.should_skip = false;
|
|
163
|
-
|
|
164
|
-
/** @type {boolean} */
|
|
165
|
-
this.should_remove = false;
|
|
166
|
-
|
|
167
|
-
/** @type {Node | null} */
|
|
168
|
-
this.replacement = null;
|
|
169
|
-
|
|
170
|
-
/** @type {WalkerContext} */
|
|
171
|
-
this.context = {
|
|
172
|
-
skip: () => (this.should_skip = true),
|
|
173
|
-
remove: () => (this.should_remove = true),
|
|
174
|
-
replace: (node) => (this.replacement = node)
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/** @type {SyncHandler | undefined} */
|
|
178
|
-
this.enter = enter;
|
|
179
|
-
|
|
180
|
-
/** @type {SyncHandler | undefined} */
|
|
181
|
-
this.leave = leave;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* @template {Node} Parent
|
|
186
|
-
* @param {Node} node
|
|
187
|
-
* @param {Parent | null} parent
|
|
188
|
-
* @param {keyof Parent} [prop]
|
|
189
|
-
* @param {number | null} [index]
|
|
190
|
-
* @returns {Node | null}
|
|
191
|
-
*/
|
|
192
|
-
visit(node, parent, prop, index) {
|
|
193
|
-
if (node) {
|
|
194
|
-
if (this.enter) {
|
|
195
|
-
const _should_skip = this.should_skip;
|
|
196
|
-
const _should_remove = this.should_remove;
|
|
197
|
-
const _replacement = this.replacement;
|
|
198
|
-
this.should_skip = false;
|
|
199
|
-
this.should_remove = false;
|
|
200
|
-
this.replacement = null;
|
|
201
|
-
|
|
202
|
-
this.enter.call(this.context, node, parent, prop, index);
|
|
203
|
-
|
|
204
|
-
if (this.replacement) {
|
|
205
|
-
node = this.replacement;
|
|
206
|
-
this.replace(parent, prop, index, node);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (this.should_remove) {
|
|
210
|
-
this.remove(parent, prop, index);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const skipped = this.should_skip;
|
|
214
|
-
const removed = this.should_remove;
|
|
215
|
-
|
|
216
|
-
this.should_skip = _should_skip;
|
|
217
|
-
this.should_remove = _should_remove;
|
|
218
|
-
this.replacement = _replacement;
|
|
219
|
-
|
|
220
|
-
if (skipped) return node;
|
|
221
|
-
if (removed) return null;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** @type {keyof Node} */
|
|
225
|
-
let key;
|
|
226
|
-
|
|
227
|
-
for (key in node) {
|
|
228
|
-
/** @type {unknown} */
|
|
229
|
-
const value = node[key];
|
|
230
|
-
|
|
231
|
-
if (value && typeof value === 'object') {
|
|
232
|
-
if (Array.isArray(value)) {
|
|
233
|
-
const nodes = /** @type {Array<unknown>} */ (value);
|
|
234
|
-
for (let i = 0; i < nodes.length; i += 1) {
|
|
235
|
-
const item = nodes[i];
|
|
236
|
-
if (isNode(item)) {
|
|
237
|
-
if (!this.visit(item, node, key, i)) {
|
|
238
|
-
// removed
|
|
239
|
-
i--;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
} else if (isNode(value)) {
|
|
244
|
-
this.visit(value, node, key, null);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (this.leave) {
|
|
250
|
-
const _replacement = this.replacement;
|
|
251
|
-
const _should_remove = this.should_remove;
|
|
252
|
-
this.replacement = null;
|
|
253
|
-
this.should_remove = false;
|
|
254
|
-
|
|
255
|
-
this.leave.call(this.context, node, parent, prop, index);
|
|
256
|
-
|
|
257
|
-
if (this.replacement) {
|
|
258
|
-
node = this.replacement;
|
|
259
|
-
this.replace(parent, prop, index, node);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (this.should_remove) {
|
|
263
|
-
this.remove(parent, prop, index);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const removed = this.should_remove;
|
|
267
|
-
|
|
268
|
-
this.replacement = _replacement;
|
|
269
|
-
this.should_remove = _should_remove;
|
|
270
|
-
|
|
271
|
-
if (removed) return null;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return node;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Ducktype a node.
|
|
281
|
-
*
|
|
282
|
-
* @param {unknown} value
|
|
283
|
-
* @returns {value is Node}
|
|
284
|
-
*/
|
|
285
|
-
function isNode(value) {
|
|
286
|
-
return (
|
|
287
|
-
value !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* @typedef {import('estree').Node} Node
|
|
293
|
-
* @typedef {import('./sync.js').SyncHandler} SyncHandler
|
|
294
|
-
* @typedef {import('./async.js').AsyncHandler} AsyncHandler
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* @param {Node} ast
|
|
299
|
-
* @param {{
|
|
300
|
-
* enter?: SyncHandler
|
|
301
|
-
* leave?: SyncHandler
|
|
302
|
-
* }} walker
|
|
303
|
-
* @returns {Node | null}
|
|
304
|
-
*/
|
|
305
|
-
function walk(ast, { enter, leave }) {
|
|
306
|
-
const instance = new SyncWalker(enter, leave);
|
|
307
|
-
return instance.visit(ast, null);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
79
|
const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
311
80
|
options.imports = options.imports || true;
|
|
312
81
|
return {
|
package/dist/vite.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const UseSeoMetaTransform = require('./shared/addons.
|
|
3
|
+
const UseSeoMetaTransform = require('./shared/addons.By35C-fR.cjs');
|
|
4
4
|
require('node:url');
|
|
5
5
|
require('ufo');
|
|
6
6
|
require('unplugin');
|
|
7
7
|
require('unplugin-ast');
|
|
8
8
|
require('node:vm');
|
|
9
9
|
require('@unhead/shared');
|
|
10
|
+
require('estree-walker');
|
|
10
11
|
require('magic-string');
|
|
11
12
|
require('mlly');
|
|
12
13
|
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.mts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.
|
|
1
|
+
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.CmryBgzY.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
7
|
import '@unhead/shared';
|
|
8
|
+
import 'estree-walker';
|
|
8
9
|
import 'magic-string';
|
|
9
10
|
import 'mlly';
|
|
10
11
|
|
package/dist/webpack.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const UseSeoMetaTransform = require('./shared/addons.
|
|
3
|
+
const UseSeoMetaTransform = require('./shared/addons.By35C-fR.cjs');
|
|
4
4
|
require('node:url');
|
|
5
5
|
require('ufo');
|
|
6
6
|
require('unplugin');
|
|
7
7
|
require('unplugin-ast');
|
|
8
8
|
require('node:vm');
|
|
9
9
|
require('@unhead/shared');
|
|
10
|
+
require('estree-walker');
|
|
10
11
|
require('magic-string');
|
|
11
12
|
require('mlly');
|
|
12
13
|
|
package/dist/webpack.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.
|
|
2
|
+
import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.cjs';
|
|
3
3
|
|
|
4
4
|
declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
|
|
5
5
|
|
package/dist/webpack.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.
|
|
2
|
+
import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.mjs';
|
|
3
3
|
|
|
4
4
|
declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
|
|
5
5
|
|
package/dist/webpack.d.ts
CHANGED
package/dist/webpack.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.
|
|
1
|
+
import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.CmryBgzY.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
7
|
import '@unhead/shared';
|
|
8
|
+
import 'estree-walker';
|
|
8
9
|
import 'magic-string';
|
|
9
10
|
import 'mlly';
|
|
10
11
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/addons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-alpha.0",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -48,23 +48,25 @@
|
|
|
48
48
|
"files": [
|
|
49
49
|
"dist"
|
|
50
50
|
],
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"unhead": "2.0.0-alpha.0"
|
|
53
|
+
},
|
|
51
54
|
"dependencies": {
|
|
52
|
-
"@rollup/pluginutils": "^5.1.
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
+
"@rollup/pluginutils": "^5.1.4",
|
|
56
|
+
"estree-walker": "^3.0.3",
|
|
57
|
+
"magic-string": "^0.30.17",
|
|
58
|
+
"mlly": "^1.7.4",
|
|
55
59
|
"ufo": "^1.5.4",
|
|
56
|
-
"unplugin": "^1.
|
|
57
|
-
"unplugin-ast": "^0.
|
|
58
|
-
"@unhead/
|
|
59
|
-
"@unhead/
|
|
60
|
+
"unplugin": "^2.1.2",
|
|
61
|
+
"unplugin-ast": "^0.13.1",
|
|
62
|
+
"@unhead/schema": "2.0.0-alpha.0",
|
|
63
|
+
"@unhead/shared": "2.0.0-alpha.0"
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
|
-
"@babel/types": "^7.26.
|
|
63
|
-
"estree-walker": "^3.0.3"
|
|
66
|
+
"@babel/types": "^7.26.5"
|
|
64
67
|
},
|
|
65
68
|
"scripts": {
|
|
66
69
|
"build": "unbuild .",
|
|
67
|
-
"stub": "unbuild . --stub"
|
|
68
|
-
"export:sizes": "npx export-size . -r"
|
|
70
|
+
"stub": "unbuild . --stub"
|
|
69
71
|
}
|
|
70
72
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|