@weapp-vite/volar 1.0.0 → 2.0.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/package.json +9 -10
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -271
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/volar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Volar plugin for weapp-vite - Provides IntelliSense and type checking for WeChat mini-program config blocks",
|
|
5
5
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,22 +25,21 @@
|
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"types":
|
|
29
|
-
|
|
30
|
-
"require": "./dist/index.d.ts"
|
|
31
|
-
},
|
|
32
|
-
"import": "./dist/index.mjs",
|
|
33
|
-
"require": "./dist/index.js"
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"import": "./dist/index.mjs"
|
|
34
30
|
}
|
|
35
31
|
},
|
|
36
|
-
"main": "./dist/index.
|
|
32
|
+
"main": "./dist/index.mjs",
|
|
37
33
|
"module": "./dist/index.mjs",
|
|
38
|
-
"types": "./dist/index.d.
|
|
34
|
+
"types": "./dist/index.d.mts",
|
|
39
35
|
"files": [
|
|
40
36
|
"dist"
|
|
41
37
|
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
40
|
+
},
|
|
42
41
|
"dependencies": {
|
|
43
|
-
"@weapp-core/schematics": "
|
|
42
|
+
"@weapp-core/schematics": "6.0.0"
|
|
44
43
|
},
|
|
45
44
|
"scripts": {
|
|
46
45
|
"dev": "tsup --watch --sourcemap",
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.8_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
|
|
2
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
3
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
4
|
-
|
|
5
|
-
// src/index.ts
|
|
6
|
-
var _module = require('module');
|
|
7
|
-
|
|
8
|
-
// package.json
|
|
9
|
-
var name = "@weapp-vite/volar";
|
|
10
|
-
|
|
11
|
-
// src/schema.ts
|
|
12
|
-
var _schematics = require('@weapp-core/schematics');
|
|
13
|
-
function getSchemaForType(type) {
|
|
14
|
-
const definition = _schematics.JSON_SCHEMA_DEFINITIONS.find((d) => d.typeName === type);
|
|
15
|
-
if (!definition) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return definition.schema;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var BLOCK_TYPE = "json";
|
|
23
|
-
var JS_LANG = "js";
|
|
24
|
-
var JSONC_LANG = "jsonc";
|
|
25
|
-
var JSON_LANG = "json";
|
|
26
|
-
var JSON5_LANG = "json5";
|
|
27
|
-
var PLUGIN_VERSION = 2.2;
|
|
28
|
-
var TS_LANG = "ts";
|
|
29
|
-
var FULL_CAPABILITIES = {
|
|
30
|
-
verification: true,
|
|
31
|
-
completion: true,
|
|
32
|
-
semantic: true,
|
|
33
|
-
navigation: true,
|
|
34
|
-
structure: true,
|
|
35
|
-
format: true
|
|
36
|
-
};
|
|
37
|
-
var VOID_CAPABILITIES = {
|
|
38
|
-
verification: false,
|
|
39
|
-
completion: false,
|
|
40
|
-
semantic: false,
|
|
41
|
-
navigation: false,
|
|
42
|
-
structure: false,
|
|
43
|
-
format: false
|
|
44
|
-
};
|
|
45
|
-
var require2 = _module.createRequire.call(void 0, importMetaUrl);
|
|
46
|
-
var hasSchematicsTypes = false;
|
|
47
|
-
try {
|
|
48
|
-
require2.resolve("@weapp-core/schematics");
|
|
49
|
-
hasSchematicsTypes = true;
|
|
50
|
-
} catch (e) {
|
|
51
|
-
hasSchematicsTypes = false;
|
|
52
|
-
}
|
|
53
|
-
function normalizeFilename(filename) {
|
|
54
|
-
if (!filename) {
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
return filename.replace(/\\/g, "/");
|
|
58
|
-
}
|
|
59
|
-
function inferConfigType(filename) {
|
|
60
|
-
const normalized = normalizeFilename(filename);
|
|
61
|
-
if (normalized.endsWith("/app.vue")) {
|
|
62
|
-
return "App";
|
|
63
|
-
}
|
|
64
|
-
if (normalized.includes("/plugin/")) {
|
|
65
|
-
return "Plugin";
|
|
66
|
-
}
|
|
67
|
-
if (normalized.includes("/components/")) {
|
|
68
|
-
return "Component";
|
|
69
|
-
}
|
|
70
|
-
if (normalized.includes("/theme/")) {
|
|
71
|
-
return "Theme";
|
|
72
|
-
}
|
|
73
|
-
if (normalized.includes("/sitemap")) {
|
|
74
|
-
return "Sitemap";
|
|
75
|
-
}
|
|
76
|
-
return "Page";
|
|
77
|
-
}
|
|
78
|
-
function normalizeLang(lang) {
|
|
79
|
-
if (!lang) {
|
|
80
|
-
return JSON_LANG;
|
|
81
|
-
}
|
|
82
|
-
const lower = lang.toLowerCase();
|
|
83
|
-
if (lower === "txt") {
|
|
84
|
-
return JSON_LANG;
|
|
85
|
-
}
|
|
86
|
-
return lower;
|
|
87
|
-
}
|
|
88
|
-
function findExportDefaultExpression(code, tsModule, lang) {
|
|
89
|
-
const scriptKind = lang === TS_LANG ? tsModule.ScriptKind.TS : tsModule.ScriptKind.JS;
|
|
90
|
-
const sourceFile = tsModule.createSourceFile(
|
|
91
|
-
`config.${lang}`,
|
|
92
|
-
code,
|
|
93
|
-
tsModule.ScriptTarget.Latest,
|
|
94
|
-
true,
|
|
95
|
-
scriptKind
|
|
96
|
-
);
|
|
97
|
-
for (const statement of sourceFile.statements) {
|
|
98
|
-
if (tsModule.isExportAssignment(statement)) {
|
|
99
|
-
const expressionStart = statement.expression.getStart(sourceFile);
|
|
100
|
-
const expressionEnd = statement.expression.getEnd();
|
|
101
|
-
const leading = code.slice(0, statement.getStart(sourceFile));
|
|
102
|
-
const expression = code.slice(expressionStart, expressionEnd);
|
|
103
|
-
const trailing = code.slice(statement.getEnd());
|
|
104
|
-
return {
|
|
105
|
-
expression,
|
|
106
|
-
expressionStart,
|
|
107
|
-
expressionEnd,
|
|
108
|
-
leading,
|
|
109
|
-
trailing
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
function injectSchemaIntoJsonObject(content, schemaId) {
|
|
116
|
-
const trimmed = content.trim();
|
|
117
|
-
if (!trimmed.startsWith("{")) {
|
|
118
|
-
return content;
|
|
119
|
-
}
|
|
120
|
-
const leftBraceIndex = content.indexOf("{");
|
|
121
|
-
if (leftBraceIndex < 0) {
|
|
122
|
-
return content;
|
|
123
|
-
}
|
|
124
|
-
const afterLeft = content.slice(leftBraceIndex + 1);
|
|
125
|
-
const firstNonSpace = afterLeft.match(/\S/);
|
|
126
|
-
const nextCharIndex = firstNonSpace ? leftBraceIndex + 1 + firstNonSpace.index : -1;
|
|
127
|
-
const isEmptyObject = nextCharIndex >= 0 && content[nextCharIndex] === "}";
|
|
128
|
-
const schemaLine = ` "$schema": "${schemaId}"`;
|
|
129
|
-
const injected = isEmptyObject ? `{
|
|
130
|
-
${schemaLine}
|
|
131
|
-
}` : `{
|
|
132
|
-
${schemaLine},${content.slice(leftBraceIndex + 1)}`;
|
|
133
|
-
if (trimmed === content) {
|
|
134
|
-
return injected;
|
|
135
|
-
}
|
|
136
|
-
const leading = content.slice(0, content.indexOf(trimmed));
|
|
137
|
-
const trailing = content.slice(content.indexOf(trimmed) + trimmed.length);
|
|
138
|
-
return `${leading}${injected}${trailing}`;
|
|
139
|
-
}
|
|
140
|
-
var plugin = (ctx) => {
|
|
141
|
-
let tsModule = _optionalChain([ctx, 'optionalAccess', _2 => _2.modules, 'optionalAccess', _3 => _3.typescript]);
|
|
142
|
-
if (!tsModule) {
|
|
143
|
-
try {
|
|
144
|
-
tsModule = require2("typescript");
|
|
145
|
-
} catch (e2) {
|
|
146
|
-
tsModule = void 0;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
name,
|
|
151
|
-
version: PLUGIN_VERSION,
|
|
152
|
-
getEmbeddedCodes(_, sfc) {
|
|
153
|
-
const names = [];
|
|
154
|
-
for (let i = 0; i < sfc.customBlocks.length; i++) {
|
|
155
|
-
const block = sfc.customBlocks[i];
|
|
156
|
-
if (block.type === BLOCK_TYPE) {
|
|
157
|
-
const normalizedLang = normalizeLang(block.lang);
|
|
158
|
-
const isJsLike = normalizedLang === JS_LANG || normalizedLang === TS_LANG;
|
|
159
|
-
if (isJsLike) {
|
|
160
|
-
names.push({ id: `${BLOCK_TYPE}_${i}`, lang: TS_LANG });
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const embeddedLang = normalizedLang === JSON_LANG || normalizedLang === JSONC_LANG || normalizedLang === JSON5_LANG ? JSONC_LANG : JSON_LANG;
|
|
164
|
-
names.push({ id: `${BLOCK_TYPE}_${i}`, lang: embeddedLang });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return names;
|
|
168
|
-
},
|
|
169
|
-
resolveEmbeddedCode(fileName, sfc, embeddedCode) {
|
|
170
|
-
const match = embeddedCode.id.match(new RegExp(`^${BLOCK_TYPE}_(\\d+)$`));
|
|
171
|
-
if (!match) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const index = Number.parseInt(match[1]);
|
|
175
|
-
const block = sfc.customBlocks[index];
|
|
176
|
-
if (!block) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const normalizedLang = normalizeLang(block.lang);
|
|
180
|
-
const configType = inferConfigType(fileName);
|
|
181
|
-
if (!hasSchematicsTypes) {
|
|
182
|
-
embeddedCode.content.push([
|
|
183
|
-
block.content,
|
|
184
|
-
block.name,
|
|
185
|
-
0,
|
|
186
|
-
FULL_CAPABILITIES
|
|
187
|
-
]);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const userWantsJs = normalizedLang === JS_LANG || normalizedLang === TS_LANG;
|
|
191
|
-
if (userWantsJs) {
|
|
192
|
-
const parsed = tsModule && findExportDefaultExpression(block.content, tsModule, normalizedLang);
|
|
193
|
-
if (parsed && hasSchematicsTypes) {
|
|
194
|
-
const typeImport = `import type { ${configType} as __WeappConfig } from '@weapp-core/schematics'
|
|
195
|
-
`;
|
|
196
|
-
const helper = "const __weapp_defineConfig = <T extends __WeappConfig>(config: T) => config\n\n";
|
|
197
|
-
embeddedCode.content.push([
|
|
198
|
-
`${typeImport}${helper}`,
|
|
199
|
-
void 0,
|
|
200
|
-
0,
|
|
201
|
-
VOID_CAPABILITIES
|
|
202
|
-
]);
|
|
203
|
-
if (parsed.leading) {
|
|
204
|
-
embeddedCode.content.push([
|
|
205
|
-
parsed.leading,
|
|
206
|
-
block.name,
|
|
207
|
-
0,
|
|
208
|
-
FULL_CAPABILITIES
|
|
209
|
-
]);
|
|
210
|
-
}
|
|
211
|
-
embeddedCode.content.push([
|
|
212
|
-
"export default __weapp_defineConfig(",
|
|
213
|
-
void 0,
|
|
214
|
-
parsed.expressionStart,
|
|
215
|
-
VOID_CAPABILITIES
|
|
216
|
-
]);
|
|
217
|
-
embeddedCode.content.push([
|
|
218
|
-
parsed.expression,
|
|
219
|
-
block.name,
|
|
220
|
-
parsed.expressionStart,
|
|
221
|
-
FULL_CAPABILITIES
|
|
222
|
-
]);
|
|
223
|
-
embeddedCode.content.push([
|
|
224
|
-
")",
|
|
225
|
-
void 0,
|
|
226
|
-
parsed.expressionEnd,
|
|
227
|
-
VOID_CAPABILITIES
|
|
228
|
-
]);
|
|
229
|
-
if (parsed.trailing) {
|
|
230
|
-
embeddedCode.content.push([
|
|
231
|
-
parsed.trailing,
|
|
232
|
-
block.name,
|
|
233
|
-
parsed.expressionEnd,
|
|
234
|
-
FULL_CAPABILITIES
|
|
235
|
-
]);
|
|
236
|
-
}
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
embeddedCode.content.push([
|
|
240
|
-
block.content,
|
|
241
|
-
block.name,
|
|
242
|
-
0,
|
|
243
|
-
FULL_CAPABILITIES
|
|
244
|
-
]);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const schema = getSchemaForType(configType);
|
|
248
|
-
if (schema && schema.$id && !block.content.includes("$schema")) {
|
|
249
|
-
embeddedCode.content.push([
|
|
250
|
-
injectSchemaIntoJsonObject(block.content, schema.$id),
|
|
251
|
-
block.name,
|
|
252
|
-
0,
|
|
253
|
-
FULL_CAPABILITIES
|
|
254
|
-
]);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
embeddedCode.content.push([
|
|
258
|
-
block.content,
|
|
259
|
-
block.name,
|
|
260
|
-
0,
|
|
261
|
-
FULL_CAPABILITIES
|
|
262
|
-
]);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
};
|
|
266
|
-
var index_default = plugin;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
exports.default = index_default;
|
|
270
|
-
|
|
271
|
-
module.exports = exports.default;
|