@weapp-vite/volar 2.0.5 → 2.0.6
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 +286 -349
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +270 -326
- package/dist/schema.d.ts +26 -0
- package/package.json +6 -6
- package/dist/index.d.mts +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { VueLanguagePlugin } from '@vue/language-core';
|
|
2
|
-
|
|
1
|
+
import type { VueLanguagePlugin } from '@vue/language-core';
|
|
3
2
|
/**
|
|
4
3
|
* Volar 语言插件:为 weapp 配置块提供类型与 schema 提示。
|
|
5
4
|
*/
|
|
6
5
|
declare const plugin: VueLanguagePlugin;
|
|
7
|
-
|
|
8
|
-
export = plugin;
|
|
6
|
+
export default plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1,355 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import process from "process";
|
|
5
|
-
|
|
6
|
-
// package.json
|
|
7
|
-
var name = "@weapp-vite/volar";
|
|
8
|
-
|
|
9
|
-
// src/schema.ts
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
10
4
|
import { JSON_SCHEMA_DEFINITIONS } from "@weapp-core/schematics";
|
|
5
|
+
//#region package.json
|
|
6
|
+
var name = "@weapp-vite/volar";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/schema.ts
|
|
9
|
+
/**
|
|
10
|
+
* 为小程序配置生成 JSON Schema
|
|
11
|
+
* 为支持 JSON Schema 的编辑器提供验证和自动补全
|
|
12
|
+
*
|
|
13
|
+
* 注意:JSON Schema 定义由 @weapp-core/schematics 统一维护
|
|
14
|
+
* 使用 Zod 定义并自动生成,确保单一数据源
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 根据文件类型获取对应的 JSON Schema
|
|
18
|
+
* Schema 定义来自 @weapp-core/schematics,使用 Zod 维护单一数据源
|
|
19
|
+
*/
|
|
11
20
|
function getSchemaForType(type) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return definition.schema;
|
|
21
|
+
const definition = JSON_SCHEMA_DEFINITIONS.find((d) => d.typeName === type);
|
|
22
|
+
if (!definition) return null;
|
|
23
|
+
return definition.schema;
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/index.ts
|
|
27
|
+
const BLOCK_TYPE = "json";
|
|
28
|
+
const JS_LANG = "js";
|
|
29
|
+
const JSONC_LANG = "jsonc";
|
|
30
|
+
const JSON_LANG = "json";
|
|
31
|
+
const JSON5_LANG = "json5";
|
|
32
|
+
const PLUGIN_VERSION = 2.2;
|
|
33
|
+
const TS_LANG = "ts";
|
|
34
|
+
const BACKSLASH_RE = /\\/g;
|
|
35
|
+
const NON_SPACE_RE = /\S/;
|
|
36
|
+
const WXS_MODULE_RE = /<wxs[\s\S]*?module\s*=\s*(?:"([^"]+)"|'([^']+)')[\s\S]*?\/?>/gi;
|
|
37
|
+
const FULL_CAPABILITIES = {
|
|
38
|
+
verification: true,
|
|
39
|
+
completion: true,
|
|
40
|
+
semantic: true,
|
|
41
|
+
navigation: true,
|
|
42
|
+
structure: true,
|
|
43
|
+
format: true
|
|
37
44
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const VOID_CAPABILITIES = {
|
|
46
|
+
verification: false,
|
|
47
|
+
completion: false,
|
|
48
|
+
semantic: false,
|
|
49
|
+
navigation: false,
|
|
50
|
+
structure: false,
|
|
51
|
+
format: false
|
|
45
52
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
49
|
-
var hasSchematicsTypes = false;
|
|
53
|
+
const require = createRequire(typeof module !== "undefined" && module.filename ? module.filename : path.join(process.cwd(), "weapp-vite-volar.cjs"));
|
|
54
|
+
let hasSchematicsTypes = false;
|
|
50
55
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
require.resolve("@weapp-core/schematics");
|
|
57
|
+
hasSchematicsTypes = true;
|
|
53
58
|
} catch {
|
|
54
|
-
|
|
59
|
+
hasSchematicsTypes = false;
|
|
55
60
|
}
|
|
56
61
|
function parseVueSfc(content, filename = "component.vue") {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
62
|
+
try {
|
|
63
|
+
return require("@vue/compiler-sfc").parse(content, { filename });
|
|
64
|
+
} catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
63
67
|
}
|
|
64
68
|
function collectWxsModuleNames(templateContent) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
names.add(name2);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return [...names];
|
|
69
|
+
if (!templateContent) return [];
|
|
70
|
+
const names = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const match of templateContent.matchAll(WXS_MODULE_RE)) {
|
|
72
|
+
const name = match[1] ?? match[2];
|
|
73
|
+
if (name) names.add(name);
|
|
74
|
+
}
|
|
75
|
+
return [...names];
|
|
76
76
|
}
|
|
77
77
|
function createWxsModuleDeclarations(moduleNames) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
return moduleNames.map((name2) => `const ${name2} = {} as Record<string, (...args: any[]) => any>`).join("\n");
|
|
78
|
+
if (!moduleNames.length) return "";
|
|
79
|
+
return moduleNames.map((name) => `const ${name} = {} as Record<string, (...args: any[]) => any>`).join("\n");
|
|
82
80
|
}
|
|
83
81
|
function appendWxsDeclarations(code, moduleNames) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
return code ? `${code}
|
|
89
|
-
|
|
90
|
-
${declarations}
|
|
91
|
-
` : `${declarations}
|
|
92
|
-
`;
|
|
82
|
+
const declarations = createWxsModuleDeclarations(moduleNames);
|
|
83
|
+
if (!declarations) return code;
|
|
84
|
+
return code ? `${code}\n\n${declarations}\n` : `${declarations}\n`;
|
|
93
85
|
}
|
|
94
86
|
function createSyntheticScriptSetup(moduleNames) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
87
|
+
const content = createWxsModuleDeclarations(moduleNames);
|
|
88
|
+
if (!content) return;
|
|
89
|
+
return {
|
|
90
|
+
type: "script",
|
|
91
|
+
content,
|
|
92
|
+
loc: {
|
|
93
|
+
source: `<script setup lang="ts">\n${content}\n<\/script>`,
|
|
94
|
+
start: {
|
|
95
|
+
column: 1,
|
|
96
|
+
line: 1,
|
|
97
|
+
offset: 0
|
|
98
|
+
},
|
|
99
|
+
end: {
|
|
100
|
+
column: 1,
|
|
101
|
+
line: 1,
|
|
102
|
+
offset: 0
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
attrs: {
|
|
106
|
+
setup: true,
|
|
107
|
+
lang: "ts"
|
|
108
|
+
},
|
|
109
|
+
lang: "ts",
|
|
110
|
+
setup: true,
|
|
111
|
+
name: "scriptSetup"
|
|
112
|
+
};
|
|
117
113
|
}
|
|
118
114
|
function normalizeFilename(filename) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
return filename.replace(BACKSLASH_RE, "/");
|
|
115
|
+
if (!filename) return "";
|
|
116
|
+
return filename.replace(BACKSLASH_RE, "/");
|
|
123
117
|
}
|
|
124
118
|
function inferConfigType(filename) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (normalized.includes("/components/")) {
|
|
133
|
-
return "Component";
|
|
134
|
-
}
|
|
135
|
-
if (normalized.includes("/theme/")) {
|
|
136
|
-
return "Theme";
|
|
137
|
-
}
|
|
138
|
-
if (normalized.includes("/sitemap")) {
|
|
139
|
-
return "Sitemap";
|
|
140
|
-
}
|
|
141
|
-
return "Page";
|
|
119
|
+
const normalized = normalizeFilename(filename);
|
|
120
|
+
if (normalized.endsWith("/app.vue")) return "App";
|
|
121
|
+
if (normalized.includes("/plugin/")) return "Plugin";
|
|
122
|
+
if (normalized.includes("/components/")) return "Component";
|
|
123
|
+
if (normalized.includes("/theme/")) return "Theme";
|
|
124
|
+
if (normalized.includes("/sitemap")) return "Sitemap";
|
|
125
|
+
return "Page";
|
|
142
126
|
}
|
|
143
127
|
function normalizeLang(lang) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (lower === "txt") {
|
|
149
|
-
return JSON_LANG;
|
|
150
|
-
}
|
|
151
|
-
return lower;
|
|
128
|
+
if (!lang) return JSON_LANG;
|
|
129
|
+
const lower = lang.toLowerCase();
|
|
130
|
+
if (lower === "txt") return JSON_LANG;
|
|
131
|
+
return lower;
|
|
152
132
|
}
|
|
153
133
|
function findExportDefaultExpression(code, tsModule, lang) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
expression,
|
|
171
|
-
expressionStart,
|
|
172
|
-
expressionEnd,
|
|
173
|
-
leading,
|
|
174
|
-
trailing
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return null;
|
|
134
|
+
const scriptKind = lang === TS_LANG ? tsModule.ScriptKind.TS : tsModule.ScriptKind.JS;
|
|
135
|
+
const sourceFile = tsModule.createSourceFile(`config.${lang}`, code, tsModule.ScriptTarget.Latest, true, scriptKind);
|
|
136
|
+
for (const statement of sourceFile.statements) if (tsModule.isExportAssignment(statement)) {
|
|
137
|
+
const expressionStart = statement.expression.getStart(sourceFile);
|
|
138
|
+
const expressionEnd = statement.expression.getEnd();
|
|
139
|
+
const leading = code.slice(0, statement.getStart(sourceFile));
|
|
140
|
+
return {
|
|
141
|
+
expression: code.slice(expressionStart, expressionEnd),
|
|
142
|
+
expressionStart,
|
|
143
|
+
expressionEnd,
|
|
144
|
+
leading,
|
|
145
|
+
trailing: code.slice(statement.getEnd())
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
179
149
|
}
|
|
180
150
|
function injectSchemaIntoJsonObject(content, schemaId) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const isEmptyObject = nextCharIndex >= 0 && content[nextCharIndex] === "}";
|
|
193
|
-
const schemaLine = ` "$schema": "${schemaId}"`;
|
|
194
|
-
const injected = isEmptyObject ? `{
|
|
195
|
-
${schemaLine}
|
|
196
|
-
}` : `{
|
|
197
|
-
${schemaLine},${content.slice(leftBraceIndex + 1)}`;
|
|
198
|
-
if (trimmed === content) {
|
|
199
|
-
return injected;
|
|
200
|
-
}
|
|
201
|
-
const leading = content.slice(0, content.indexOf(trimmed));
|
|
202
|
-
const trailing = content.slice(content.indexOf(trimmed) + trimmed.length);
|
|
203
|
-
return `${leading}${injected}${trailing}`;
|
|
151
|
+
const trimmed = content.trim();
|
|
152
|
+
if (!trimmed.startsWith("{")) return content;
|
|
153
|
+
const leftBraceIndex = content.indexOf("{");
|
|
154
|
+
if (leftBraceIndex < 0) return content;
|
|
155
|
+
const firstNonSpace = content.slice(leftBraceIndex + 1).match(NON_SPACE_RE);
|
|
156
|
+
const nextCharIndex = firstNonSpace ? leftBraceIndex + 1 + firstNonSpace.index : -1;
|
|
157
|
+
const isEmptyObject = nextCharIndex >= 0 && content[nextCharIndex] === "}";
|
|
158
|
+
const schemaLine = ` "$schema": "${schemaId}"`;
|
|
159
|
+
const injected = isEmptyObject ? `{\n${schemaLine}\n}` : `{\n${schemaLine},${content.slice(leftBraceIndex + 1)}`;
|
|
160
|
+
if (trimmed === content) return injected;
|
|
161
|
+
return `${content.slice(0, content.indexOf(trimmed))}${injected}${content.slice(content.indexOf(trimmed) + trimmed.length)}`;
|
|
204
162
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
FULL_CAPABILITIES
|
|
340
|
-
]);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
embeddedCode.content.push([
|
|
344
|
-
block.content,
|
|
345
|
-
block.name,
|
|
346
|
-
0,
|
|
347
|
-
FULL_CAPABILITIES
|
|
348
|
-
]);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
};
|
|
352
|
-
var index_default = plugin;
|
|
353
|
-
export {
|
|
354
|
-
index_default as default
|
|
163
|
+
/**
|
|
164
|
+
* Volar 语言插件:为 weapp 配置块提供类型与 schema 提示。
|
|
165
|
+
*/
|
|
166
|
+
const plugin = (ctx) => {
|
|
167
|
+
let tsModule = ctx?.modules?.typescript;
|
|
168
|
+
if (!tsModule) try {
|
|
169
|
+
tsModule = require("typescript");
|
|
170
|
+
} catch {
|
|
171
|
+
tsModule = void 0;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
name,
|
|
175
|
+
version: PLUGIN_VERSION,
|
|
176
|
+
order: -1,
|
|
177
|
+
parseSFC2(fileName, languageId, content) {
|
|
178
|
+
if (languageId !== "vue") return;
|
|
179
|
+
const parsed = parseVueSfc(content, fileName);
|
|
180
|
+
if (!parsed) return;
|
|
181
|
+
const descriptor = parsed.descriptor;
|
|
182
|
+
const wxsModuleNames = collectWxsModuleNames(descriptor.template?.content);
|
|
183
|
+
if (!wxsModuleNames.length) return parsed;
|
|
184
|
+
if (descriptor.scriptSetup) descriptor.scriptSetup.content = appendWxsDeclarations(descriptor.scriptSetup.content, wxsModuleNames);
|
|
185
|
+
else descriptor.scriptSetup = createSyntheticScriptSetup(wxsModuleNames);
|
|
186
|
+
return parsed;
|
|
187
|
+
},
|
|
188
|
+
getEmbeddedCodes(_, sfc) {
|
|
189
|
+
const names = [];
|
|
190
|
+
for (let i = 0; i < sfc.customBlocks.length; i++) {
|
|
191
|
+
const block = sfc.customBlocks[i];
|
|
192
|
+
if (block.type === BLOCK_TYPE) {
|
|
193
|
+
const normalizedLang = normalizeLang(block.lang);
|
|
194
|
+
if (normalizedLang === JS_LANG || normalizedLang === TS_LANG) {
|
|
195
|
+
names.push({
|
|
196
|
+
id: `${BLOCK_TYPE}_${i}`,
|
|
197
|
+
lang: TS_LANG
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const embeddedLang = normalizedLang === JSON_LANG || normalizedLang === JSONC_LANG || normalizedLang === JSON5_LANG ? JSONC_LANG : JSON_LANG;
|
|
202
|
+
names.push({
|
|
203
|
+
id: `${BLOCK_TYPE}_${i}`,
|
|
204
|
+
lang: embeddedLang
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return names;
|
|
209
|
+
},
|
|
210
|
+
resolveEmbeddedCode(fileName, sfc, embeddedCode) {
|
|
211
|
+
const match = embeddedCode.id.match(new RegExp(`^${BLOCK_TYPE}_(\\d+)$`));
|
|
212
|
+
if (!match) return;
|
|
213
|
+
const index = Number.parseInt(match[1]);
|
|
214
|
+
const block = sfc.customBlocks[index];
|
|
215
|
+
if (!block) return;
|
|
216
|
+
const normalizedLang = normalizeLang(block.lang);
|
|
217
|
+
const configType = inferConfigType(fileName);
|
|
218
|
+
if (!hasSchematicsTypes) {
|
|
219
|
+
embeddedCode.content.push([
|
|
220
|
+
block.content,
|
|
221
|
+
block.name,
|
|
222
|
+
0,
|
|
223
|
+
FULL_CAPABILITIES
|
|
224
|
+
]);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (normalizedLang === JS_LANG || normalizedLang === TS_LANG) {
|
|
228
|
+
const parsed = tsModule && findExportDefaultExpression(block.content, tsModule, normalizedLang);
|
|
229
|
+
if (parsed && hasSchematicsTypes) {
|
|
230
|
+
const typeImport = `import type { ${configType} as __WeappConfig } from '@weapp-core/schematics'\n`;
|
|
231
|
+
embeddedCode.content.push([
|
|
232
|
+
`${typeImport}const __weapp_defineConfig = <T extends __WeappConfig>(config: T) => config
|
|
233
|
+
|
|
234
|
+
`,
|
|
235
|
+
void 0,
|
|
236
|
+
0,
|
|
237
|
+
VOID_CAPABILITIES
|
|
238
|
+
]);
|
|
239
|
+
if (parsed.leading) embeddedCode.content.push([
|
|
240
|
+
parsed.leading,
|
|
241
|
+
block.name,
|
|
242
|
+
0,
|
|
243
|
+
FULL_CAPABILITIES
|
|
244
|
+
]);
|
|
245
|
+
embeddedCode.content.push([
|
|
246
|
+
"export default __weapp_defineConfig(",
|
|
247
|
+
void 0,
|
|
248
|
+
parsed.expressionStart,
|
|
249
|
+
VOID_CAPABILITIES
|
|
250
|
+
]);
|
|
251
|
+
embeddedCode.content.push([
|
|
252
|
+
parsed.expression,
|
|
253
|
+
block.name,
|
|
254
|
+
parsed.expressionStart,
|
|
255
|
+
FULL_CAPABILITIES
|
|
256
|
+
]);
|
|
257
|
+
embeddedCode.content.push([
|
|
258
|
+
")",
|
|
259
|
+
void 0,
|
|
260
|
+
parsed.expressionEnd,
|
|
261
|
+
VOID_CAPABILITIES
|
|
262
|
+
]);
|
|
263
|
+
if (parsed.trailing) embeddedCode.content.push([
|
|
264
|
+
parsed.trailing,
|
|
265
|
+
block.name,
|
|
266
|
+
parsed.expressionEnd,
|
|
267
|
+
FULL_CAPABILITIES
|
|
268
|
+
]);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
embeddedCode.content.push([
|
|
272
|
+
block.content,
|
|
273
|
+
block.name,
|
|
274
|
+
0,
|
|
275
|
+
FULL_CAPABILITIES
|
|
276
|
+
]);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const schema = getSchemaForType(configType);
|
|
280
|
+
if (schema && schema.$id && !block.content.includes("$schema")) {
|
|
281
|
+
embeddedCode.content.push([
|
|
282
|
+
injectSchemaIntoJsonObject(block.content, schema.$id),
|
|
283
|
+
block.name,
|
|
284
|
+
0,
|
|
285
|
+
FULL_CAPABILITIES
|
|
286
|
+
]);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
embeddedCode.content.push([
|
|
290
|
+
block.content,
|
|
291
|
+
block.name,
|
|
292
|
+
0,
|
|
293
|
+
FULL_CAPABILITIES
|
|
294
|
+
]);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
355
297
|
};
|
|
298
|
+
//#endregion
|
|
299
|
+
export { plugin as default };
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface JsonSchema {
|
|
2
|
+
$schema?: string;
|
|
3
|
+
$id?: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
type: string;
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
additionalProperties?: boolean | any;
|
|
10
|
+
items?: any;
|
|
11
|
+
definitions?: Record<string, any>;
|
|
12
|
+
enum?: string[];
|
|
13
|
+
minimum?: number;
|
|
14
|
+
maximum?: number;
|
|
15
|
+
minItems?: number;
|
|
16
|
+
maxItems?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 根据文件类型获取对应的 JSON Schema
|
|
20
|
+
* Schema 定义来自 @weapp-core/schematics,使用 Zod 维护单一数据源
|
|
21
|
+
*/
|
|
22
|
+
export declare function getSchemaForType(type: 'App' | 'Page' | 'Component' | 'Plugin' | 'Sitemap' | 'Theme'): JsonSchema | null;
|
|
23
|
+
/**
|
|
24
|
+
* 为配置块生成 schema 注释
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateSchemaComment(type: 'App' | 'Page' | 'Component' | 'Plugin' | 'Sitemap' | 'Theme'): string;
|