create-yeow 0.2.42 → 0.2.43

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-yeow",
3
- "version": "0.2.42",
3
+ "version": "0.2.43",
4
4
  "description": "Scaffold a Yeow plugin project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -203,48 +203,65 @@ async function printFormattedError(err) {
203
203
  out += ` ${c.Y}${err.message}${c.r}\n`;
204
204
 
205
205
  const consumer = (err.fileName === 'main.js' || err.stack) ? await getSourceMapConsumer() : null;
206
- if (consumer) {
207
- if (err.lineNumber > 0) {
208
- const orig = consumer.originalPositionFor({ line: err.lineNumber, column: err.columnNumber || 0 });
209
- if (orig.source && orig.line) {
210
- const srcPath = orig.source.replace(/^\.\.\/\.\.\//, '');
211
- out += ` ${c.C}at ${srcPath}:${orig.line}:${orig.column}${c.r}\n`;
212
- const content = consumer.sourceContentFor(orig.source);
213
- if (content) {
214
- const lines = content.split('\n');
215
- const start = Math.max(0, orig.line - 3);
216
- const end = Math.min(lines.length, orig.line + 2);
217
- for (let i = start; i < end; i++) {
218
- const prefix = i === orig.line - 1 ? c.R + ' →' : ' ';
219
- out += ` ${prefix} ${c.D}${String(i + 1).padStart(4)}|${c.r} ${lines[i]}\n`;
220
- if (i === orig.line - 1 && orig.column > 0) {
221
- const col = Math.max(0, orig.column);
222
- const indent = ' '.repeat(String(i + 1).padStart(4).length) + '| ';
223
- const caret = ' '.repeat(col) + c.R + '^' + c.r;
224
- out += ` ${c.R} →${c.r} ${indent}${caret}\n`;
225
- }
226
- }
227
- }
206
+ if (!consumer) {
207
+ if (err.stack) err.stack.split('\n').slice(0, 5).forEach(l => { out += ` ${c.D} ${l.trim()}${c.r}\n`; });
208
+ console.log(out);
209
+ return;
210
+ }
211
+
212
+ // Resolve all stack frames
213
+ const frames = [];
214
+ if (err.stack) {
215
+ for (const line of err.stack.split('\n')) {
216
+ const m = line.match(/at\s+(?:\S+\s+)?\(?(?:\/main\.js|[^:]+):(\d+):(\d+)\)?/);
217
+ if (m) {
218
+ const orig = consumer.originalPositionFor({ line: parseInt(m[1]), column: parseInt(m[2]) });
219
+ frames.push({ orig, raw: line });
220
+ } else {
221
+ frames.push({ raw: line });
228
222
  }
229
223
  }
230
- if (err.stack) {
231
- const stackLines = err.stack.split('\n');
232
- for (let i = 0; i < Math.min(stackLines.length, 8); i++) {
233
- const line = stackLines[i].trim();
234
- const m = line.match(/at\s+(?:\S+\s+)?\(?(?:\/main\.js|[^:]+):(\d+):(\d+)\)?/);
235
- if (m) {
236
- const orig = consumer.originalPositionFor({ line: parseInt(m[1]), column: parseInt(m[2]) });
237
- if (orig.source) {
238
- const srcPath = orig.source.replace(/^\.\.\/\.\.\//, '');
239
- out += ` ${c.D} at ${srcPath}:${orig.line}:${orig.column}${c.r}\n`;
240
- continue;
241
- }
224
+ }
225
+
226
+ // Find first frame from user's src/ directory (not node_modules)
227
+ let ctxFrame = frames.find(f => f.orig?.source?.match(/[\\/]src[\\/]/) && !f.orig.source.includes('node_modules'))?.orig || null;
228
+ if (!ctxFrame && err.lineNumber > 0) {
229
+ ctxFrame = consumer.originalPositionFor({ line: err.lineNumber, column: err.columnNumber || 0 });
230
+ }
231
+
232
+ // Show context for the chosen frame
233
+ if (ctxFrame?.source && ctxFrame.line) {
234
+ const srcPath = ctxFrame.source.replace(/^\.\.\/\.\.\//, '');
235
+ out += ` ${c.C}at ${srcPath}:${ctxFrame.line}:${ctxFrame.column}${c.r}\n`;
236
+ const content = consumer.sourceContentFor(ctxFrame.source);
237
+ if (content) {
238
+ const lines = content.split('\n');
239
+ const start = Math.max(0, ctxFrame.line - 3);
240
+ const end = Math.min(lines.length, ctxFrame.line + 2);
241
+ for (let i = start; i < end; i++) {
242
+ const prefix = i === ctxFrame.line - 1 ? c.R + ' →' : ' ';
243
+ out += ` ${prefix} ${c.D}${String(i + 1).padStart(4)}|${c.r} ${lines[i]}\n`;
244
+ if (i === ctxFrame.line - 1 && ctxFrame.column > 0) {
245
+ const col = Math.max(0, ctxFrame.column);
246
+ const indent = ' '.repeat(String(i + 1).padStart(4).length) + '| ';
247
+ const caret = ' '.repeat(col) + c.R + '^' + c.r;
248
+ out += ` ${c.R} →${c.r} ${indent}${caret}\n`;
242
249
  }
243
- out += ` ${c.D} ${line}${c.r}\n`;
244
250
  }
245
251
  }
246
- } else if (err.stack) {
247
- err.stack.split('\n').slice(0, 5).forEach(l => { out += ` ${c.D} ${l.trim()}${c.r}\n`; });
252
+ }
253
+
254
+ // Print resolved stack (all frames)
255
+ if (frames.length > 0) {
256
+ out += ` ${c.D}Stack:${c.r}\n`;
257
+ for (const f of frames) {
258
+ if (f.orig?.source) {
259
+ const srcPath = f.orig.source.replace(/^\.\.\/\.\.\//, '');
260
+ out += ` ${c.D} at ${srcPath}:${f.orig.line}:${f.orig.column}${c.r}\n`;
261
+ } else {
262
+ out += ` ${c.D} ${f.raw}${c.r}\n`;
263
+ }
264
+ }
248
265
  }
249
266
  console.log(out);
250
267
  }
@@ -7,7 +7,7 @@
7
7
  "dev": "node .yeow/dev-server.js"
8
8
  },
9
9
  "dependencies": {
10
- "yeow-api": "^0.2.28",
10
+ "yeow-api": "^0.2.29",
11
11
  "yeow-utils": "^0.1.2"
12
12
  },
13
13
  "devDependencies": {