@unhead/addons 2.0.0-alpha.2 → 2.0.0-alpha.20
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.Bh7ZeIPm.d.ts → addons.ChoDmUFv.d.mts} +2 -7
- package/dist/shared/{addons.Bh7ZeIPm.d.cts → addons.ChoDmUFv.d.ts} +2 -7
- package/dist/shared/{addons.CmryBgzY.mjs → addons.DMDJAAwv.mjs} +9 -5
- package/dist/vite.d.mts +3 -1
- package/dist/vite.d.ts +3 -1
- package/dist/vite.mjs +2 -2
- package/dist/webpack.d.mts +3 -1
- package/dist/webpack.d.ts +3 -1
- 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.Bh7ZeIPm.d.mts +0 -21
- package/dist/shared/addons.By35C-fR.cjs +0 -232
- package/dist/vite.cjs +0 -21
- package/dist/vite.d.cts +0 -6
- package/dist/webpack.cjs +0 -21
- package/dist/webpack.d.cts +0 -6
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
interface UseSeoMetaTransformOptions extends BaseTransformerTypes {
|
|
6
|
-
imports?: boolean;
|
|
7
|
-
}
|
|
1
|
+
import { TreeshakeServerComposablesOptions } from '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
2
|
+
import { UseSeoMetaTransformOptions } from '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
8
3
|
|
|
9
4
|
interface BaseTransformerTypes {
|
|
10
5
|
sourcemap?: boolean;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
interface UseSeoMetaTransformOptions extends BaseTransformerTypes {
|
|
6
|
-
imports?: boolean;
|
|
7
|
-
}
|
|
1
|
+
import { TreeshakeServerComposablesOptions } from '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
2
|
+
import { UseSeoMetaTransformOptions } from '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
8
3
|
|
|
9
4
|
interface BaseTransformerTypes {
|
|
10
5
|
sourcemap?: boolean;
|
|
@@ -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",
|
|
@@ -99,7 +99,7 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
99
99
|
async transform(code, id) {
|
|
100
100
|
if (!code.includes("useSeoMeta") && !code.includes("useServerSeoMeta"))
|
|
101
101
|
return;
|
|
102
|
-
const packages = ["unhead", "@unhead/vue", "unhead"];
|
|
102
|
+
const packages = ["unhead", "@unhead/vue", "@unhead/react"];
|
|
103
103
|
const statements = findStaticImports(code).filter((i) => packages.includes(i.specifier));
|
|
104
104
|
const importNames = {};
|
|
105
105
|
for (const i of statements.flatMap((i2) => parseStaticImport(i2))) {
|
|
@@ -169,9 +169,13 @@ const UseSeoMetaTransform = createUnplugin((options = {}) => {
|
|
|
169
169
|
if (output === false)
|
|
170
170
|
return;
|
|
171
171
|
const propertyKey = property.key;
|
|
172
|
-
|
|
172
|
+
let key = resolveMetaKeyType(propertyKey.name);
|
|
173
173
|
const keyValue = resolveMetaKeyValue(propertyKey.name);
|
|
174
|
-
|
|
174
|
+
let valueKey = "content";
|
|
175
|
+
if (keyValue === "charset") {
|
|
176
|
+
valueKey = "charset";
|
|
177
|
+
key = "charset";
|
|
178
|
+
}
|
|
175
179
|
let value = code.substring(property.value.start, property.value.end);
|
|
176
180
|
if (property.value.type === "ArrayExpression") {
|
|
177
181
|
output = false;
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.
|
|
2
|
+
import { U as UnpluginOptions } from './shared/addons.ChoDmUFv.mjs';
|
|
3
|
+
import '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
4
|
+
import '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
3
5
|
|
|
4
6
|
declare const _default: (options?: UnpluginOptions) => Plugin[];
|
|
5
7
|
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.
|
|
2
|
+
import { U as UnpluginOptions } from './shared/addons.ChoDmUFv.js';
|
|
3
|
+
import '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
4
|
+
import '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
3
5
|
|
|
4
6
|
declare const _default: (options?: UnpluginOptions) => Plugin[];
|
|
5
7
|
|
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.DMDJAAwv.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.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.
|
|
2
|
+
import { U as UnpluginOptions } from './shared/addons.ChoDmUFv.mjs';
|
|
3
|
+
import '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
4
|
+
import '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
3
5
|
|
|
4
6
|
declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
|
|
5
7
|
|
package/dist/webpack.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
|
-
import { U as UnpluginOptions } from './shared/addons.
|
|
2
|
+
import { U as UnpluginOptions } from './shared/addons.ChoDmUFv.js';
|
|
3
|
+
import '@unhead/addons/src/unplugin/TreeshakeServerComposables';
|
|
4
|
+
import '@unhead/addons/src/unplugin/UseSeoMetaTransform';
|
|
3
5
|
|
|
4
6
|
declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
|
|
5
7
|
|
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.DMDJAAwv.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-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.20",
|
|
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-alpha.
|
|
53
|
+
"unhead": "2.0.0-alpha.20"
|
|
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.2",
|
|
67
|
-
"@unhead/shared": "2.0.0-alpha.2"
|
|
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,21 +0,0 @@
|
|
|
1
|
-
interface TreeshakeServerComposablesOptions extends BaseTransformerTypes {
|
|
2
|
-
enabled?: boolean;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
interface UseSeoMetaTransformOptions extends BaseTransformerTypes {
|
|
6
|
-
imports?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface BaseTransformerTypes {
|
|
10
|
-
sourcemap?: boolean;
|
|
11
|
-
filter?: {
|
|
12
|
-
exclude?: RegExp[];
|
|
13
|
-
include?: RegExp[];
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
interface UnpluginOptions extends BaseTransformerTypes {
|
|
17
|
-
treeshake?: TreeshakeServerComposablesOptions;
|
|
18
|
-
transformSeoMeta?: UseSeoMetaTransformOptions;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type { UnpluginOptions as U };
|
|
@@ -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;
|
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
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