vite-plugin-qingkuai 1.0.21 → 1.0.23

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.
Files changed (3) hide show
  1. package/dist/index.cjs +149 -101
  2. package/dist/index.js +151 -103
  3. package/package.json +1 -1
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,9 @@ 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
-
33
+ function isNumber(v) {
34
+ return typeof v === "number";
35
+ }
43
36
  function isUndefined(v) {
44
37
  return void 0 === v;
45
38
  }
@@ -122,6 +115,17 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
122
115
  };
123
116
  }
124
117
 
118
+ const globalStyle = "\n" + compiler.util.formatSourceCode(
119
+ `
120
+ /* Injected by vite-plugin-qingkuai */
121
+
122
+ *[hidden] {
123
+ display: none !important;
124
+ }
125
+ `
126
+ ).replace(/^/gm, " ") + "\n";
127
+ const VIRTUAL_STYLE_ID_RE = /^virtual:\[\d+\].*?\.qk\.(css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
128
+
125
129
  function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
126
130
  return sourcemapCodec.decode(mappings).map((line) => {
127
131
  return line.map((segment) => {
@@ -148,7 +152,6 @@ function qingkuai(options = {}) {
148
152
  let viteConfig;
149
153
  const compileResultCache = /* @__PURE__ */ new Map();
150
154
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
151
- const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
152
155
  if (isUndefined(options.maxScheduleDepth)) {
153
156
  options.maxScheduleDepth = 300;
154
157
  }
@@ -189,7 +192,7 @@ function qingkuai(options = {}) {
189
192
  };
190
193
  },
191
194
  resolveId(id, importer) {
192
- if (styleIdRE.test(id)) {
195
+ if (VIRTUAL_STYLE_ID_RE.test(id)) {
193
196
  return id;
194
197
  }
195
198
  if (importer?.endsWith(".qk") && !nodePath.extname(id)) {
@@ -202,22 +205,26 @@ function qingkuai(options = {}) {
202
205
  return id;
203
206
  },
204
207
  async load(id) {
205
- if (styleIdRE.test(id)) {
206
- const { fileId, index } = parseStyleId(id);
207
- if (index === -1) {
208
- return "";
209
- }
210
- let virtualFileName;
211
- const compileRes = compileResultCache.get(fileId);
212
- const style = compileRes.styleDescriptors[index];
213
- while (true) {
214
- const hash = nodeCrypto.randomBytes(6).toString("hex");
215
- virtualFileName = `${fileId}.${hash}.${style.lang}`;
216
- if (!nodeFs.existsSync(virtualFileName)) {
217
- break;
218
- }
208
+ if (!VIRTUAL_STYLE_ID_RE.test(id)) {
209
+ return;
210
+ }
211
+ const { fileId, index } = parseStyleId(id);
212
+ if (index === -1) {
213
+ return "";
214
+ }
215
+ let virtualFileName;
216
+ const compileRes = compileResultCache.get(fileId);
217
+ const styleDescriptor = compileRes.styleDescriptors[index];
218
+ while (true) {
219
+ const hash = nodeCrypto.randomBytes(6).toString("hex");
220
+ virtualFileName = `${fileId}.${hash}.${styleDescriptor.lang}`;
221
+ if (!nodeFs.existsSync(virtualFileName)) {
222
+ break;
219
223
  }
220
- const preprocessRes = await vite__namespace.preprocessCSS(style.code, virtualFileName, {
224
+ }
225
+ let preprocessRes;
226
+ try {
227
+ preprocessRes = await vite__namespace.preprocessCSS(styleDescriptor.code, virtualFileName, {
221
228
  ...viteConfig,
222
229
  css: {
223
230
  ...viteConfig.css,
@@ -226,87 +233,126 @@ function qingkuai(options = {}) {
226
233
  }
227
234
  }
228
235
  });
229
- if (!cssSourcemap) {
230
- return preprocessRes.code;
231
- }
232
- const assertedPreprocessMap = preprocessRes.map;
233
- const attachScopeResult = await attachScopeForStyleSelectors(
234
- preprocessRes.code,
235
- compileRes.hashId,
236
- virtualFileName,
237
- assertedPreprocessMap
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;
245
- const offsetMappings = sourcemapCodec.encode(
246
- offsetSourceMap(
247
- attachScopeResult.mappings,
248
- currentSourceIndex,
249
- style.loc.start.line - 1,
250
- style.loc.start.column - 1
251
- )
252
- );
253
- if (attachScopeResult.error) {
254
- if (!attachScopeResult.error.loc) {
255
- this.error(attachScopeResult.error.message);
256
- } else {
257
- const preprocessedPosition = await getOriginalPosition(
258
- assertedPreprocessMap,
259
- attachScopeResult.error.loc.line,
260
- attachScopeResult.error.loc.column
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
- }
236
+ } catch (err) {
237
+ let errorPos = null;
238
+ const lac = new linesAndColumns.LinesAndColumns(styleDescriptor.code);
239
+ switch (styleDescriptor.lang) {
240
+ case "css":
241
+ case "less":
242
+ case "stylus": {
243
+ delete err.loc;
244
+ err.message += `
245
+
246
+ Caused by: "${fileId}".`;
247
+ break;
248
+ }
249
+ case "sass":
250
+ case "scss": {
251
+ if (err.sassMessage) {
252
+ err.message = err.sassMessage;
253
+ }
254
+ if (isNumber(err.line) && isNumber(err.column)) {
255
+ errorPos = lac.indexForLocation({
256
+ line: err.line - 1,
257
+ column: err.column - 1
270
258
  });
271
259
  }
272
- const preprocessedIndex = new linesAndColumns.LinesAndColumns(style.code).indexForLocation({
273
- line: preprocessedPosition.line - 1,
274
- column: preprocessedPosition.column
275
- }) || 0;
276
- const position = compileRes.positions[style.loc.start.index + preprocessedIndex];
260
+ break;
261
+ }
262
+ }
263
+ if (isNumber(errorPos) && !isNaN(errorPos)) {
264
+ const loc = lac.locationForIndex(errorPos + styleDescriptor.loc.start.index);
265
+ if (loc) {
266
+ err.loc = {
267
+ file: fileId,
268
+ line: loc.line + 1,
269
+ column: loc.column
270
+ };
271
+ delete err.frame;
272
+ }
273
+ }
274
+ return this.error(err);
275
+ }
276
+ if (!cssSourcemap || styleDescriptor.global) {
277
+ return preprocessRes;
278
+ }
279
+ const assertedPreprocessMap = preprocessRes.map;
280
+ const attachScopeResult = await attachScopeForStyleSelectors(
281
+ preprocessRes.code,
282
+ compileRes.hashId,
283
+ virtualFileName,
284
+ assertedPreprocessMap
285
+ );
286
+ const attachScopeMap = attachScopeResult.map ?? assertedPreprocessMap;
287
+ const samePath = (left, right) => {
288
+ return nodePath.normalize(left) === nodePath.normalize(right);
289
+ };
290
+ const sourceIndex = attachScopeMap?.sources.findIndex((source) => samePath(source, virtualFileName)) ?? -1;
291
+ const currentSourceIndex = sourceIndex === -1 ? preprocessRes.deps?.size || 0 : sourceIndex;
292
+ const offsetMappings = sourcemapCodec.encode(
293
+ offsetSourceMap(
294
+ attachScopeResult.mappings,
295
+ currentSourceIndex,
296
+ styleDescriptor.loc.start.line - 1,
297
+ styleDescriptor.loc.start.column - 1
298
+ )
299
+ );
300
+ if (attachScopeResult.error) {
301
+ if (!attachScopeResult.error.loc) {
302
+ this.error(attachScopeResult.error.message);
303
+ } else {
304
+ const preprocessedPosition = await getOriginalPosition(
305
+ assertedPreprocessMap,
306
+ attachScopeResult.error.loc.line,
307
+ attachScopeResult.error.loc.column
308
+ );
309
+ if (preprocessedPosition.source && !samePath(preprocessedPosition.source, virtualFileName)) {
277
310
  this.error({
278
311
  message: attachScopeResult.error.message,
279
312
  loc: {
280
- file: fileId,
281
- line: position.line,
282
- column: position.column
313
+ file: preprocessedPosition.source,
314
+ line: preprocessedPosition.line,
315
+ column: preprocessedPosition.column
283
316
  }
284
317
  });
285
318
  }
319
+ const preprocessedIndex = new linesAndColumns.LinesAndColumns(styleDescriptor.code).indexForLocation({
320
+ line: preprocessedPosition.line - 1,
321
+ column: preprocessedPosition.column
322
+ }) || 0;
323
+ const position = compileRes.positions[styleDescriptor.loc.start.index + preprocessedIndex];
324
+ this.error({
325
+ message: attachScopeResult.error.message,
326
+ loc: {
327
+ file: fileId,
328
+ line: position.line,
329
+ column: position.column
330
+ }
331
+ });
286
332
  }
287
- return {
288
- code: attachScopeResult.code,
289
- map: {
290
- version: 3,
291
- mappings: offsetMappings,
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
307
- }
308
- };
309
333
  }
334
+ return {
335
+ code: attachScopeResult.code,
336
+ map: {
337
+ version: 3,
338
+ mappings: offsetMappings,
339
+ names: attachScopeMap?.names || assertedPreprocessMap?.names || [],
340
+ sources: attachScopeMap?.sources ? (() => {
341
+ const sources = [...attachScopeMap.sources];
342
+ if (currentSourceIndex !== -1) {
343
+ sources[currentSourceIndex] = fileId;
344
+ }
345
+ return sources;
346
+ })() : [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId],
347
+ sourcesContent: attachScopeMap?.sourcesContent ? (() => {
348
+ const sourcesContent = [...attachScopeMap.sourcesContent];
349
+ if (currentSourceIndex !== -1) {
350
+ sourcesContent[currentSourceIndex] = nodeFs.readFileSync(fileId, "utf-8");
351
+ }
352
+ return sourcesContent;
353
+ })() : void 0
354
+ }
355
+ };
310
356
  },
311
357
  async transform(src, id) {
312
358
  if (!id.endsWith(".qk")) {
@@ -382,8 +428,10 @@ function qingkuai(options = {}) {
382
428
  })
383
429
  };
384
430
  } catch (err) {
385
- if (err.loc && "start" in err.loc && "index" in err.loc.start) {
386
- err.pos = err.loc.start.index, this.error(err);
431
+ if (compiler.isCompileError(err)) {
432
+ this.error(err.message, err.loc.start.index);
433
+ } else if (err.cause && isNumber(err.cause.pos)) {
434
+ this.error(err, err.cause.pos);
387
435
  } else {
388
436
  this.error(
389
437
  "Qingkuai compile result is invalid. Please report this at https://github.com/qingkuai-js/qingkuai/issues and include your .qk source for reproduction."
package/dist/index.js CHANGED
@@ -1,24 +1,17 @@
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
- import { util, compile } from 'qingkuai/compiler';
5
- import nodeFs, { existsSync, readFileSync } from 'node:fs';
5
+ import { util, compile, isCompileError } from 'qingkuai/compiler';
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
-
12
+ function isNumber(v) {
13
+ return typeof v === "number";
14
+ }
22
15
  function isUndefined(v) {
23
16
  return void 0 === v;
24
17
  }
@@ -101,6 +94,17 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
101
94
  };
102
95
  }
103
96
 
97
+ const globalStyle = "\n" + util.formatSourceCode(
98
+ `
99
+ /* Injected by vite-plugin-qingkuai */
100
+
101
+ *[hidden] {
102
+ display: none !important;
103
+ }
104
+ `
105
+ ).replace(/^/gm, " ") + "\n";
106
+ const VIRTUAL_STYLE_ID_RE = /^virtual:\[\d+\].*?\.qk\.(css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
107
+
104
108
  function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
105
109
  return decode(mappings).map((line) => {
106
110
  return line.map((segment) => {
@@ -127,7 +131,6 @@ function qingkuai(options = {}) {
127
131
  let viteConfig;
128
132
  const compileResultCache = /* @__PURE__ */ new Map();
129
133
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
130
- const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
131
134
  if (isUndefined(options.maxScheduleDepth)) {
132
135
  options.maxScheduleDepth = 300;
133
136
  }
@@ -168,7 +171,7 @@ function qingkuai(options = {}) {
168
171
  };
169
172
  },
170
173
  resolveId(id, importer) {
171
- if (styleIdRE.test(id)) {
174
+ if (VIRTUAL_STYLE_ID_RE.test(id)) {
172
175
  return id;
173
176
  }
174
177
  if (importer?.endsWith(".qk") && !nodePath.extname(id)) {
@@ -181,22 +184,26 @@ function qingkuai(options = {}) {
181
184
  return id;
182
185
  },
183
186
  async load(id) {
184
- if (styleIdRE.test(id)) {
185
- const { fileId, index } = parseStyleId(id);
186
- if (index === -1) {
187
- return "";
188
- }
189
- let virtualFileName;
190
- const compileRes = compileResultCache.get(fileId);
191
- const style = compileRes.styleDescriptors[index];
192
- while (true) {
193
- const hash = nodeCrypto.randomBytes(6).toString("hex");
194
- virtualFileName = `${fileId}.${hash}.${style.lang}`;
195
- if (!existsSync(virtualFileName)) {
196
- break;
197
- }
187
+ if (!VIRTUAL_STYLE_ID_RE.test(id)) {
188
+ return;
189
+ }
190
+ const { fileId, index } = parseStyleId(id);
191
+ if (index === -1) {
192
+ return "";
193
+ }
194
+ let virtualFileName;
195
+ const compileRes = compileResultCache.get(fileId);
196
+ const styleDescriptor = compileRes.styleDescriptors[index];
197
+ while (true) {
198
+ const hash = nodeCrypto.randomBytes(6).toString("hex");
199
+ virtualFileName = `${fileId}.${hash}.${styleDescriptor.lang}`;
200
+ if (!nodeFs.existsSync(virtualFileName)) {
201
+ break;
198
202
  }
199
- const preprocessRes = await vite.preprocessCSS(style.code, virtualFileName, {
203
+ }
204
+ let preprocessRes;
205
+ try {
206
+ preprocessRes = await vite.preprocessCSS(styleDescriptor.code, virtualFileName, {
200
207
  ...viteConfig,
201
208
  css: {
202
209
  ...viteConfig.css,
@@ -205,87 +212,126 @@ function qingkuai(options = {}) {
205
212
  }
206
213
  }
207
214
  });
208
- if (!cssSourcemap) {
209
- return preprocessRes.code;
210
- }
211
- const assertedPreprocessMap = preprocessRes.map;
212
- const attachScopeResult = await attachScopeForStyleSelectors(
213
- preprocessRes.code,
214
- compileRes.hashId,
215
- virtualFileName,
216
- assertedPreprocessMap
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;
224
- const offsetMappings = encode(
225
- offsetSourceMap(
226
- attachScopeResult.mappings,
227
- currentSourceIndex,
228
- style.loc.start.line - 1,
229
- style.loc.start.column - 1
230
- )
231
- );
232
- if (attachScopeResult.error) {
233
- if (!attachScopeResult.error.loc) {
234
- this.error(attachScopeResult.error.message);
235
- } else {
236
- const preprocessedPosition = await getOriginalPosition(
237
- assertedPreprocessMap,
238
- attachScopeResult.error.loc.line,
239
- attachScopeResult.error.loc.column
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
- }
215
+ } catch (err) {
216
+ let errorPos = null;
217
+ const lac = new LinesAndColumns(styleDescriptor.code);
218
+ switch (styleDescriptor.lang) {
219
+ case "css":
220
+ case "less":
221
+ case "stylus": {
222
+ delete err.loc;
223
+ err.message += `
224
+
225
+ Caused by: "${fileId}".`;
226
+ break;
227
+ }
228
+ case "sass":
229
+ case "scss": {
230
+ if (err.sassMessage) {
231
+ err.message = err.sassMessage;
232
+ }
233
+ if (isNumber(err.line) && isNumber(err.column)) {
234
+ errorPos = lac.indexForLocation({
235
+ line: err.line - 1,
236
+ column: err.column - 1
249
237
  });
250
238
  }
251
- const preprocessedIndex = new LinesAndColumns(style.code).indexForLocation({
252
- line: preprocessedPosition.line - 1,
253
- column: preprocessedPosition.column
254
- }) || 0;
255
- const position = compileRes.positions[style.loc.start.index + preprocessedIndex];
239
+ break;
240
+ }
241
+ }
242
+ if (isNumber(errorPos) && !isNaN(errorPos)) {
243
+ const loc = lac.locationForIndex(errorPos + styleDescriptor.loc.start.index);
244
+ if (loc) {
245
+ err.loc = {
246
+ file: fileId,
247
+ line: loc.line + 1,
248
+ column: loc.column
249
+ };
250
+ delete err.frame;
251
+ }
252
+ }
253
+ return this.error(err);
254
+ }
255
+ if (!cssSourcemap || styleDescriptor.global) {
256
+ return preprocessRes;
257
+ }
258
+ const assertedPreprocessMap = preprocessRes.map;
259
+ const attachScopeResult = await attachScopeForStyleSelectors(
260
+ preprocessRes.code,
261
+ compileRes.hashId,
262
+ virtualFileName,
263
+ assertedPreprocessMap
264
+ );
265
+ const attachScopeMap = attachScopeResult.map ?? assertedPreprocessMap;
266
+ const samePath = (left, right) => {
267
+ return nodePath.normalize(left) === nodePath.normalize(right);
268
+ };
269
+ const sourceIndex = attachScopeMap?.sources.findIndex((source) => samePath(source, virtualFileName)) ?? -1;
270
+ const currentSourceIndex = sourceIndex === -1 ? preprocessRes.deps?.size || 0 : sourceIndex;
271
+ const offsetMappings = encode(
272
+ offsetSourceMap(
273
+ attachScopeResult.mappings,
274
+ currentSourceIndex,
275
+ styleDescriptor.loc.start.line - 1,
276
+ styleDescriptor.loc.start.column - 1
277
+ )
278
+ );
279
+ if (attachScopeResult.error) {
280
+ if (!attachScopeResult.error.loc) {
281
+ this.error(attachScopeResult.error.message);
282
+ } else {
283
+ const preprocessedPosition = await getOriginalPosition(
284
+ assertedPreprocessMap,
285
+ attachScopeResult.error.loc.line,
286
+ attachScopeResult.error.loc.column
287
+ );
288
+ if (preprocessedPosition.source && !samePath(preprocessedPosition.source, virtualFileName)) {
256
289
  this.error({
257
290
  message: attachScopeResult.error.message,
258
291
  loc: {
259
- file: fileId,
260
- line: position.line,
261
- column: position.column
292
+ file: preprocessedPosition.source,
293
+ line: preprocessedPosition.line,
294
+ column: preprocessedPosition.column
262
295
  }
263
296
  });
264
297
  }
298
+ const preprocessedIndex = new LinesAndColumns(styleDescriptor.code).indexForLocation({
299
+ line: preprocessedPosition.line - 1,
300
+ column: preprocessedPosition.column
301
+ }) || 0;
302
+ const position = compileRes.positions[styleDescriptor.loc.start.index + preprocessedIndex];
303
+ this.error({
304
+ message: attachScopeResult.error.message,
305
+ loc: {
306
+ file: fileId,
307
+ line: position.line,
308
+ column: position.column
309
+ }
310
+ });
265
311
  }
266
- return {
267
- code: attachScopeResult.code,
268
- map: {
269
- version: 3,
270
- mappings: offsetMappings,
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
286
- }
287
- };
288
312
  }
313
+ return {
314
+ code: attachScopeResult.code,
315
+ map: {
316
+ version: 3,
317
+ mappings: offsetMappings,
318
+ names: attachScopeMap?.names || assertedPreprocessMap?.names || [],
319
+ sources: attachScopeMap?.sources ? (() => {
320
+ const sources = [...attachScopeMap.sources];
321
+ if (currentSourceIndex !== -1) {
322
+ sources[currentSourceIndex] = fileId;
323
+ }
324
+ return sources;
325
+ })() : [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId],
326
+ sourcesContent: attachScopeMap?.sourcesContent ? (() => {
327
+ const sourcesContent = [...attachScopeMap.sourcesContent];
328
+ if (currentSourceIndex !== -1) {
329
+ sourcesContent[currentSourceIndex] = nodeFs.readFileSync(fileId, "utf-8");
330
+ }
331
+ return sourcesContent;
332
+ })() : void 0
333
+ }
334
+ };
289
335
  },
290
336
  async transform(src, id) {
291
337
  if (!id.endsWith(".qk")) {
@@ -361,8 +407,10 @@ function qingkuai(options = {}) {
361
407
  })
362
408
  };
363
409
  } catch (err) {
364
- if (err.loc && "start" in err.loc && "index" in err.loc.start) {
365
- err.pos = err.loc.start.index, this.error(err);
410
+ if (isCompileError(err)) {
411
+ this.error(err.message, err.loc.start.index);
412
+ } else if (err.cause && isNumber(err.cause.pos)) {
413
+ this.error(err, err.cause.pos);
366
414
  } else {
367
415
  this.error(
368
416
  "Qingkuai compile result is invalid. Please report this at https://github.com/qingkuai-js/qingkuai/issues and include your .qk source for reproduction."
@@ -418,7 +466,7 @@ function qingkuai(options = {}) {
418
466
  }
419
467
  function recordQingkuaiConfiguration(fileName) {
420
468
  try {
421
- qingkuaiConfigurations.set(nodePath.dirname(fileName), JSON.parse(readFileSync(fileName, "utf-8")));
469
+ qingkuaiConfigurations.set(nodePath.dirname(fileName), JSON.parse(nodeFs.readFileSync(fileName, "utf-8")));
422
470
  } catch {
423
471
  }
424
472
  }
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.21",
5
+ "version": "1.0.23",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "vite",