@unhead/cli 3.2.2 → 3.3.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.mjs +81 -3
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { readFile, writeFile } from 'node:fs/promises';
|
|
|
5
5
|
import MagicString from 'magic-string';
|
|
6
6
|
import { parseSync } from 'oxc-parser';
|
|
7
7
|
import { glob } from 'tinyglobby';
|
|
8
|
-
import { tagPredicates, headInputPredicates, migrationTagPredicates } from 'unhead/validate';
|
|
8
|
+
import { tagPredicates, inputShapePredicates, headInputPredicates, migrationTagPredicates } from 'unhead/validate';
|
|
9
9
|
import { walk } from 'oxc-walker';
|
|
10
10
|
import { parseHtmlForUnheadExtraction } from 'unhead/parser';
|
|
11
11
|
import { ValidatePlugin } from 'unhead/plugins';
|
|
@@ -219,6 +219,47 @@ function getKeyName$2(prop) {
|
|
|
219
219
|
return k.value;
|
|
220
220
|
return void 0;
|
|
221
221
|
}
|
|
222
|
+
function valueKind(node) {
|
|
223
|
+
const value = unwrapTS$2(node);
|
|
224
|
+
if (!value)
|
|
225
|
+
return "unknown";
|
|
226
|
+
if (value.type === "ArrayExpression")
|
|
227
|
+
return "array";
|
|
228
|
+
if (value.type === "ObjectExpression")
|
|
229
|
+
return "object";
|
|
230
|
+
if (value.type === "ArrowFunctionExpression" || value.type === "FunctionExpression")
|
|
231
|
+
return "function";
|
|
232
|
+
if (value.type === "TemplateLiteral")
|
|
233
|
+
return "string";
|
|
234
|
+
if (value.type !== "Literal")
|
|
235
|
+
return "unknown";
|
|
236
|
+
if (value.value === null)
|
|
237
|
+
return "null";
|
|
238
|
+
const kind = typeof value.value;
|
|
239
|
+
if (kind === "boolean" || kind === "number" || kind === "string")
|
|
240
|
+
return kind;
|
|
241
|
+
return "unknown";
|
|
242
|
+
}
|
|
243
|
+
function materializeInputShape(obj, context) {
|
|
244
|
+
const keys = /* @__PURE__ */ new Set();
|
|
245
|
+
const valueKinds = /* @__PURE__ */ new Map();
|
|
246
|
+
const propLocs = {};
|
|
247
|
+
for (const prop of obj.properties) {
|
|
248
|
+
const name = getKeyName$2(prop);
|
|
249
|
+
if (!name)
|
|
250
|
+
continue;
|
|
251
|
+
keys.add(name);
|
|
252
|
+
valueKinds.set(name, valueKind(prop.value));
|
|
253
|
+
propLocs[name] = { start: prop.start, end: prop.end };
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
context,
|
|
257
|
+
keys,
|
|
258
|
+
valueKinds,
|
|
259
|
+
loc: { start: obj.start, end: obj.end },
|
|
260
|
+
propLocs
|
|
261
|
+
};
|
|
262
|
+
}
|
|
222
263
|
function findProperty(obj, key) {
|
|
223
264
|
for (let i = obj.properties.length - 1; i >= 0; i--) {
|
|
224
265
|
const prop = obj.properties[i];
|
|
@@ -521,6 +562,10 @@ const HEAD_INPUT_TAG_KEYS = /* @__PURE__ */ new Set([
|
|
|
521
562
|
"noscript",
|
|
522
563
|
"style"
|
|
523
564
|
]);
|
|
565
|
+
const HEAD_INPUT_ATTR_KEYS = /* @__PURE__ */ new Set([
|
|
566
|
+
"htmlAttrs",
|
|
567
|
+
"bodyAttrs"
|
|
568
|
+
]);
|
|
524
569
|
const TS_WRAPPERS = /* @__PURE__ */ new Set(["TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion", "TSInstantiationExpression"]);
|
|
525
570
|
function unwrapTS(node) {
|
|
526
571
|
let cur = node;
|
|
@@ -714,9 +759,16 @@ function descendHeadInput(arg, name, visitor) {
|
|
|
714
759
|
return;
|
|
715
760
|
for (const prop of arg.properties) {
|
|
716
761
|
const key = getKeyName(prop);
|
|
717
|
-
if (!key
|
|
762
|
+
if (!key)
|
|
718
763
|
continue;
|
|
719
764
|
const value = unwrapTS(prop.value);
|
|
765
|
+
if (HEAD_INPUT_ATTR_KEYS.has(key)) {
|
|
766
|
+
if (value?.type === "ObjectExpression")
|
|
767
|
+
visitor.onTag?.(value, key, { inArray: false });
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
if (!HEAD_INPUT_TAG_KEYS.has(key))
|
|
771
|
+
continue;
|
|
720
772
|
if (value?.type === "ArrayExpression") {
|
|
721
773
|
for (const el of value.elements) {
|
|
722
774
|
const inner = unwrapTS(el);
|
|
@@ -754,6 +806,7 @@ const RECOMMENDED_SEVERITY = {
|
|
|
754
806
|
"deprecated-prop-hid-vmid": "error",
|
|
755
807
|
"deprecated-prop-body": "error",
|
|
756
808
|
"html-in-title": "warning",
|
|
809
|
+
"invalid-input-shape": "warning",
|
|
757
810
|
"possible-typo": "warning",
|
|
758
811
|
"non-absolute-canonical": "warning",
|
|
759
812
|
"numeric-tag-priority": "warning",
|
|
@@ -927,8 +980,28 @@ async function auditFile(filePath, source, pieces, predicateNames, shouldFix) {
|
|
|
927
980
|
for (const diag of pred(view))
|
|
928
981
|
emit(diag, input);
|
|
929
982
|
}
|
|
983
|
+
const inputContext = callee === "useSeoMeta" || callee === "useServerSeoMeta" ? "seoMeta" : "head";
|
|
984
|
+
const shape = materializeInputShape(input, inputContext);
|
|
985
|
+
for (const name of predicateNames) {
|
|
986
|
+
const pred = inputShapePredicates[name];
|
|
987
|
+
if (!pred)
|
|
988
|
+
continue;
|
|
989
|
+
for (const diag of pred(shape))
|
|
990
|
+
emit(diag, input);
|
|
991
|
+
}
|
|
930
992
|
},
|
|
931
993
|
onTag(tag, tagType, info) {
|
|
994
|
+
if (tagType === "htmlAttrs" || tagType === "bodyAttrs") {
|
|
995
|
+
const shape = materializeInputShape(tag, tagType);
|
|
996
|
+
for (const name of predicateNames) {
|
|
997
|
+
const pred = inputShapePredicates[name];
|
|
998
|
+
if (!pred)
|
|
999
|
+
continue;
|
|
1000
|
+
for (const diag of pred(shape))
|
|
1001
|
+
emit(diag, tag);
|
|
1002
|
+
}
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
932
1005
|
const view = materializeTag(tag, tagType, info.inArray);
|
|
933
1006
|
const ctx = {
|
|
934
1007
|
get importedHelpers() {
|
|
@@ -999,7 +1072,12 @@ async function runAudit(opts) {
|
|
|
999
1072
|
ignore: opts.ignore
|
|
1000
1073
|
});
|
|
1001
1074
|
const shouldFix = opts.mode === "migrate";
|
|
1002
|
-
const
|
|
1075
|
+
const recommendedPredicates = [
|
|
1076
|
+
...Object.keys(tagPredicates),
|
|
1077
|
+
...Object.keys(inputShapePredicates),
|
|
1078
|
+
...Object.keys(headInputPredicates)
|
|
1079
|
+
];
|
|
1080
|
+
const predicateNames = opts.mode === "migrate" ? [...recommendedPredicates, ...Object.keys(migrationTagPredicates)] : recommendedPredicates;
|
|
1003
1081
|
const results = [];
|
|
1004
1082
|
const allGraphs = [];
|
|
1005
1083
|
const pageFiles = [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"description": "CLI for auditing and migrating unhead head usage in your codebase.",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"citty": "^0.2.2",
|
|
49
|
-
"magic-string": "^1.
|
|
50
|
-
"oxc-parser": "^0.
|
|
51
|
-
"oxc-walker": "^1.
|
|
49
|
+
"magic-string": "^1.1.0",
|
|
50
|
+
"oxc-parser": "^0.142.0",
|
|
51
|
+
"oxc-walker": "^1.1.1",
|
|
52
52
|
"pathe": "^2.0.3",
|
|
53
53
|
"tinyglobby": "^0.2.17",
|
|
54
|
-
"unhead": "3.
|
|
54
|
+
"unhead": "3.3.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"vitest": "^4.1.10"
|