create-yeow 0.2.44 → 0.2.45
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
|
Binary file
|
|
@@ -48,7 +48,7 @@ function startWebSocket() {
|
|
|
48
48
|
if (msg.type === 'js-error') {
|
|
49
49
|
await printFormattedError(msg);
|
|
50
50
|
}
|
|
51
|
-
} catch (e) {
|
|
51
|
+
} catch (e) { warn('Error processing message: ' + (e?.message || e)); }
|
|
52
52
|
});
|
|
53
53
|
ws.on('close', () => info('Java runtime disconnected'));
|
|
54
54
|
});
|
|
@@ -198,42 +198,52 @@ async function getSourceMapConsumer() {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
async function printFormattedError(err) {
|
|
201
|
-
const c = { r: '\x1b[0m', R: '\x1b[31m', Y: '\x1b[33m', C: '\x1b[36m', B: '\x1b[1m', D: '\x1b[2m' };
|
|
201
|
+
const c = { r: '\x1b[0m', R: '\x1b[31m', Y: '\x1b[33m', C: '\x1b[36m', B: '\x1b[1m', D: '\x1b[2m', g: '\x1b[32m' };
|
|
202
202
|
let out = `\n${c.R}${c.B} JS Error [${err.plugin}]${c.r}\n`;
|
|
203
203
|
if (err.context) out += ` ${c.D}context: ${err.context}${c.r}\n`;
|
|
204
204
|
out += ` ${c.Y}${err.message}${c.r}\n`;
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
// Check if stack contains any main.js frames — if so, load source-map consumer
|
|
207
|
+
const hasMainJs = err.stack?.match(/main\.js:\d+:\d+/) || err.fileName === 'main.js';
|
|
208
|
+
let consumer = null;
|
|
209
|
+
if (hasMainJs) {
|
|
210
|
+
consumer = await getSourceMapConsumer();
|
|
211
|
+
}
|
|
212
|
+
if (hasMainJs && !consumer) {
|
|
213
|
+
const mapFile = resolve(ROOT, 'dist', '.yeow', 'main.js.map');
|
|
214
|
+
out += ` ${c.D}(source-map not found: ${existsSync(mapFile) ? 'exists but failed to parse' : 'missing at ' + mapFile})${c.r}\n`;
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
// Resolve all stack frames
|
|
214
218
|
const frames = [];
|
|
215
219
|
if (err.stack) {
|
|
216
|
-
for (const
|
|
217
|
-
const m =
|
|
218
|
-
if (m) {
|
|
220
|
+
for (const rawLine of err.stack.split('\n')) {
|
|
221
|
+
const m = rawLine.match(/at\s+(?:\S+\s+)?\(?main\.js:(\d+):(\d+)\)?/);
|
|
222
|
+
if (m && consumer) {
|
|
219
223
|
const orig = consumer.originalPositionFor({ line: parseInt(m[1]), column: parseInt(m[2]) });
|
|
220
|
-
|
|
224
|
+
if (!orig?.source) {
|
|
225
|
+
// Try adjusted column
|
|
226
|
+
const orig2 = consumer.originalPositionFor({ line: parseInt(m[1]), column: parseInt(m[2]) - 1 });
|
|
227
|
+
if (orig2?.source) { orig.source = orig2.source; orig.line = orig2.line; orig.column = orig2.column; }
|
|
228
|
+
}
|
|
229
|
+
frames.push({ orig, raw: rawLine });
|
|
221
230
|
} else {
|
|
222
|
-
frames.push({ raw:
|
|
231
|
+
frames.push({ raw: rawLine });
|
|
223
232
|
}
|
|
224
233
|
}
|
|
225
234
|
}
|
|
226
235
|
|
|
227
236
|
// Find first frame from user's src/ directory (not node_modules)
|
|
228
237
|
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
238
|
|
|
233
239
|
// Show context for the chosen frame
|
|
234
|
-
if (ctxFrame?.source && ctxFrame.line) {
|
|
240
|
+
if (ctxFrame?.source && ctxFrame.line && consumer) {
|
|
235
241
|
const srcPath = ctxFrame.source.replace(/^\.\.\/\.\.\//, '');
|
|
236
|
-
|
|
242
|
+
// Preserve function name
|
|
243
|
+
const ctxRaw = frames.find(f => f.orig === ctxFrame)?.raw || '';
|
|
244
|
+
const fnM = ctxRaw.match(/at\s+(\S+)\s+\(/);
|
|
245
|
+
const fnS = fnM ? fnM[1] + ' ' : '';
|
|
246
|
+
out += ` ${c.C}at ${fnS}(${srcPath}:${ctxFrame.line}:${ctxFrame.column})${c.r}\n`;
|
|
237
247
|
const content = consumer.sourceContentFor(ctxFrame.source);
|
|
238
248
|
if (content) {
|
|
239
249
|
const lines = content.split('\n');
|
|
@@ -258,7 +268,11 @@ async function printFormattedError(err) {
|
|
|
258
268
|
for (const f of frames) {
|
|
259
269
|
if (f.orig?.source) {
|
|
260
270
|
const srcPath = f.orig.source.replace(/^\.\.\/\.\.\//, '');
|
|
261
|
-
|
|
271
|
+
const fnMatch = f.raw.match(/at\s+(\S+)\s+\(/);
|
|
272
|
+
const fn = fnMatch ? fnMatch[1] + ' ' : '';
|
|
273
|
+
const isUser = srcPath.startsWith('src/');
|
|
274
|
+
const style = isUser ? c.B + c.g : c.D;
|
|
275
|
+
out += ` ${style} at ${fn}(${srcPath}:${f.orig.line}:${f.orig.column})${c.r}\n`;
|
|
262
276
|
} else {
|
|
263
277
|
const internal = f.raw.includes('init.js') || f.raw.includes('unknown.js') ? ' (internal)' : '';
|
|
264
278
|
out += ` ${c.D} ${f.raw}${internal}${c.r}\n`;
|