@vizejs/nuxt 0.775.0 → 0.777.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 +1 -1
- package/dist/lint/index.d.mts +3 -1
- package/dist/lint/index.mjs +1 -1
- package/dist/plugin-host-1EkMFIOn.mjs +2 -0
- package/dist/plugin-plan-CisluFXw.mjs +717 -0
- package/dist/plugin-tools-UYf8FWuq.mjs +127 -0
- package/dist/{setup-CA6DHcgG.mjs → setup-DsbpyMZt.mjs} +215 -12
- package/package.json +7 -7
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
//#region ../../../crates/vize_carton/src/config/loader/plugin-canonical.js
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
var VizePluginPlanError = class extends Error {
|
|
5
|
+
constructor(code, subject, message) {
|
|
6
|
+
super(`[plugin/${code}] ${subject}: ${message}`);
|
|
7
|
+
this.name = "VizePluginPlanError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.subject = subject;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Normalize authored data to canonical JSON values: plain objects, arrays,
|
|
14
|
+
* strings, booleans, null and safe integers. Object members whose value is
|
|
15
|
+
* `undefined` are omitted, as in JSON; everything else fails closed.
|
|
16
|
+
*/
|
|
17
|
+
function canonicalData(value, subject, path, code = "options-invalid") {
|
|
18
|
+
const parents = /* @__PURE__ */ new Set();
|
|
19
|
+
const visit = (current, at) => {
|
|
20
|
+
if (current === null || typeof current === "boolean") return current;
|
|
21
|
+
if (typeof current === "string") {
|
|
22
|
+
if (!current.isWellFormed()) throw new VizePluginPlanError(code, subject, `${at} contains a lone surrogate`);
|
|
23
|
+
return current;
|
|
24
|
+
}
|
|
25
|
+
if (typeof current === "number") {
|
|
26
|
+
if (!Number.isSafeInteger(current)) throw new VizePluginPlanError(code, subject, `${at} must be a safe integer; pass other numbers as strings`);
|
|
27
|
+
return current === 0 ? 0 : current;
|
|
28
|
+
}
|
|
29
|
+
if (typeof current !== "object") throw new VizePluginPlanError(code, subject, `${at} is not canonical JSON data`);
|
|
30
|
+
if (parents.has(current)) throw new VizePluginPlanError(code, subject, `${at} contains a cycle`);
|
|
31
|
+
parents.add(current);
|
|
32
|
+
try {
|
|
33
|
+
if (Array.isArray(current)) return Array.from({ length: current.length }, (_, index) => {
|
|
34
|
+
if (!Object.hasOwn(current, index) || current[index] === void 0) throw new VizePluginPlanError(code, subject, `${at}[${index}] is undefined`);
|
|
35
|
+
return visit(current[index], `${at}[${index}]`);
|
|
36
|
+
});
|
|
37
|
+
const prototype = Object.getPrototypeOf(current);
|
|
38
|
+
if (prototype !== Object.prototype && prototype !== null) throw new VizePluginPlanError(code, subject, `${at} must be a plain object`);
|
|
39
|
+
if (Object.getOwnPropertySymbols(current).length !== 0) throw new VizePluginPlanError(code, subject, `${at} has symbol keys`);
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const key of sortedKeys(current)) {
|
|
42
|
+
if (!key.isWellFormed()) throw new VizePluginPlanError(code, subject, `${at} has a key with a lone surrogate`);
|
|
43
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
44
|
+
if (descriptor.get || descriptor.set) throw new VizePluginPlanError(code, subject, `${at}.${key} is an accessor`);
|
|
45
|
+
if (descriptor.value === void 0) continue;
|
|
46
|
+
result[key] = visit(descriptor.value, `${at}.${key}`);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
} finally {
|
|
50
|
+
parents.delete(current);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return visit(value, path);
|
|
54
|
+
}
|
|
55
|
+
/** Object keys in Unicode code point order (UTF-8 byte order), like the native verifier. */
|
|
56
|
+
function sortedKeys(object) {
|
|
57
|
+
return Object.keys(object).sort(compareCodePoints);
|
|
58
|
+
}
|
|
59
|
+
function compareCodePoints(left, right) {
|
|
60
|
+
const a = encoder.encode(left);
|
|
61
|
+
const b = encoder.encode(right);
|
|
62
|
+
const length = Math.min(a.length, b.length);
|
|
63
|
+
for (let index = 0; index < length; index++) if (a[index] !== b[index]) return a[index] - b[index];
|
|
64
|
+
return a.length - b.length;
|
|
65
|
+
}
|
|
66
|
+
/** Serialize canonical data without whitespace, with sorted keys. */
|
|
67
|
+
function canonicalJson(value) {
|
|
68
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
69
|
+
if (value !== null && typeof value === "object") return `{${sortedKeys(value).map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`;
|
|
70
|
+
return JSON.stringify(value);
|
|
71
|
+
}
|
|
72
|
+
function digestOf(json) {
|
|
73
|
+
return createHash("sha256").update(json).digest("hex");
|
|
74
|
+
}
|
|
75
|
+
function deepFreeze(value) {
|
|
76
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
77
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
78
|
+
Object.freeze(value);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region ../../../crates/vize_carton/src/config/loader/plugin-registry.json
|
|
84
|
+
var lintDocuments = ["template"];
|
|
85
|
+
var recordKinds = [
|
|
86
|
+
"ui.element",
|
|
87
|
+
"ui.component",
|
|
88
|
+
"ui.text",
|
|
89
|
+
"ui.interpolation",
|
|
90
|
+
"ui.comment",
|
|
91
|
+
"ui.if",
|
|
92
|
+
"ui.for",
|
|
93
|
+
"ui.slot",
|
|
94
|
+
"ui.bind",
|
|
95
|
+
"ui.on",
|
|
96
|
+
"ui.model",
|
|
97
|
+
"ui.slot-content",
|
|
98
|
+
"vue.directive",
|
|
99
|
+
"vue.css-bind",
|
|
100
|
+
"vue.sync",
|
|
101
|
+
"vue.slot-scope",
|
|
102
|
+
"vue.once",
|
|
103
|
+
"vue.memo",
|
|
104
|
+
"vue.show",
|
|
105
|
+
"vue.html",
|
|
106
|
+
"vue.text",
|
|
107
|
+
"vue.cloak"
|
|
108
|
+
];
|
|
109
|
+
var factGroups = [
|
|
110
|
+
"templateScopes",
|
|
111
|
+
"bindings",
|
|
112
|
+
"undefined-refs",
|
|
113
|
+
"component-usages",
|
|
114
|
+
"reactivity",
|
|
115
|
+
"provide-inject",
|
|
116
|
+
"race-conditions",
|
|
117
|
+
"unused-bindings",
|
|
118
|
+
"component-signature",
|
|
119
|
+
"prop-types",
|
|
120
|
+
"emit-types",
|
|
121
|
+
"slot-types",
|
|
122
|
+
"reactivity-classes",
|
|
123
|
+
"component-references"
|
|
124
|
+
];
|
|
125
|
+
var reservedDirectives = [
|
|
126
|
+
"bind",
|
|
127
|
+
"cloak",
|
|
128
|
+
"else",
|
|
129
|
+
"else-if",
|
|
130
|
+
"for",
|
|
131
|
+
"html",
|
|
132
|
+
"if",
|
|
133
|
+
"is",
|
|
134
|
+
"memo",
|
|
135
|
+
"model",
|
|
136
|
+
"on",
|
|
137
|
+
"once",
|
|
138
|
+
"pre",
|
|
139
|
+
"show",
|
|
140
|
+
"slot",
|
|
141
|
+
"text"
|
|
142
|
+
];
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region ../../../crates/vize_carton/src/config/loader/plugin-capabilities.js
|
|
145
|
+
const PLUGIN_REGISTRY = {
|
|
146
|
+
planSchema: 1,
|
|
147
|
+
apiVersions: [1, 2],
|
|
148
|
+
products: [
|
|
149
|
+
"compiler",
|
|
150
|
+
"typecheck",
|
|
151
|
+
"lint",
|
|
152
|
+
"format",
|
|
153
|
+
"lsp"
|
|
154
|
+
],
|
|
155
|
+
backends: [
|
|
156
|
+
"js",
|
|
157
|
+
"native",
|
|
158
|
+
"wasm"
|
|
159
|
+
],
|
|
160
|
+
admittedBackends: ["js"],
|
|
161
|
+
capabilities: {
|
|
162
|
+
"lint.plugin-v1": {
|
|
163
|
+
"schemaVersions": [1],
|
|
164
|
+
"apiVersions": [1],
|
|
165
|
+
"consumers": ["lint", "lsp"],
|
|
166
|
+
"callbacks": ["run"],
|
|
167
|
+
"admittedBy": ["lint", "lsp"]
|
|
168
|
+
},
|
|
169
|
+
"lint.rule": {
|
|
170
|
+
"schemaVersions": [1],
|
|
171
|
+
"apiVersions": [2],
|
|
172
|
+
"consumers": ["lint", "lsp"],
|
|
173
|
+
"callbacks": ["run"],
|
|
174
|
+
"admittedBy": ["lint", "lsp"]
|
|
175
|
+
},
|
|
176
|
+
"sfc.custom-block": {
|
|
177
|
+
"schemaVersions": [1],
|
|
178
|
+
"apiVersions": [2],
|
|
179
|
+
"consumers": [
|
|
180
|
+
"compiler",
|
|
181
|
+
"typecheck",
|
|
182
|
+
"lint",
|
|
183
|
+
"format",
|
|
184
|
+
"lsp"
|
|
185
|
+
],
|
|
186
|
+
"callbacks": [],
|
|
187
|
+
"admittedBy": []
|
|
188
|
+
},
|
|
189
|
+
"vue.directive": {
|
|
190
|
+
"schemaVersions": [1],
|
|
191
|
+
"apiVersions": [2],
|
|
192
|
+
"consumers": [
|
|
193
|
+
"compiler",
|
|
194
|
+
"typecheck",
|
|
195
|
+
"lint",
|
|
196
|
+
"lsp"
|
|
197
|
+
],
|
|
198
|
+
"callbacks": [],
|
|
199
|
+
"admittedBy": ["lint", "lsp"]
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
lintDocuments,
|
|
203
|
+
recordKinds,
|
|
204
|
+
factGroups,
|
|
205
|
+
reservedDirectives
|
|
206
|
+
};
|
|
207
|
+
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
208
|
+
const MESSAGE_ID = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
209
|
+
const LEVELS = [
|
|
210
|
+
"off",
|
|
211
|
+
"warn",
|
|
212
|
+
"error"
|
|
213
|
+
];
|
|
214
|
+
const FIXABLE = [
|
|
215
|
+
"none",
|
|
216
|
+
"safe",
|
|
217
|
+
"unsafe"
|
|
218
|
+
];
|
|
219
|
+
/** Normalize one capability's data; `data` is already canonical JSON. */
|
|
220
|
+
function normalizeCapability(plugin, capability) {
|
|
221
|
+
const where = `${plugin.name} ${capability.id}`;
|
|
222
|
+
const normalize = NORMALIZERS[capability.id];
|
|
223
|
+
return normalize(plugin, capability.data, where);
|
|
224
|
+
}
|
|
225
|
+
const NORMALIZERS = {
|
|
226
|
+
"lint.plugin-v1"(plugin, data, where) {
|
|
227
|
+
fields(data, where, [
|
|
228
|
+
"demands",
|
|
229
|
+
"rules",
|
|
230
|
+
"visit"
|
|
231
|
+
], [
|
|
232
|
+
"demands",
|
|
233
|
+
"rules",
|
|
234
|
+
"visit"
|
|
235
|
+
]);
|
|
236
|
+
const visit = data.visit === null ? null : kinds(data.visit, `${where} visit`, { allowEmpty: true });
|
|
237
|
+
const rules = strings(data.rules, `${where} rules`, { unique: true });
|
|
238
|
+
if (rules.length === 0) invalid(where, "a v1 plugin needs at least one rule");
|
|
239
|
+
return {
|
|
240
|
+
key: plugin.name,
|
|
241
|
+
data: {
|
|
242
|
+
demands: facts(data.demands, `${where} demands`),
|
|
243
|
+
rules,
|
|
244
|
+
visit
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
"lint.rule"(plugin, data, where) {
|
|
249
|
+
fields(data, where, [
|
|
250
|
+
"defaultLevel",
|
|
251
|
+
"demands",
|
|
252
|
+
"docs",
|
|
253
|
+
"documents",
|
|
254
|
+
"fixable",
|
|
255
|
+
"id",
|
|
256
|
+
"messages",
|
|
257
|
+
"visit"
|
|
258
|
+
], [
|
|
259
|
+
"id",
|
|
260
|
+
"messages",
|
|
261
|
+
"visit"
|
|
262
|
+
]);
|
|
263
|
+
const id = kebab(data.id, `${where} id`);
|
|
264
|
+
const messages = record(data.messages, `${where} messages`);
|
|
265
|
+
const ids = Object.keys(messages);
|
|
266
|
+
if (ids.length === 0) invalid(where, "messages must declare at least one message id");
|
|
267
|
+
for (const messageId of ids) {
|
|
268
|
+
if (!MESSAGE_ID.test(messageId)) invalid(where, `message id \`${messageId}\` is invalid`);
|
|
269
|
+
if (typeof messages[messageId] !== "string" || messages[messageId] === "") invalid(where, `message \`${messageId}\` must be a non-empty string`);
|
|
270
|
+
}
|
|
271
|
+
const documents = strings(data.documents ?? ["template"], `${where} documents`, {
|
|
272
|
+
unique: true,
|
|
273
|
+
sorted: true
|
|
274
|
+
});
|
|
275
|
+
for (const document of documents) if (!lintDocuments.includes(document)) invalid(where, `document domain \`${document}\` is not available in schema 1`);
|
|
276
|
+
if (documents.length === 0) invalid(where, "documents must not be empty");
|
|
277
|
+
return {
|
|
278
|
+
key: `${plugin.name}/${id}`,
|
|
279
|
+
data: {
|
|
280
|
+
defaultLevel: oneOf(data.defaultLevel ?? "off", LEVELS, `${where} defaultLevel`),
|
|
281
|
+
demands: facts(data.demands ?? [], `${where} demands`),
|
|
282
|
+
docs: text(data.docs ?? "", `${where} docs`),
|
|
283
|
+
documents,
|
|
284
|
+
fixable: oneOf(data.fixable ?? "none", FIXABLE, `${where} fixable`),
|
|
285
|
+
id,
|
|
286
|
+
messages,
|
|
287
|
+
visit: kinds(data.visit, `${where} visit`, { allowEmpty: false })
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
"sfc.custom-block"(_plugin, data, where) {
|
|
292
|
+
fields(data, where, ["lang", "type"], ["type"]);
|
|
293
|
+
const type = kebab(data.type, `${where} type`);
|
|
294
|
+
if ([
|
|
295
|
+
"template",
|
|
296
|
+
"script",
|
|
297
|
+
"style"
|
|
298
|
+
].includes(type)) invalid(where, `\`${type}\` is a core SFC block`);
|
|
299
|
+
const lang = data.lang === void 0 ? void 0 : kebab(data.lang, `${where} lang`);
|
|
300
|
+
return {
|
|
301
|
+
key: lang === void 0 ? type : `${type}:${lang}`,
|
|
302
|
+
data: lang === void 0 ? { type } : {
|
|
303
|
+
lang,
|
|
304
|
+
type
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
},
|
|
308
|
+
"vue.directive"(_plugin, data, where) {
|
|
309
|
+
fields(data, where, ["modifiers", "name"], ["name"]);
|
|
310
|
+
const name = kebab(data.name, `${where} name`);
|
|
311
|
+
if (reservedDirectives.includes(name)) invalid(where, `v-${name} is a built-in Vue directive`);
|
|
312
|
+
const modifiers = {};
|
|
313
|
+
for (const [modifier, contract] of Object.entries(record(data.modifiers ?? {}, `${where} modifiers`))) {
|
|
314
|
+
const at = `${where} modifier \`${modifier}\``;
|
|
315
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(modifier)) invalid(at, "has an invalid name");
|
|
316
|
+
fields(record(contract, at), at, ["default", "optional"], []);
|
|
317
|
+
const optional = boolean(contract.optional ?? true, `${at} optional`);
|
|
318
|
+
if (!optional && contract.default !== void 0) invalid(at, "is required and cannot declare a default");
|
|
319
|
+
modifiers[modifier] = {
|
|
320
|
+
default: boolean(contract.default ?? false, `${at} default`),
|
|
321
|
+
optional
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
key: name,
|
|
326
|
+
data: {
|
|
327
|
+
modifiers,
|
|
328
|
+
name
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
function claimKey(capabilityId, key) {
|
|
334
|
+
return `${capabilityId}:${key}`;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Exclusive owners. Exact keys conflict; a custom block claimed for every
|
|
338
|
+
* language also conflicts with the same block claimed for one language.
|
|
339
|
+
*/
|
|
340
|
+
function ownershipConflict(claims) {
|
|
341
|
+
const owners = /* @__PURE__ */ new Map();
|
|
342
|
+
for (const claim of claims) {
|
|
343
|
+
const previous = owners.get(claim.key);
|
|
344
|
+
if (previous) return [previous, claim];
|
|
345
|
+
owners.set(claim.key, claim);
|
|
346
|
+
}
|
|
347
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
348
|
+
for (const claim of claims) {
|
|
349
|
+
const match = /^sfc\.custom-block:([^:]+)(?::(.+))?$/.exec(claim.key);
|
|
350
|
+
if (!match) continue;
|
|
351
|
+
const entry = blocks.get(match[1]) ?? {
|
|
352
|
+
any: void 0,
|
|
353
|
+
langs: []
|
|
354
|
+
};
|
|
355
|
+
if (match[2] === void 0) entry.any = claim;
|
|
356
|
+
else entry.langs.push(claim);
|
|
357
|
+
blocks.set(match[1], entry);
|
|
358
|
+
if (entry.any && entry.langs.length > 0) return [entry.any, entry.langs[0]];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function fields(data, where, known, required) {
|
|
362
|
+
record(data, where);
|
|
363
|
+
for (const key of Object.keys(data)) if (!known.includes(key)) invalid(where, `unknown field \`${key}\``);
|
|
364
|
+
for (const key of required) if (data[key] === void 0) invalid(where, `missing field \`${key}\``);
|
|
365
|
+
}
|
|
366
|
+
function record(value, where) {
|
|
367
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) invalid(where, "must be an object");
|
|
368
|
+
return value;
|
|
369
|
+
}
|
|
370
|
+
function strings(value, where, { unique = false, sorted = false } = {}) {
|
|
371
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry === "")) invalid(where, "must be an array of non-empty strings");
|
|
372
|
+
if (unique && new Set(value).size !== value.length) invalid(where, "contains duplicates");
|
|
373
|
+
return sorted ? [...value].sort(compareCodePoints) : value;
|
|
374
|
+
}
|
|
375
|
+
function kinds(value, where, { allowEmpty }) {
|
|
376
|
+
const list = strings(value, where, {
|
|
377
|
+
unique: true,
|
|
378
|
+
sorted: true
|
|
379
|
+
});
|
|
380
|
+
if (!allowEmpty && list.length === 0) invalid(where, "must visit at least one record kind");
|
|
381
|
+
for (const kind of list) if (!recordKinds.includes(kind)) invalid(where, `unknown record kind \`${kind}\``);
|
|
382
|
+
return list;
|
|
383
|
+
}
|
|
384
|
+
function facts(value, where) {
|
|
385
|
+
const list = strings(value, where, {
|
|
386
|
+
unique: true,
|
|
387
|
+
sorted: true
|
|
388
|
+
});
|
|
389
|
+
for (const fact of list) if (!factGroups.includes(fact)) invalid(where, `unknown fact group \`${fact}\``);
|
|
390
|
+
return list;
|
|
391
|
+
}
|
|
392
|
+
function kebab(value, where) {
|
|
393
|
+
if (typeof value !== "string" || !KEBAB.test(value)) invalid(where, "must be kebab-case");
|
|
394
|
+
return value;
|
|
395
|
+
}
|
|
396
|
+
function text(value, where) {
|
|
397
|
+
if (typeof value !== "string") invalid(where, "must be a string");
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
400
|
+
function boolean(value, where) {
|
|
401
|
+
if (typeof value !== "boolean") invalid(where, "must be a boolean");
|
|
402
|
+
return value;
|
|
403
|
+
}
|
|
404
|
+
function oneOf(value, allowed, where) {
|
|
405
|
+
if (!allowed.includes(value)) invalid(where, `must be one of ${allowed.join(", ")}`);
|
|
406
|
+
return value;
|
|
407
|
+
}
|
|
408
|
+
function invalid(where, message) {
|
|
409
|
+
throw new VizePluginPlanError("capability-invalid", where, message);
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region ../../../crates/vize_carton/src/config/loader/plugin-plan.js
|
|
413
|
+
const PLUGIN_PLAN_SCHEMA = PLUGIN_REGISTRY.planSchema;
|
|
414
|
+
const PLUGIN_ENTRY = Symbol.for("vize.plugin.entry");
|
|
415
|
+
const NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
416
|
+
const FINGERPRINT = /^[0-9a-f]{64}$/;
|
|
417
|
+
const MANIFEST_FIELDS = [
|
|
418
|
+
"after",
|
|
419
|
+
"apiVersion",
|
|
420
|
+
"backend",
|
|
421
|
+
"before",
|
|
422
|
+
"cacheInputs",
|
|
423
|
+
"capabilities",
|
|
424
|
+
"fingerprint",
|
|
425
|
+
"name",
|
|
426
|
+
"options",
|
|
427
|
+
"permissions",
|
|
428
|
+
"stability",
|
|
429
|
+
"supports",
|
|
430
|
+
"version"
|
|
431
|
+
];
|
|
432
|
+
const SUPPORTS = {
|
|
433
|
+
outputs: [
|
|
434
|
+
"ssr",
|
|
435
|
+
"vapor",
|
|
436
|
+
"vdom"
|
|
437
|
+
],
|
|
438
|
+
runtimes: ["bun", "node"],
|
|
439
|
+
vue: ["2", "3"]
|
|
440
|
+
};
|
|
441
|
+
const PERMISSIONS = {
|
|
442
|
+
env: "keys",
|
|
443
|
+
"fs.read": "paths"
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* Build the plan for authored `vue.plugins`. `false`, `null` and `undefined`
|
|
447
|
+
* entries are skipped like conditional Vite plugins; every other entry must be
|
|
448
|
+
* a v2 entry or a v1 rule plugin hosted through the compatibility adapter.
|
|
449
|
+
*/
|
|
450
|
+
function resolvePluginPlan(entries, host = {}) {
|
|
451
|
+
if (entries === void 0) entries = [];
|
|
452
|
+
if (!Array.isArray(entries)) throw new VizePluginPlanError("entry-invalid", "vue.plugins", "must be an array");
|
|
453
|
+
const runtime = host.runtime ?? (globalThis.Bun ? "bun" : "node");
|
|
454
|
+
const lowered = [];
|
|
455
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
456
|
+
const sources = /* @__PURE__ */ new Map();
|
|
457
|
+
entries.forEach((entry, index) => {
|
|
458
|
+
if (entry === false || entry === null || entry === void 0) return;
|
|
459
|
+
const { manifest, handlers } = lowerEntry(entry, `vue.plugins[${index}]`);
|
|
460
|
+
const plugin = validateManifest(manifest, index, runtime);
|
|
461
|
+
sources.set(plugin.name, entry);
|
|
462
|
+
plugin.capabilities.forEach((capability, position) => {
|
|
463
|
+
const handler = handlers[capability.source] ?? {};
|
|
464
|
+
for (const name of PLUGIN_REGISTRY.capabilities[capability.id].callbacks) {
|
|
465
|
+
if (typeof handler[name] !== "function") throw new VizePluginPlanError("callback-missing", `${plugin.name} ${capability.id} ${capability.key}`, `the \`${name}\` callback is missing`);
|
|
466
|
+
callbacks.set(callbackKey(plugin.name, capability.id, capability.key, name), handler[name]);
|
|
467
|
+
}
|
|
468
|
+
delete plugin.capabilities[position].source;
|
|
469
|
+
});
|
|
470
|
+
lowered.push(plugin);
|
|
471
|
+
});
|
|
472
|
+
const plugins = orderPlugins(lowered);
|
|
473
|
+
const claims = plugins.flatMap((plugin) => plugin.capabilities.map((capability) => ({
|
|
474
|
+
key: claimKey(capability.id, capability.key),
|
|
475
|
+
owner: plugin.name
|
|
476
|
+
}))).sort((left, right) => compareCodePoints(left.key, right.key));
|
|
477
|
+
const conflict = ownershipConflict(claims);
|
|
478
|
+
if (conflict) {
|
|
479
|
+
const [first, second] = conflict;
|
|
480
|
+
throw new VizePluginPlanError("owner-conflict", second.key, first.key !== second.key ? `${second.owner} claims it, but ${first.owner} owns ${first.key} for every language` : first.owner === second.owner ? `${first.owner} claims it more than once` : `claimed by both ${first.owner} and ${second.owner}`);
|
|
481
|
+
}
|
|
482
|
+
const plan = deepFreeze({
|
|
483
|
+
claims,
|
|
484
|
+
planSchema: PLUGIN_PLAN_SCHEMA,
|
|
485
|
+
plugins
|
|
486
|
+
});
|
|
487
|
+
const json = canonicalJson(plan);
|
|
488
|
+
return Object.freeze({
|
|
489
|
+
plan,
|
|
490
|
+
json,
|
|
491
|
+
digest: digestOf(json),
|
|
492
|
+
callbacks,
|
|
493
|
+
entries: sources
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
function callbackKey(plugin, capability, key, name) {
|
|
497
|
+
return `${plugin}\u0000${capability}\u0000${key}\u0000${name}`;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Refuse a capability until every product that consumes it implements it,
|
|
501
|
+
* whichever product loads it, so no product silently ignores it.
|
|
502
|
+
*/
|
|
503
|
+
function refuseUnimplementedCapabilities(plan) {
|
|
504
|
+
for (const plugin of plan.plugins) for (const capability of plugin.capabilities) {
|
|
505
|
+
const { consumers, admittedBy } = PLUGIN_REGISTRY.capabilities[capability.id];
|
|
506
|
+
const missing = consumers.filter((consumer) => !admittedBy.includes(consumer));
|
|
507
|
+
if (missing.length === 0) continue;
|
|
508
|
+
const subject = `${capability.id} \`${capability.key}\``;
|
|
509
|
+
const refusal = admittedBy.length === 0 ? `no Vize product implements ${subject} yet` : `${subject} is not implemented by ${missing.join(", ")} yet`;
|
|
510
|
+
throw new VizePluginPlanError("capability-unadmitted", plugin.name, `${refusal}; run \`vize plugin inspect\` for the plan`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/** An empty plan has no observable product behavior. */
|
|
514
|
+
function isEmptyPluginPlan(plan) {
|
|
515
|
+
return plan.plugins.length === 0;
|
|
516
|
+
}
|
|
517
|
+
function lowerEntry(entry, where) {
|
|
518
|
+
if (typeof entry !== "object" && typeof entry !== "function") throw new VizePluginPlanError("entry-invalid", where, "is not a Vize plugin entry");
|
|
519
|
+
if (Array.isArray(entry) || typeof entry.then === "function") throw new VizePluginPlanError("entry-invalid", where, "nested arrays and promises are not plugin entries; list resolved entries");
|
|
520
|
+
const descriptor = entry[PLUGIN_ENTRY];
|
|
521
|
+
if (descriptor !== void 0) {
|
|
522
|
+
if (descriptor?.apiVersion !== 2 || typeof descriptor.manifest !== "object") throw new VizePluginPlanError("api-unsupported", where, `plugin API ${descriptor?.apiVersion} is not supported (supported: ${PLUGIN_REGISTRY.apiVersions.join(", ")})`);
|
|
523
|
+
return {
|
|
524
|
+
manifest: descriptor.manifest,
|
|
525
|
+
handlers: Array.isArray(descriptor.callbacks) ? descriptor.callbacks : []
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
return lowerV1Plugin(entry, where);
|
|
529
|
+
}
|
|
530
|
+
function lowerV1Plugin(plugin, where) {
|
|
531
|
+
if (typeof plugin.run !== "function" || typeof plugin.fingerprint !== "string" || plugin.rules === null || typeof plugin.rules !== "object" || "family" in plugin || "provides" in plugin) throw new VizePluginPlanError("entry-invalid", where, "expected a defineVizePlugin entry or a v1 definePlugin rule plugin; other v1 hooks keep their native APIs");
|
|
532
|
+
return {
|
|
533
|
+
manifest: {
|
|
534
|
+
apiVersion: 1,
|
|
535
|
+
backend: "js",
|
|
536
|
+
cacheInputs: plugin.cacheInputs === void 0 ? null : plugin.cacheInputs,
|
|
537
|
+
capabilities: [{
|
|
538
|
+
data: {
|
|
539
|
+
demands: [...plugin.demands ?? []],
|
|
540
|
+
rules: Object.keys(plugin.rules),
|
|
541
|
+
visit: plugin.visit === void 0 ? null : [...plugin.visit]
|
|
542
|
+
},
|
|
543
|
+
id: "lint.plugin-v1",
|
|
544
|
+
required: true,
|
|
545
|
+
schemaVersion: 1
|
|
546
|
+
}],
|
|
547
|
+
fingerprint: plugin.fingerprint,
|
|
548
|
+
name: plugin.name,
|
|
549
|
+
stability: "v1",
|
|
550
|
+
version: plugin.version
|
|
551
|
+
},
|
|
552
|
+
handlers: [{ run: plugin.run }]
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function validateManifest(authored, index, runtime) {
|
|
556
|
+
const where = `vue.plugins[${index}]`;
|
|
557
|
+
if (authored === null || typeof authored !== "object" || Array.isArray(authored)) throw new VizePluginPlanError("manifest-invalid", where, "the manifest must be an object");
|
|
558
|
+
const { options = {}, ...rest } = authored;
|
|
559
|
+
const manifest = {
|
|
560
|
+
...canonicalData(rest, where, "manifest", "manifest-invalid"),
|
|
561
|
+
options: canonicalData(options, typeof authored.name === "string" ? authored.name : where, "options", "options-invalid")
|
|
562
|
+
};
|
|
563
|
+
for (const key of Object.keys(manifest)) if (!MANIFEST_FIELDS.includes(key)) throw new VizePluginPlanError("manifest-invalid", where, `unknown manifest field \`${key}\``);
|
|
564
|
+
const name = manifest.name;
|
|
565
|
+
if (typeof name !== "string" || !NAME.test(name)) throw new VizePluginPlanError("manifest-invalid", where, "name must be a package-style name");
|
|
566
|
+
const fail = (code, message) => {
|
|
567
|
+
throw new VizePluginPlanError(code, name, message);
|
|
568
|
+
};
|
|
569
|
+
const apiVersion = manifest.apiVersion;
|
|
570
|
+
if (!PLUGIN_REGISTRY.apiVersions.includes(apiVersion)) fail("api-unsupported", `plugin API ${apiVersion} is not supported`);
|
|
571
|
+
if (apiVersion === 2 && manifest.stability !== "experimental") fail("manifest-invalid", "API v2 plugins must declare stability \"experimental\"");
|
|
572
|
+
if (typeof manifest.version !== "string" || manifest.version === "") fail("manifest-invalid", "version must be a non-empty string");
|
|
573
|
+
if (typeof manifest.fingerprint !== "string" || manifest.fingerprint === "") fail("manifest-invalid", "fingerprint must be a non-empty string");
|
|
574
|
+
if (apiVersion === 2 && !FINGERPRINT.test(manifest.fingerprint)) fail("manifest-invalid", "fingerprint must be a sha256 hex digest");
|
|
575
|
+
const backend = manifest.backend ?? "js";
|
|
576
|
+
if (!PLUGIN_REGISTRY.backends.includes(backend)) fail("manifest-invalid", `unknown backend \`${backend}\``);
|
|
577
|
+
if (!PLUGIN_REGISTRY.admittedBackends.includes(backend)) fail("backend-unavailable", `the ${backend} backend is not available in plugin API v2 incubation; select an implemented backend explicitly (no fallback is attempted)`);
|
|
578
|
+
const supports = supportsOf(manifest.supports ?? {}, fail);
|
|
579
|
+
if (!supports.runtimes.includes(runtime)) fail("host-unsupported", `does not support the ${runtime} runtime`);
|
|
580
|
+
const plugin = {
|
|
581
|
+
after: namesOf(manifest.after ?? [], "after", fail),
|
|
582
|
+
apiVersion,
|
|
583
|
+
backend,
|
|
584
|
+
before: namesOf(manifest.before ?? [], "before", fail),
|
|
585
|
+
cacheInputs: apiVersion === 1 && manifest.cacheInputs === null ? null : cacheInputsOf(manifest.cacheInputs ?? [], fail),
|
|
586
|
+
capabilities: [],
|
|
587
|
+
fingerprint: manifest.fingerprint,
|
|
588
|
+
index,
|
|
589
|
+
name,
|
|
590
|
+
options: manifest.options,
|
|
591
|
+
permissions: permissionsOf(manifest.permissions ?? [], fail),
|
|
592
|
+
skipped: [],
|
|
593
|
+
stability: manifest.stability,
|
|
594
|
+
supports,
|
|
595
|
+
version: manifest.version
|
|
596
|
+
};
|
|
597
|
+
if (apiVersion === 1) delete plugin.supports;
|
|
598
|
+
if (!Array.isArray(manifest.capabilities) || manifest.capabilities.length === 0) fail("manifest-invalid", "capabilities must be a non-empty array");
|
|
599
|
+
manifest.capabilities.forEach((capability, source) => {
|
|
600
|
+
const at = `capabilities[${source}]`;
|
|
601
|
+
if (capability === null || typeof capability !== "object" || Array.isArray(capability)) fail("manifest-invalid", `${at} must be an object`);
|
|
602
|
+
for (const key of Object.keys(capability)) if (![
|
|
603
|
+
"data",
|
|
604
|
+
"id",
|
|
605
|
+
"required",
|
|
606
|
+
"schemaVersion"
|
|
607
|
+
].includes(key)) fail("manifest-invalid", `${at} has unknown field \`${key}\``);
|
|
608
|
+
const { id, required = true, schemaVersion } = capability;
|
|
609
|
+
if (typeof id !== "string" || typeof required !== "boolean" || !Number.isInteger(schemaVersion)) fail("manifest-invalid", `${at} needs a string id, integer schemaVersion and boolean required`);
|
|
610
|
+
const known = PLUGIN_REGISTRY.capabilities[id];
|
|
611
|
+
const unsupported = known === void 0 ? `unknown capability \`${id}\`` : !known.apiVersions.includes(apiVersion) ? `capability \`${id}\` is not available to plugin API ${apiVersion}` : !known.schemaVersions.includes(schemaVersion) ? `capability \`${id}\` schema ${schemaVersion} is not supported (supported: ${known.schemaVersions.join(", ")})` : void 0;
|
|
612
|
+
if (unsupported !== void 0) {
|
|
613
|
+
if (required) fail(known === void 0 ? "capability-unknown" : "capability-unsupported", unsupported);
|
|
614
|
+
plugin.skipped.push({
|
|
615
|
+
id,
|
|
616
|
+
schemaVersion
|
|
617
|
+
});
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const { key, data } = normalizeCapability(plugin, {
|
|
621
|
+
id,
|
|
622
|
+
data: capability.data ?? {}
|
|
623
|
+
});
|
|
624
|
+
plugin.capabilities.push({
|
|
625
|
+
data,
|
|
626
|
+
id,
|
|
627
|
+
key,
|
|
628
|
+
required,
|
|
629
|
+
schemaVersion,
|
|
630
|
+
source
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
if (plugin.capabilities.length === 0) fail("manifest-invalid", "no supported capability remains after skipping optional ones");
|
|
634
|
+
return plugin;
|
|
635
|
+
}
|
|
636
|
+
function supportsOf(value, fail) {
|
|
637
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) fail("manifest-invalid", "supports must be an object");
|
|
638
|
+
const result = {};
|
|
639
|
+
for (const [key, allowed] of Object.entries(SUPPORTS)) {
|
|
640
|
+
const list = value[key] ?? allowed;
|
|
641
|
+
if (!Array.isArray(list) || list.length === 0 || new Set(list).size !== list.length) fail("manifest-invalid", `supports.${key} must be a non-empty unique array`);
|
|
642
|
+
for (const item of list) if (!allowed.includes(item)) fail("manifest-invalid", `supports.${key} has unknown \`${item}\``);
|
|
643
|
+
result[key] = [...list].sort(compareCodePoints);
|
|
644
|
+
}
|
|
645
|
+
for (const key of Object.keys(value)) if (!Object.hasOwn(SUPPORTS, key)) fail("manifest-invalid", `supports has unknown field \`${key}\``);
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
function namesOf(value, field, fail) {
|
|
649
|
+
if (!Array.isArray(value) || value.some((name) => typeof name !== "string" || !NAME.test(name))) fail("manifest-invalid", `${field} must list plugin names`);
|
|
650
|
+
if (new Set(value).size !== value.length) fail("manifest-invalid", `${field} has duplicates`);
|
|
651
|
+
return [...value].sort(compareCodePoints);
|
|
652
|
+
}
|
|
653
|
+
function cacheInputsOf(value, fail) {
|
|
654
|
+
if (!Array.isArray(value)) fail("manifest-invalid", "cacheInputs must be an array");
|
|
655
|
+
const names = /* @__PURE__ */ new Set();
|
|
656
|
+
for (const input of value) {
|
|
657
|
+
if (input === null || typeof input !== "object" || Object.keys(input).sort(compareCodePoints).join() !== "name,value" || typeof input.name !== "string" || typeof input.value !== "string" || input.name === "") fail("manifest-invalid", "cacheInputs entries are { name, value } strings");
|
|
658
|
+
if (input.name.startsWith("@vize/")) fail("manifest-invalid", `cache input \`${input.name}\` uses the host-reserved @vize/ prefix`);
|
|
659
|
+
if (names.has(input.name)) fail("manifest-invalid", `cache input \`${input.name}\` is duplicated`);
|
|
660
|
+
names.add(input.name);
|
|
661
|
+
}
|
|
662
|
+
return [...value].sort((left, right) => compareCodePoints(left.name, right.name));
|
|
663
|
+
}
|
|
664
|
+
function permissionsOf(value, fail) {
|
|
665
|
+
if (!Array.isArray(value)) fail("manifest-invalid", "permissions must be an array");
|
|
666
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
667
|
+
return value.map((permission) => {
|
|
668
|
+
const field = PERMISSIONS[permission?.kind];
|
|
669
|
+
if (field === void 0) fail("manifest-invalid", `unknown permission \`${permission?.kind}\``);
|
|
670
|
+
if (Object.keys(permission).sort(compareCodePoints).join() !== ["kind", field].sort(compareCodePoints).join() || !Array.isArray(permission[field]) || permission[field].length === 0 || permission[field].some((item) => typeof item !== "string" || item === "")) fail("manifest-invalid", `the ${permission.kind} permission lists non-empty ${field}`);
|
|
671
|
+
if (kinds.has(permission.kind)) fail("manifest-invalid", `the ${permission.kind} permission is declared twice`);
|
|
672
|
+
kinds.add(permission.kind);
|
|
673
|
+
return {
|
|
674
|
+
kind: permission.kind,
|
|
675
|
+
[field]: [...new Set(permission[field])].sort(compareCodePoints)
|
|
676
|
+
};
|
|
677
|
+
}).sort((left, right) => compareCodePoints(left.kind, right.kind));
|
|
678
|
+
}
|
|
679
|
+
function orderPlugins(plugins) {
|
|
680
|
+
const byName = /* @__PURE__ */ new Map();
|
|
681
|
+
for (const plugin of plugins) {
|
|
682
|
+
if (byName.has(plugin.name)) throw new VizePluginPlanError("duplicate-name", plugin.name, `listed at vue.plugins[${byName.get(plugin.name).index}] and vue.plugins[${plugin.index}]`);
|
|
683
|
+
byName.set(plugin.name, plugin);
|
|
684
|
+
}
|
|
685
|
+
const edges = new Map(plugins.map((plugin) => [plugin.name, /* @__PURE__ */ new Set()]));
|
|
686
|
+
const incoming = new Map(plugins.map((plugin) => [plugin.name, 0]));
|
|
687
|
+
const edge = (from, to, plugin, field) => {
|
|
688
|
+
if (!byName.has(from === plugin.name ? to : from)) throw new VizePluginPlanError("order-unknown", plugin.name, `${field} names \`${from === plugin.name ? to : from}\`, which is not in vue.plugins`);
|
|
689
|
+
if (from === to) throw new VizePluginPlanError("order-cycle", plugin.name, "orders itself");
|
|
690
|
+
if (!edges.get(from).has(to)) {
|
|
691
|
+
edges.get(from).add(to);
|
|
692
|
+
incoming.set(to, incoming.get(to) + 1);
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
for (const plugin of plugins) {
|
|
696
|
+
for (const name of plugin.before) edge(plugin.name, name, plugin, "before");
|
|
697
|
+
for (const name of plugin.after) edge(name, plugin.name, plugin, "after");
|
|
698
|
+
}
|
|
699
|
+
const ordered = [];
|
|
700
|
+
const ready = plugins.filter((plugin) => incoming.get(plugin.name) === 0);
|
|
701
|
+
while (ready.length > 0) {
|
|
702
|
+
ready.sort((left, right) => left.index - right.index);
|
|
703
|
+
const next = ready.shift();
|
|
704
|
+
ordered.push(next);
|
|
705
|
+
for (const name of edges.get(next.name)) {
|
|
706
|
+
incoming.set(name, incoming.get(name) - 1);
|
|
707
|
+
if (incoming.get(name) === 0) ready.push(byName.get(name));
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (ordered.length !== plugins.length) {
|
|
711
|
+
const cycle = plugins.filter((plugin) => incoming.get(plugin.name) > 0).map((plugin) => plugin.name);
|
|
712
|
+
throw new VizePluginPlanError("order-cycle", cycle[0], `ordering cycle among ${cycle.join(", ")}`);
|
|
713
|
+
}
|
|
714
|
+
return ordered;
|
|
715
|
+
}
|
|
716
|
+
//#endregion
|
|
717
|
+
export { PLUGIN_REGISTRY as a, resolvePluginPlan as i, isEmptyPluginPlan as n, VizePluginPlanError as o, refuseUnimplementedCapabilities as r, deepFreeze as s, callbackKey as t };
|