vite-plugin-qingkuai 1.0.20 → 1.0.22

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 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 [QingKuai](https://qingkuai.dev)(a front-end framework).
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
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var vite = require('vite');
4
+ var nodeFs = require('node:fs');
4
5
  var nodePath = require('node:path');
5
6
  var nodeCrypto = require('node:crypto');
6
7
  var compiler = require('qingkuai/compiler');
7
- var nodeFs = require('node:fs');
8
8
  var linesAndColumns = require('lines-and-columns');
9
9
  var sourcemapCodec = require('@jridgewell/sourcemap-codec');
10
10
  var postcss = require('postcss');
@@ -30,16 +30,6 @@ function _interopNamespaceDefault(e) {
30
30
 
31
31
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
32
32
 
33
- const globalStyle = "\n" + compiler.util.formatSourceCode(
34
- `
35
- /* Injected by vite-plugin-qingkuai */
36
-
37
- *[hidden] {
38
- display: none !important;
39
- }
40
- `
41
- ).replace(/^/gm, " ") + "\n";
42
-
43
33
  function isUndefined(v) {
44
34
  return void 0 === v;
45
35
  }
@@ -62,15 +52,22 @@ function findFilesByName(dir, targetFileName, ignoreList) {
62
52
 
63
53
  async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
64
54
  let error;
65
- const hashAttribute = selectorParser.attribute({
66
- attribute: `qk-${hash}`,
67
- value: void 0,
68
- raws: {}
69
- });
55
+ const processedRules = /* @__PURE__ */ new WeakSet();
56
+ const createHashAttribute = () => {
57
+ return selectorParser.attribute({
58
+ attribute: `qk-${hash}`,
59
+ value: void 0,
60
+ raws: {}
61
+ });
62
+ };
70
63
  const processor = postcss([
71
64
  {
72
65
  postcssPlugin: "postcss-attach-scope-qingkuai",
73
66
  Rule(rule) {
67
+ if (processedRules.has(rule)) {
68
+ return;
69
+ }
70
+ processedRules.add(rule);
74
71
  if (rule.parent && "name" in rule?.parent && rule.parent.name === "keyframes") {
75
72
  return;
76
73
  }
@@ -80,7 +77,8 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
80
77
  for (let i = 0; i < selector.nodes.length; i++) {
81
78
  const item = selector.nodes[i];
82
79
  if (item.type === "attribute" && item.attribute === "qk-scope") {
83
- [usedScopeAttribute, selector.nodes[i]] = [true, hashAttribute];
80
+ selector.nodes[i] = createHashAttribute();
81
+ usedScopeAttribute = true;
84
82
  }
85
83
  }
86
84
  if (usedScopeAttribute) {
@@ -91,7 +89,7 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
91
89
  });
92
90
  if (index !== -1) {
93
91
  const lastNode = selector.nodes[index];
94
- lastNode.parent?.insertAfter(lastNode, hashAttribute);
92
+ lastNode.parent?.insertAfter(lastNode, createHashAttribute());
95
93
  }
96
94
  });
97
95
  }).processSync(rule.selector);
@@ -105,9 +103,26 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
105
103
  annotation: false
106
104
  }
107
105
  });
108
- return { error, code: ret.css, mappings: ret.map.toJSON().mappings };
106
+ const outputMap = ret.map?.toJSON();
107
+ return {
108
+ error,
109
+ code: ret.css,
110
+ map: outputMap,
111
+ mappings: outputMap?.mappings || ""
112
+ };
109
113
  }
110
114
 
