vite-plugin-qingkuai 1.0.19 → 1.0.21
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/README.md +2 -3
- package/dist/index.cjs +66 -13
- package/dist/index.d.ts +5 -1
- package/dist/index.js +66 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# vite-plugin-qingkuai
|
|
2
2
|
|
|
3
|
-
vite-plugin-qingkuai is a Vite plugin that transforms `.qk` component files into native JavaScript using the Qingkuai compiler. It enables fast and seamless development of web applications built with [
|
|
4
|
-
|
|
5
|
-
[QingKuai Documentation](https://qingkuai.dev) | [VSCode extension For QingKuai Language Features](https://marketplace.visualstudio.com/items?itemName=qingkuai-tools.qingkuai-language-features) | [Issues]("https://github.com/qingkuai-js/vite-plugin/issues)
|
|
3
|
+
vite-plugin-qingkuai is a Vite plugin that transforms `.qk` component files into native JavaScript using the Qingkuai compiler. It enables fast and seamless development of web applications built with [Qingkuai](https://qingkuai.dev).
|
|
6
4
|
|
|
7
5
|
## Usage
|
|
8
6
|
|
|
9
7
|
```js
|
|
8
|
+
// vite.config.js
|
|
10
9
|
import { defineConfig } from "vite"
|
|
11
10
|
import qingkuai from "vite-plugin-qingkuai"
|
|
12
11
|
|
package/dist/index.cjs
CHANGED
|
@@ -62,15 +62,22 @@ function findFilesByName(dir, targetFileName, ignoreList) {
|
|
|
62
62
|
|
|
63
63
|
async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
64
64
|
let error;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const processedRules = /* @__PURE__ */ new WeakSet();
|
|
66
|
+
const createHashAttribute = () => {
|
|
67
|
+
return selectorParser.attribute({
|
|
68
|
+
attribute: `qk-${hash}`,
|
|
69
|
+
value: void 0,
|
|
70
|
+
raws: {}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
70
73
|
const processor = postcss([
|
|
71
74
|
{
|
|
72
75
|
postcssPlugin: "postcss-attach-scope-qingkuai",
|
|
73
76
|
Rule(rule) {
|
|
77
|
+
if (processedRules.has(rule)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
processedRules.add(rule);
|
|
74
81
|
if (rule.parent && "name" in rule?.parent && rule.parent.name === "keyframes") {
|
|
75
82
|
return;
|
|
76
83
|
}
|
|
@@ -80,7 +87,8 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
|
80
87
|
for (let i = 0; i < selector.nodes.length; i++) {
|
|
81
88
|
const item = selector.nodes[i];
|
|
82
89
|
if (item.type === "attribute" && item.attribute === "qk-scope") {
|
|
83
|
-
|
|
90
|
+
selector.nodes[i] = createHashAttribute();
|
|
91
|
+
usedScopeAttribute = true;
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
if (usedScopeAttribute) {
|
|
@@ -91,7 +99,7 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
|
91
99
|
});
|
|
92
100
|
if (index !== -1) {
|
|
93
101
|
const lastNode = selector.nodes[index];
|
|
94
|
-
lastNode.parent?.insertAfter(lastNode,
|
|
102
|
+
lastNode.parent?.insertAfter(lastNode, createHashAttribute());
|
|
95
103
|
}
|
|
96
104
|
});
|
|
97
105
|
}).processSync(rule.selector);
|
|
@@ -105,7 +113,13 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
|
105
113
|
annotation: false
|
|
106
114
|
}
|
|
107
115
|
});
|
|
108
|
-
|
|
116
|
+
const outputMap = ret.map?.toJSON();
|
|
117
|
+
return {
|
|
118
|
+
error,
|
|
119
|
+
code: ret.css,
|
|
120
|
+
map: outputMap,
|
|
121
|
+
mappings: outputMap?.mappings || ""
|
|
122
|
+
};
|
|
109
123
|
}
|
|
110
124
|
|
|
111
125
|
function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
|
|
@@ -127,7 +141,7 @@ async function getOriginalPosition(map, line, column) {
|
|
|
127
141
|
return new sourceMapJs.SourceMapConsumer(map).originalPositionFor({ line, column });
|
|
128
142
|
}
|
|
129
143
|
|
|
130
|
-
function qingkuai() {
|
|
144
|
+
function qingkuai(options = {}) {
|
|
131
145
|
let isDev;
|
|
132
146
|
let sourcemap;
|
|
133
147
|
let cssSourcemap;
|
|
@@ -135,10 +149,18 @@ function qingkuai() {
|
|
|
135
149
|
const compileResultCache = /* @__PURE__ */ new Map();
|
|
136
150
|
const qingkuaiConfigurations = /* @__PURE__ */ new Map();
|
|
137
151
|
const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
|
|
152
|
+
if (isUndefined(options.maxScheduleDepth)) {
|
|
153
|
+
options.maxScheduleDepth = 300;
|
|
154
|
+
}
|
|
138
155
|
return {
|
|
139
156
|
name: "qingkuai-compiler",
|
|
140
157
|
config(_, env) {
|
|
141
158
|
isDev = env.command === "serve";
|
|
159
|
+
return {
|
|
160
|
+
define: {
|
|
161
|
+
__qk_max_schedule_depth: options.maxScheduleDepth
|
|
162
|
+
}
|
|
163
|
+
};
|
|
142
164
|
},
|
|
143
165
|
configureServer(server) {
|
|
144
166
|
createQingkuaiConfigurationWatcher(server);
|
|
@@ -214,10 +236,16 @@ function qingkuai() {
|
|
|
214
236
|
virtualFileName,
|
|
215
237
|
assertedPreprocessMap
|
|
216
238
|
);
|
|
239
|
+
const attachScopeMap = attachScopeResult.map ?? assertedPreprocessMap;
|
|
240
|
+
const samePath = (left, right) => {
|
|
241
|
+
return nodePath.normalize(left) === nodePath.normalize(right);
|
|
242
|
+
};
|
|
243
|
+
const sourceIndex = attachScopeMap?.sources.findIndex((source) => samePath(source, virtualFileName)) ?? -1;
|
|
244
|
+
const currentSourceIndex = sourceIndex === -1 ? preprocessRes.deps?.size || 0 : sourceIndex;
|
|
217
245
|
const offsetMappings = sourcemapCodec.encode(
|
|
218
246
|
offsetSourceMap(
|
|
219
247
|
attachScopeResult.mappings,
|
|
220
|
-
|
|
248
|
+
currentSourceIndex,
|
|
221
249
|
style.loc.start.line - 1,
|
|
222
250
|
style.loc.start.column - 1
|
|
223
251
|
)
|
|
@@ -231,6 +259,16 @@ function qingkuai() {
|
|
|
231
259
|
attachScopeResult.error.loc.line,
|
|
232
260
|
attachScopeResult.error.loc.column
|
|
233
261
|
);
|
|
262
|
+
if (preprocessedPosition.source && !samePath(preprocessedPosition.source, virtualFileName)) {
|
|
263
|
+
this.error({
|
|
264
|
+
message: attachScopeResult.error.message,
|
|
265
|
+
loc: {
|
|
266
|
+
file: preprocessedPosition.source,
|
|
267
|
+
line: preprocessedPosition.line,
|
|
268
|
+
column: preprocessedPosition.column
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
234
272
|
const preprocessedIndex = new linesAndColumns.LinesAndColumns(style.code).indexForLocation({
|
|
235
273
|
line: preprocessedPosition.line - 1,
|
|
236
274
|
column: preprocessedPosition.column
|
|
@@ -251,8 +289,21 @@ function qingkuai() {
|
|
|
251
289
|
map: {
|
|
252
290
|
version: 3,
|
|
253
291
|
mappings: offsetMappings,
|
|
254
|
-
names: assertedPreprocessMap?.names || [],
|
|
255
|
-
sources:
|
|
292
|
+
names: attachScopeMap?.names || assertedPreprocessMap?.names || [],
|
|
293
|
+
sources: attachScopeMap?.sources ? (() => {
|
|
294
|
+
const sources = [...attachScopeMap.sources];
|
|
295
|
+
if (currentSourceIndex !== -1) {
|
|
296
|
+
sources[currentSourceIndex] = fileId;
|
|
297
|
+
}
|
|
298
|
+
return sources;
|
|
299
|
+
})() : [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId],
|
|
300
|
+
sourcesContent: attachScopeMap?.sourcesContent ? (() => {
|
|
301
|
+
const sourcesContent = [...attachScopeMap.sourcesContent];
|
|
302
|
+
if (currentSourceIndex !== -1) {
|
|
303
|
+
sourcesContent[currentSourceIndex] = nodeFs.readFileSync(fileId, "utf-8");
|
|
304
|
+
}
|
|
305
|
+
return sourcesContent;
|
|
306
|
+
})() : void 0
|
|
256
307
|
}
|
|
257
308
|
};
|
|
258
309
|
}
|
|
@@ -302,11 +353,13 @@ function qingkuai() {
|
|
|
302
353
|
id,
|
|
303
354
|
{
|
|
304
355
|
sourcemap,
|
|
356
|
+
lang: "ts",
|
|
305
357
|
loader: "ts",
|
|
306
358
|
target: "esnext"
|
|
307
359
|
},
|
|
308
360
|
sourcemap ? {
|
|
309
361
|
version: 3,
|
|
362
|
+
names: [],
|
|
310
363
|
sources: [id],
|
|
311
364
|
sourcesContent: [src],
|
|
312
365
|
mappings: compileRes.mappings
|
|
@@ -329,7 +382,7 @@ function qingkuai() {
|
|
|
329
382
|
})
|
|
330
383
|
};
|
|
331
384
|
} catch (err) {
|
|
332
|
-
if (err.loc
|
|
385
|
+
if (err.loc && "start" in err.loc && "index" in err.loc.start) {
|
|
333
386
|
err.pos = err.loc.start.index, this.error(err);
|
|
334
387
|
} else {
|
|
335
388
|
this.error(
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -41,15 +41,22 @@ function findFilesByName(dir, targetFileName, ignoreList) {
|
|
|
41
41
|
|
|
42
42
|
async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
43
43
|
let error;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
const processedRules = /* @__PURE__ */ new WeakSet();
|
|
45
|
+
const createHashAttribute = () => {
|
|
46
|
+
return selectorParser.attribute({
|
|
47
|
+
attribute: `qk-${hash}`,
|
|
48
|
+
value: void 0,
|
|
49
|
+
raws: {}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
49
52
|
const processor = postcss([
|
|
50
53
|
{
|
|
51
54
|
postcssPlugin: "postcss-attach-scope-qingkuai",
|
|
52
55
|
Rule(rule) {
|
|
56
|
+
if (processedRules.has(rule)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
processedRules.add(rule);
|
|
53
60
|
if (rule.parent && "name" in rule?.parent && rule.parent.name === "keyframes") {
|
|
54
61
|
return;
|
|
55
62
|
}
|
|
@@ -59,7 +66,8 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
|
59
66
|
for (let i = 0; i < selector.nodes.length; i++) {
|
|
60
67
|
const item = selector.nodes[i];
|
|
61
68
|
if (item.type === "attribute" && item.attribute === "qk-scope") {
|
|
62
|
-
|
|
69
|
+
selector.nodes[i] = createHashAttribute();
|
|
70
|
+
usedScopeAttribute = true;
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
if (usedScopeAttribute) {
|
|
@@ -70,7 +78,7 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
|
70
78
|
});
|
|
71
79
|
if (index !== -1) {
|
|
72
80
|
const lastNode = selector.nodes[index];
|
|
73
|
-
lastNode.parent?.insertAfter(lastNode,
|
|
81
|
+
lastNode.parent?.insertAfter(lastNode, createHashAttribute());
|
|
74
82
|
}
|
|
75
83
|
});
|
|
76
84
|
}).processSync(rule.selector);
|
|
@@ -84,7 +92,13 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
|
|
|
84
92
|
annotation: false
|
|
85
93
|
}
|
|
86
94
|
});
|
|
87
|
-
|
|
95
|
+
const outputMap = ret.map?.toJSON();
|
|
96
|
+
return {
|
|
97
|
+
error,
|
|
98
|
+
code: ret.css,
|
|
99
|
+
map: outputMap,
|
|
100
|
+
mappings: outputMap?.mappings || ""
|
|
101
|
+
};
|
|
88
102
|
}
|
|
89
103
|
|
|
90
104
|
function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
|
|
@@ -106,7 +120,7 @@ async function getOriginalPosition(map, line, column) {
|
|
|
106
120
|
return new SourceMapConsumer(map).originalPositionFor({ line, column });
|
|
107
121
|
}
|
|
108
122
|
|
|
109
|
-
function qingkuai() {
|
|
123
|
+
function qingkuai(options = {}) {
|
|
110
124
|
let isDev;
|
|
111
125
|
let sourcemap;
|
|
112
126
|
let cssSourcemap;
|
|
@@ -114,10 +128,18 @@ function qingkuai() {
|
|
|
114
128
|
const compileResultCache = /* @__PURE__ */ new Map();
|
|
115
129
|
const qingkuaiConfigurations = /* @__PURE__ */ new Map();
|
|
116
130
|
const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
|
|
131
|
+
if (isUndefined(options.maxScheduleDepth)) {
|
|
132
|
+
options.maxScheduleDepth = 300;
|
|
133
|
+
}
|
|
117
134
|
return {
|
|
118
135
|
name: "qingkuai-compiler",
|
|
119
136
|
config(_, env) {
|
|
120
137
|
isDev = env.command === "serve";
|
|
138
|
+
return {
|
|
139
|
+
define: {
|
|
140
|
+
__qk_max_schedule_depth: options.maxScheduleDepth
|
|
141
|
+
}
|
|
142
|
+
};
|
|
121
143
|
},
|
|
122
144
|
configureServer(server) {
|
|
123
145
|
createQingkuaiConfigurationWatcher(server);
|
|
@@ -193,10 +215,16 @@ function qingkuai() {
|
|
|
193
215
|
virtualFileName,
|
|
194
216
|
assertedPreprocessMap
|
|
195
217
|
);
|
|
218
|
+
const attachScopeMap = attachScopeResult.map ?? assertedPreprocessMap;
|
|
219
|
+
const samePath = (left, right) => {
|
|
220
|
+
return nodePath.normalize(left) === nodePath.normalize(right);
|
|
221
|
+
};
|
|
222
|
+
const sourceIndex = attachScopeMap?.sources.findIndex((source) => samePath(source, virtualFileName)) ?? -1;
|
|
223
|
+
const currentSourceIndex = sourceIndex === -1 ? preprocessRes.deps?.size || 0 : sourceIndex;
|
|
196
224
|
const offsetMappings = encode(
|
|
197
225
|
offsetSourceMap(
|
|
198
226
|
attachScopeResult.mappings,
|
|
199
|
-
|
|
227
|
+
currentSourceIndex,
|
|
200
228
|
style.loc.start.line - 1,
|
|
201
229
|
style.loc.start.column - 1
|
|
202
230
|
)
|
|
@@ -210,6 +238,16 @@ function qingkuai() {
|
|
|
210
238
|
attachScopeResult.error.loc.line,
|
|
211
239
|
attachScopeResult.error.loc.column
|
|
212
240
|
);
|
|
241
|
+
if (preprocessedPosition.source && !samePath(preprocessedPosition.source, virtualFileName)) {
|
|
242
|
+
this.error({
|
|
243
|
+
message: attachScopeResult.error.message,
|
|
244
|
+
loc: {
|
|
245
|
+
file: preprocessedPosition.source,
|
|
246
|
+
line: preprocessedPosition.line,
|
|
247
|
+
column: preprocessedPosition.column
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
213
251
|
const preprocessedIndex = new LinesAndColumns(style.code).indexForLocation({
|
|
214
252
|
line: preprocessedPosition.line - 1,
|
|
215
253
|
column: preprocessedPosition.column
|
|
@@ -230,8 +268,21 @@ function qingkuai() {
|
|
|
230
268
|
map: {
|
|
231
269
|
version: 3,
|
|
232
270
|
mappings: offsetMappings,
|
|
233
|
-
names: assertedPreprocessMap?.names || [],
|
|
234
|
-
sources:
|
|
271
|
+
names: attachScopeMap?.names || assertedPreprocessMap?.names || [],
|
|
272
|
+
sources: attachScopeMap?.sources ? (() => {
|
|
273
|
+
const sources = [...attachScopeMap.sources];
|
|
274
|
+
if (currentSourceIndex !== -1) {
|
|
275
|
+
sources[currentSourceIndex] = fileId;
|
|
276
|
+
}
|
|
277
|
+
return sources;
|
|
278
|
+
})() : [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId],
|
|
279
|
+
sourcesContent: attachScopeMap?.sourcesContent ? (() => {
|
|
280
|
+
const sourcesContent = [...attachScopeMap.sourcesContent];
|
|
281
|
+
if (currentSourceIndex !== -1) {
|
|
282
|
+
sourcesContent[currentSourceIndex] = readFileSync(fileId, "utf-8");
|
|
283
|
+
}
|
|
284
|
+
return sourcesContent;
|
|
285
|
+
})() : void 0
|
|
235
286
|
}
|
|
236
287
|
};
|
|
237
288
|
}
|
|
@@ -281,11 +332,13 @@ function qingkuai() {
|
|
|
281
332
|
id,
|
|
282
333
|
{
|
|
283
334
|
sourcemap,
|
|
335
|
+
lang: "ts",
|
|
284
336
|
loader: "ts",
|
|
285
337
|
target: "esnext"
|
|
286
338
|
},
|
|
287
339
|
sourcemap ? {
|
|
288
340
|
version: 3,
|
|
341
|
+
names: [],
|
|
289
342
|
sources: [id],
|
|
290
343
|
sourcesContent: [src],
|
|
291
344
|
mappings: compileRes.mappings
|
|
@@ -308,7 +361,7 @@ function qingkuai() {
|
|
|
308
361
|
})
|
|
309
362
|
};
|
|
310
363
|
} catch (err) {
|
|
311
|
-
if (err.loc
|
|
364
|
+
if (err.loc && "start" in err.loc && "index" in err.loc.start) {
|
|
312
365
|
err.pos = err.loc.start.index, this.error(err);
|
|
313
366
|
} else {
|
|
314
367
|
this.error(
|