create-yeow 0.2.42 → 0.2.44

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.44",
4
4
  "description": "Scaffold a Yeow plugin project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -157,6 +157,7 @@ function startHotReload() {
157
157
  codeFile: compiled.replace(/\\/g, '/'),
158
158
  assetsDir: existsSync(assetsDir) ? assetsDir.replace(/\\/g, '/') : null,
159
159
  });
160
+ _consumer = null; // invalidate stale source-map cache
160
161
  ok('Hot reload sent via WebSocket');
161
162
  }
162
163
  } catch (e) {
@@ -202,49 +203,67 @@ async function printFormattedError(err) {
202
203
  if (err.context) out += ` ${c.D}context: ${err.context}${c.r}\n`;
203
204
  out += ` ${c.Y}${err.message}${c.r}\n`;
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
+ const consumer = err.fileName === 'main.js' ? await getSourceMapConsumer() : null;
207
+ if (!consumer) {
208
+ if (err.stack) err.stack.split('\n').slice(0, 5).forEach(l => { out += ` ${c.D} ${l.trim()}${c.r}\n`; });
209
+ console.log(out);
210
+ return;
211
+ }
212
+
213
+ // Resolve all stack frames
214
+ const frames = [];
215
+ if (err.stack) {
216
+ for (const line of err.stack.split('\n')) {
217
+ const m = line.match(/at\s+(?:\S+\s+)?\(?\/main\.js:(\d+):(\d+)\)?/);
218
+ if (m) {
219
+ const orig = consumer.originalPositionFor({ line: parseInt(m[1]), column: parseInt(m[2]) });
220
+ frames.push({ orig, raw: line });
221
+ } else {
222
+ frames.push({ raw: line });
228
223
  }
229
224
  }
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
- }
225
+ }
226
+
227
+ // Find first frame from user's src/ directory (not node_modules)
228
+ let ctxFrame = frames.find(f => f.orig?.source?.match(/[\\/]src[\\/]/) && !f.orig.source.includes('node_modules'))?.orig || null;
229
+ if (!ctxFrame && err.lineNumber > 0) {
230
+ ctxFrame = consumer.originalPositionFor({ line: err.lineNumber, column: err.columnNumber || 0 });
231
+ }
232
+
233
+ // Show context for the chosen frame
234
+ if (ctxFrame?.source && ctxFrame.line) {
235
+ const srcPath = ctxFrame.source.replace(/^\.\.\/\.\.\//, '');
236
+ out += ` ${c.C}at ${srcPath}:${ctxFrame.line}:${ctxFrame.column}${c.r}\n`;
237
+ const content = consumer.sourceContentFor(ctxFrame.source);
238
+ if (content) {
239
+ const lines = content.split('\n');
240
+ const start = Math.max(0, ctxFrame.line - 3);
241
+ const end = Math.min(lines.length, ctxFrame.line + 2);
242
+ for (let i = start; i < end; i++) {
243
+ const prefix = i === ctxFrame.line - 1 ? c.R + ' →' : ' ';
244
+ out += ` ${prefix} ${c.D}${String(i + 1).padStart(4)}|${c.r} ${lines[i]}\n`;
245
+ if (i === ctxFrame.line - 1 && ctxFrame.column > 0) {
246
+ const col = Math.max(0, ctxFrame.column);
247
+ const indent = ' '.repeat(String(i + 1).padStart(4).length) + '| ';
248
+ const caret = ' '.repeat(col) + c.R + '^' + c.r;
249
+ out += ` ${c.R} →${c.r} ${indent}${caret}\n`;
242
250
  }
243
- out += ` ${c.D} ${line}${c.r}\n`;
244
251
  }
245
252
  }
246
- } else if (err.stack) {
247
- err.stack.split('\n').slice(0, 5).forEach(l => { out += ` ${c.D} ${l.trim()}${c.r}\n`; });
253
+ }
254
+
255
+ // Print resolved stack (all frames)
256
+ if (frames.length > 0) {
257
+ out += ` ${c.D}Stack:${c.r}\n`;
258
+ for (const f of frames) {
259
+ if (f.orig?.source) {
260
+ const srcPath = f.orig.source.replace(/^\.\.\/\.\.\//, '');
261
+ out += ` ${c.D} at ${srcPath}:${f.orig.line}:${f.orig.column}${c.r}\n`;
262
+ } else {
263
+ const internal = f.raw.includes('init.js') || f.raw.includes('unknown.js') ? ' (internal)' : '';
264
+ out += ` ${c.D} ${f.raw}${internal}${c.r}\n`;
265
+ }
266
+ }
248
267
  }
249
268
  console.log(out);
250
269
  }
@@ -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": {