115
+ const globalStyle = "\n" + compiler.util.formatSourceCode(
116
+ `
117
+ /* Injected by vite-plugin-qingkuai */
118
+
119
+ *[hidden] {
120
+ display: none !important;
121
+ }
122
+ `
123
+ ).replace(/^/gm, " ") + "\n";
124
+ const VIRTUAL_STYLE_ID_RE = /^virtual:\[\d+\].*?\.qk\.(css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
125
+
111
126
  function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
112
127
  return sourcemapCodec.decode(mappings).map((line) => {
113
128
  return line.map((segment) => {
@@ -127,18 +142,25 @@ async function getOriginalPosition(map, line, column) {
127
142
  return new sourceMapJs.SourceMapConsumer(map).originalPositionFor({ line, column });
128
143
  }
129
144
 
130
- function qingkuai() {
145
+ function qingkuai(options = {}) {
131
146
  let isDev;
132
147
  let sourcemap;
133
148
  let cssSourcemap;
134
149
  let viteConfig;
135
150
  const compileResultCache = /* @__PURE__ */ new Map();
136
151
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
137
- 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);
@@ -167,7 +189,7 @@ function qingkuai() {
167
189
  };
168
190
  },
169
191
  resolveId(id, importer) {
170
- if (styleIdRE.test(id)) {
192
+ if (VIRTUAL_STYLE_ID_RE.test(id)) {
171
193
  return id;
172
194
  }
173
195
  if (importer?.endsWith(".qk") && !nodePath.extname(id)) {
@@ -180,82 +202,112 @@ function qingkuai() {
180
202
  return id;
181
203
  },
182
204
  async load(id) {
183
- if (styleIdRE.test(id)) {
184
- const { fileId, index } = parseStyleId(id);
185
- if (index === -1) {
186
- return "";
187
- }
188
- let virtualFileName;
189
- const compileRes = compileResultCache.get(fileId);
190
- const style = compileRes.styleDescriptors[index];
191
- while (true) {
192
- const hash = nodeCrypto.randomBytes(6).toString("hex");
193
- virtualFileName = `${fileId}.${hash}.${style.lang}`;
194
- if (!nodeFs.existsSync(virtualFileName)) {
195
- break;
196
- }
205
+ if (!VIRTUAL_STYLE_ID_RE.test(id)) {
206
+ return;
207
+ }
208
+ const { fileId, index } = parseStyleId(id);
209
+ if (index === -1) {
210
+ return "";
211
+ }
212
+ let virtualFileName;
213
+ const compileRes = compileResultCache.get(fileId);
214
+ const style = compileRes.styleDescriptors[index];
215
+ while (true) {
216
+ const hash = nodeCrypto.randomBytes(6).toString("hex");
217
+ virtualFileName = `${fileId}.${hash}.${style.lang}`;
218
+ if (!nodeFs.existsSync(virtualFileName)) {
219
+ break;
197
220
  }
198
- const preprocessRes = await vite__namespace.preprocessCSS(style.code, virtualFileName, {
199
- ...viteConfig,
200
- css: {
201
- ...viteConfig.css,
202
- postcss: {
203
- from: virtualFileName
204
- }
221
+ }
222
+ const preprocessRes = await vite__namespace.preprocessCSS(style.code, virtualFileName, {
223
+ ...viteConfig,
224
+ css: {
225
+ ...viteConfig.css,
226
+ postcss: {
227
+ from: virtualFileName
205
228
  }
206
- });
207
- if (!cssSourcemap) {
208
- return preprocessRes.code;
209
229
  }
210
- const assertedPreprocessMap = preprocessRes.map;
211
- const attachScopeResult = await attachScopeForStyleSelectors(
212
- preprocessRes.code,
213
- compileRes.hashId,
214
- virtualFileName,
215
- assertedPreprocessMap
216
- );
217
- const offsetMappings = sourcemapCodec.encode(
218
- offsetSourceMap(
219
- attachScopeResult.mappings,
220
- preprocessRes.deps?.size || 0,
221
- style.loc.start.line - 1,
222
- style.loc.start.column - 1
223
- )
224
- );
225
- if (attachScopeResult.error) {
226
- if (!attachScopeResult.error.loc) {
227
- this.error(attachScopeResult.error.message);
228
- } else {
229
- const preprocessedPosition = await getOriginalPosition(
230
- assertedPreprocessMap,
231
- attachScopeResult.error.loc.line,
232
- attachScopeResult.error.loc.column
233
- );
234
- const preprocessedIndex = new linesAndColumns.LinesAndColumns(style.code).indexForLocation({
235
- line: preprocessedPosition.line - 1,
236
- column: preprocessedPosition.column
237
- }) || 0;
238
- const position = compileRes.positions[style.loc.start.index + preprocessedIndex];
230
+ });
231
+ if (!cssSourcemap || style.global) {
232
+ return preprocessRes;
233
+ }
234
+ const assertedPreprocessMap = preprocessRes.map;
235
+ const attachScopeResult = await attachScopeForStyleSelectors(
236
+ preprocessRes.code,
237
+ compileRes.hashId,
238
+ virtualFileName,
239
+ assertedPreprocessMap
240
+ );
241
+ const attachScopeMap = attachScopeResult.map ?? assertedPreprocessMap;
242
+ const samePath = (left, right) => {
243
+ return nodePath.normalize(left) === nodePath.normalize(right);
244
+ };
245
+ const sourceIndex = attachScopeMap?.sources.findIndex((source) => samePath(source, virtualFileName)) ?? -1;
246
+ const currentSourceIndex = sourceIndex === -1 ? preprocessRes.deps?.size || 0 : sourceIndex;
247
+ const offsetMappings = sourcemapCodec.encode(
248
+ offsetSourceMap(
249
+ attachScopeResult.mappings,
250
+ currentSourceIndex,
251
+ style.loc.start.line - 1,
252
+ style.loc.start.column - 1
253
+ )
254
+ );
255
+ if (attachScopeResult.error) {
256
+ if (!attachScopeResult.error.loc) {
257
+ this.error(attachScopeResult.error.message);
258
+ } else {
259
+ const preprocessedPosition = await getOriginalPosition(
260
+ assertedPreprocessMap,
261
+ attachScopeResult.error.loc.line,
262
+ attachScopeResult.error.loc.column
263
+ );
264
+ if (preprocessedPosition.source && !samePath(preprocessedPosition.source, virtualFileName)) {
239
265
  this.error({
240
266
  message: attachScopeResult.error.message,
241
267
  loc: {
242
- file: fileId,
243
- line: position.line,
244
- column: position.column
268
+ file: preprocessedPosition.source,
269
+ line: preprocessedPosition.line,
270
+ column: preprocessedPosition.column
245
271
  }
246
272
  });
247
273
  }
274
+ const preprocessedIndex = new linesAndColumns.LinesAndColumns(style.code).indexForLocation({
275
+ line: preprocessedPosition.line - 1,
276
+ column: preprocessedPosition.column
277
+ }) || 0;
278
+ const position = compileRes.positions[style.loc.start.index + preprocessedIndex];
279
+ this.error({
280
+ message: attachScopeResult.error.message,
281
+ loc: {
282
+ file: fileId,
283
+ line: position.line,
284
+ column: position.column
285
+ }
286
+ });
248
287
  }
249
- return {
250
- code: attachScopeResult.code,
251
- map: {
252
- version: 3,
253
- mappings: offsetMappings,
254
- names: assertedPreprocessMap?.names || [],
255
- sources: [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId]
256
- }
257
- };
258
288
  }
289
+ return {
290
+ code: attachScopeResult.code,
291
+ map: {
292
+ version: 3,
293
+ mappings: offsetMappings,
294
+ names: attachScopeMap?.names || assertedPreprocessMap?.names || [],
295
+ sources: attachScopeMap?.sources ? (() => {
296
+ const sources = [...attachScopeMap.sources];
297
+ if (currentSourceIndex !== -1) {
298
+ sources[currentSourceIndex] = fileId;
299
+ }
300
+ return sources;
301
+ })() : [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId],
302
+ sourcesContent: attachScopeMap?.sourcesContent ? (() => {
303
+ const sourcesContent = [...attachScopeMap.sourcesContent];
304
+ if (currentSourceIndex !== -1) {
305
+ sourcesContent[currentSourceIndex] = nodeFs.readFileSync(fileId, "utf-8");
306
+ }
307
+ return sourcesContent;
308
+ })() : void 0
309
+ }
310
+ };
259
311
  },
260
312
  async transform(src, id) {
261
313
  if (!id.endsWith(".qk")) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
- declare function qingkuai(): Plugin;
3
+ type InitOptions = Partial<{
4
+ maxScheduleDepth: number;
5
+ }>;
6
+
7
+ declare function qingkuai(options?: InitOptions): Plugin;
4
8
 
5
9
  export { qingkuai as default };
package/dist/index.js CHANGED
@@ -1,24 +1,14 @@
1
1
  import * as vite from 'vite';
2
+ import nodeFs from 'node:fs';
2
3
  import nodePath from 'node:path';
3
4
  import nodeCrypto from 'node:crypto';
4
5
  import { util, compile } from 'qingkuai/compiler';
5
- import nodeFs, { existsSync, readFileSync } from 'node:fs';
6
6
  import { LinesAndColumns } from 'lines-and-columns';
7
7
  import { decode, encode } from '@jridgewell/sourcemap-codec';
8
8
  import postcss from 'postcss';
9
9
  import selectorParser from 'postcss-selector-parser';
10
10
  import { SourceMapConsumer } from 'source-map-js';
11
11
 
12
- const globalStyle = "\n" + util.formatSourceCode(
13
- `
14
- /* Injected by vite-plugin-qingkuai */
15
-
16
- *[hidden] {
17
- display: none !important;
18
- }
19
- `
20
- ).replace(/^/gm, " ") + "\n";
21
-
22
12
  function isUndefined(v) {
23
13
  return void 0 === v;
24
14
  }
@@ -41,15 +31,22 @@ function findFilesByName(dir, targetFileName, ignoreList) {
41
31
 
42
32
  async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
43
33
  let error;
44
- const hashAttribute = selectorParser.attribute({
45
- attribute: `qk-${hash}`,
46
- value: void 0,
47
- raws: {}
48
- });
34
+ const processedRules = /* @__PURE__ */ new WeakSet();
35
+ const createHashAttribute = () => {
36
+ return selectorParser.attribute({
37
+ attribute: `qk-${hash}`,
38
+ value: void 0,
39
+ raws: {}
40
+ });
41
+ };
49
42
  const processor = postcss([
50
43
  {
51
44
  postcssPlugin: "postcss-attach-scope-qingkuai",
52
45
  Rule(rule) {
46
+ if (processedRules.has(rule)) {
47
+ return;
48
+ }
49
+ processedRules.add(rule);
53
50
  if (rule.parent && "name" in rule?.parent && rule.parent.name === "keyframes") {
54
51
  return;
55
52
  }
@@ -59,7 +56,8 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
59
56
  for (let i = 0; i < selector.nodes.length; i++) {
60
57
  const item = selector.nodes[i];
61
58
  if (item.type === "attribute" && item.attribute === "qk-scope") {
62
- [usedScopeAttribute, selector.nodes[i]] = [true, hashAttribute];
59
+ selector.nodes[i] = createHashAttribute();
60
+ usedScopeAttribute = true;
63
61
  }
64
62
  }
65
63
  if (usedScopeAttribute) {
@@ -70,7 +68,7 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
70
68
  });
71
69
  if (index !== -1) {
72
70
  const lastNode = selector.nodes[index];
73
- lastNode.parent?.insertAfter(lastNode, hashAttribute);
71
+ lastNode.parent?.insertAfter(lastNode, createHashAttribute());
74
72
  }
75
73
  });
76
74
  }).processSync(rule.selector);
@@ -84,9 +82,26 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
84
82
  annotation: false
85
83
  }
86
84
  });
87
- return { error, code: ret.css, mappings: ret.map.toJSON().mappings };
85
+ const outputMap = ret.map?.toJSON();
86
+ return {
87
+ error,
88
+ code: ret.css,
89
+ map: outputMap,
90
+ mappings: outputMap?.mappings || ""
91
+ };
88
92
  }
89
93
 
94
+ const globalStyle = "\n" + util.formatSourceCode(
95
+ `
96
+ /* Injected by vite-plugin-qingkuai */
97
+
98
+ *[hidden] {
99
+ display: none !important;
100
+ }
101
+ `
102
+ ).replace(/^/gm, " ") + "\n";
103
+ const VIRTUAL_STYLE_ID_RE = /^virtual:\[\d+\].*?\.qk\.(css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
104
+
90
105
  function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
91
106
  return decode(mappings).map((line) => {
92
107
  return line.map((segment) => {
@@ -106,18 +121,25 @@ async function getOriginalPosition(map, line, column) {
106
121
  return new SourceMapConsumer(map).originalPositionFor({ line, column });
107
122
  }
108
123
 
109
- function qingkuai() {
124
+ function qingkuai(options = {}) {
110
125
  let isDev;
111
126
  let sourcemap;
112
127
  let cssSourcemap;
113
128
  let viteConfig;
114
129
  const compileResultCache = /* @__PURE__ */ new Map();
115
130
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
116
- 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);
@@ -146,7 +168,7 @@ function qingkuai() {
146
168
  };
147
169
  },
148
170
  resolveId(id, importer) {
149
- if (styleIdRE.test(id)) {
171
+ if (VIRTUAL_STYLE_ID_RE.test(id)) {
150
172
  return id;
151
173
  }
152
174
  if (importer?.endsWith(".qk") && !nodePath.extname(id)) {
@@ -159,82 +181,112 @@ function qingkuai() {
159
181
  return id;
160
182
  },
161
183
  async load(id) {
162
- if (styleIdRE.test(id)) {
163
- const { fileId, index } = parseStyleId(id);
164
- if (index === -1) {
165
- return "";
166
- }
167
- let virtualFileName;
168
- const compileRes = compileResultCache.get(fileId);
169
- const style = compileRes.styleDescriptors[index];
170
- while (true) {
171
- const hash = nodeCrypto.randomBytes(6).toString("hex");
172
- virtualFileName = `${fileId}.${hash}.${style.lang}`;
173
- if (!existsSync(virtualFileName)) {
174
- break;
175
- }
184
+ if (!VIRTUAL_STYLE_ID_RE.test(id)) {
185
+ return;
186
+ }
187
+ const { fileId, index } = parseStyleId(id);
188
+ if (index === -1) {
189
+ return "";
190
+ }
191
+ let virtualFileName;
192
+ const compileRes = compileResultCache.get(fileId);
193
+ const style = compileRes.styleDescriptors[index];
194
+ while (true) {
195
+ const hash = nodeCrypto.randomBytes(6).toString("hex");
196
+ virtualFileName = `${fileId}.${hash}.${style.lang}`;
197
+ if (!nodeFs.existsSync(virtualFileName)) {
198
+ break;
176
199
  }
177
- const preprocessRes = await vite.preprocessCSS(style.code, virtualFileName, {
178
- ...viteConfig,
179
- css: {
180
- ...viteConfig.css,
181
- postcss: {
182
- from: virtualFileName
183
- }
200
+ }
201
+ const preprocessRes = await vite.preprocessCSS(style.code, virtualFileName, {
202
+ ...viteConfig,
203
+ css: {
204
+ ...viteConfig.css,
205
+ postcss: {
206
+ from: virtualFileName
184
207
  }
185
- });
186
- if (!cssSourcemap) {
187
- return preprocessRes.code;
188
208
  }
189
- const assertedPreprocessMap = preprocessRes.map;
190
- const attachScopeResult = await attachScopeForStyleSelectors(
191
- preprocessRes.code,
192
- compileRes.hashId,
193
- virtualFileName,
194
- assertedPreprocessMap
195
- );
196
- const offsetMappings = encode(
197
- offsetSourceMap(
198
- attachScopeResult.mappings,
199
- preprocessRes.deps?.size || 0,
200
- style.loc.start.line - 1,
201
- style.loc.start.column - 1
202
- )
203
- );
204
- if (attachScopeResult.error) {
205
- if (!attachScopeResult.error.loc) {
206
- this.error(attachScopeResult.error.message);
207
- } else {
208
- const preprocessedPosition = await getOriginalPosition(
209
- assertedPreprocessMap,
210
- attachScopeResult.error.loc.line,
211
- attachScopeResult.error.loc.column
212
- );
213
- const preprocessedIndex = new LinesAndColumns(style.code).indexForLocation({
214
- line: preprocessedPosition.line - 1,
215
- column: preprocessedPosition.column
216
- }) || 0;
217
- const position = compileRes.positions[style.loc.start.index + preprocessedIndex];
209
+ });
210
+ if (!cssSourcemap || style.global) {
211
+ return preprocessRes;
212
+ }
213
+ const assertedPreprocessMap = preprocessRes.map;
214
+ const attachScopeResult = await attachScopeForStyleSelectors(
215
+ preprocessRes.code,
216
+ compileRes.hashId,
217
+ virtualFileName,
218
+ assertedPreprocessMap
219
+ );
220
+ const attachScopeMap = attachScopeResult.map ?? assertedPreprocessMap;
221
+ const samePath = (left, right) => {
222
+ return nodePath.normalize(left) === nodePath.normalize(right);
223
+ };
224
+ const sourceIndex = attachScopeMap?.sources.findIndex((source) => samePath(source, virtualFileName)) ?? -1;
225
+ const currentSourceIndex = sourceIndex === -1 ? preprocessRes.deps?.size || 0 : sourceIndex;
226
+ const offsetMappings = encode(
227
+ offsetSourceMap(
228
+ attachScopeResult.mappings,
229
+ currentSourceIndex,
230
+ style.loc.start.line - 1,
231
+ style.loc.start.column - 1
232
+ )
233
+ );
234
+ if (attachScopeResult.error) {
235
+ if (!attachScopeResult.error.loc) {
236
+ this.error(attachScopeResult.error.message);
237
+ } else {
238
+ const preprocessedPosition = await getOriginalPosition(
239
+ assertedPreprocessMap,
240
+ attachScopeResult.error.loc.line,
241
+ attachScopeResult.error.loc.column
242
+ );
243
+ if (preprocessedPosition.source && !samePath(preprocessedPosition.source, virtualFileName)) {
218
244
  this.error({
219
245
  message: attachScopeResult.error.message,
220
246
  loc: {
221
- file: fileId,
222
- line: position.line,
223
- column: position.column
247
+ file: preprocessedPosition.source,
248
+ line: preprocessedPosition.line,
249
+ column: preprocessedPosition.column
224
250
  }
225
251
  });
226
252
  }
253
+ const preprocessedIndex = new LinesAndColumns(style.code).indexForLocation({
254
+ line: preprocessedPosition.line - 1,
255
+ column: preprocessedPosition.column
256
+ }) || 0;
257
+ const position = compileRes.positions[style.loc.start.index + preprocessedIndex];
258
+ this.error({
259
+ message: attachScopeResult.error.message,
260
+ loc: {
261
+ file: fileId,
262
+ line: position.line,
263
+ column: position.column
264
+ }
265
+ });
227
266
  }
228
- return {
229
- code: attachScopeResult.code,
230
- map: {
231
- version: 3,
232
- mappings: offsetMappings,
233
- names: assertedPreprocessMap?.names || [],
234
- sources: [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId]
235
- }
236
- };
237
267
  }
268
+ return {
269
+ code: attachScopeResult.code,
270
+ map: {
271
+ version: 3,
272
+ mappings: offsetMappings,
273
+ names: attachScopeMap?.names || assertedPreprocessMap?.names || [],
274
+ sources: attachScopeMap?.sources ? (() => {
275
+ const sources = [...attachScopeMap.sources];
276
+ if (currentSourceIndex !== -1) {
277
+ sources[currentSourceIndex] = fileId;
278
+ }
279
+ return sources;
280
+ })() : [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId],
281
+ sourcesContent: attachScopeMap?.sourcesContent ? (() => {
282
+ const sourcesContent = [...attachScopeMap.sourcesContent];
283
+ if (currentSourceIndex !== -1) {
284
+ sourcesContent[currentSourceIndex] = nodeFs.readFileSync(fileId, "utf-8");
285
+ }
286
+ return sourcesContent;
287
+ })() : void 0
288
+ }
289
+ };
238
290
  },
239
291
  async transform(src, id) {
240
292
  if (!id.endsWith(".qk")) {
@@ -367,7 +419,7 @@ function qingkuai() {
367
419
  }
368
420
  function recordQingkuaiConfiguration(fileName) {
369
421
  try {
370
- qingkuaiConfigurations.set(nodePath.dirname(fileName), JSON.parse(readFileSync(fileName, "utf-8")));
422
+ qingkuaiConfigurations.set(nodePath.dirname(fileName), JSON.parse(nodeFs.readFileSync(fileName, "utf-8")));
371
423
  } catch {
372
424
  }
373
425
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vite-plugin-qingkuai",
3
3
  "author": "mlgq",
4
4
  "license": "MIT",
5
- "version": "1.0.20",
5
+ "version": "1.0.22",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "vite",