nodexh 2.2.0 → 2.2.2
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/lib/main.js +14 -117
- package/lib/main.js.map +2 -2
- package/package.json +3 -5
- package/src/main.coffee +12 -108
package/lib/main.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
(function() {
|
|
2
2
|
'use strict';
|
|
3
|
-
var FS, GUY, PATH, _exit_handler, _get_context, alert, bold, cyan, debug, echo, exit_handler, fetch_mapped_location, get_context, get_error_callsites,
|
|
3
|
+
var FS, GUY, PATH, _exit_handler, _get_context, alert, blue, bold, cyan, debug, echo, exit_handler, fetch_mapped_location, get_context, get_error_callsites, gold, green, grey, inspect, load_source_map, log, red, reverse, rpr, show_error_with_source_context, steel, underline, white, write_to_stderr, yellow;
|
|
4
4
|
|
|
5
5
|
//###########################################################################################################
|
|
6
6
|
GUY = require('guy');
|
|
7
7
|
|
|
8
|
-
({alert, debug
|
|
8
|
+
({alert, debug} = GUY.trm.get_loggers('NODEXH'));
|
|
9
9
|
|
|
10
10
|
({rpr, inspect, echo, log} = GUY.trm);
|
|
11
11
|
|
|
12
|
-
types = new (require('intertype')).Intertype();
|
|
13
|
-
|
|
14
|
-
({isa, type_of} = types);
|
|
15
|
-
|
|
16
|
-
// stackman = ( require 'stackman' )()
|
|
17
12
|
get_error_callsites = require('error-callsites');
|
|
18
13
|
|
|
19
14
|
load_source_map = (require('util')).promisify(require('load-source-map'));
|
|
@@ -22,7 +17,7 @@
|
|
|
22
17
|
|
|
23
18
|
PATH = require('path');
|
|
24
19
|
|
|
25
|
-
({red, green, steel, grey, cyan, bold, gold, white, yellow, reverse, underline, bold} = GUY.trm);
|
|
20
|
+
({red, green, steel, grey, cyan, bold, gold, white, blue, yellow, reverse, underline, bold} = GUY.trm); // Слава Україні // Слава Україні
|
|
26
21
|
|
|
27
22
|
//-----------------------------------------------------------------------------------------------------------
|
|
28
23
|
write_to_stderr = function(...P) {
|
|
@@ -40,8 +35,6 @@
|
|
|
40
35
|
});
|
|
41
36
|
} catch (error1) {
|
|
42
37
|
error = error1;
|
|
43
|
-
// warn '^7763-3^', "!!!!!!!!!!!!!!!!!", { path, }
|
|
44
|
-
// warn '^7763-3^', "!!!!!!!!!!!!!!!!!", error.message
|
|
45
38
|
return {path, linenr, colnr};
|
|
46
39
|
}
|
|
47
40
|
//.........................................................................................................
|
|
@@ -72,7 +65,6 @@
|
|
|
72
65
|
};
|
|
73
66
|
|
|
74
67
|
//-----------------------------------------------------------------------------------------------------------
|
|
75
|
-
// return [ ( red "!!! #{rpr error.message} !!!" ), ]
|
|
76
68
|
_get_context = function(path, linenr, colnr, width) {
|
|
77
69
|
/* TAINT perform line length adjustment, hiliting in dedicated method */
|
|
78
70
|
var R, c0, c1, coldelta, delta, effect, first_idx, hilite, i, idx, last_idx, len, line, lines, ref, this_linenr, this_linenr_txt, width2;
|
|
@@ -107,18 +99,13 @@
|
|
|
107
99
|
}
|
|
108
100
|
R.push(`${grey(this_linenr_txt)}${cyan(line)}`);
|
|
109
101
|
}
|
|
110
|
-
// R = R.join '\n'
|
|
111
102
|
return R;
|
|
112
103
|
};
|
|
113
104
|
|
|
114
105
|
//-----------------------------------------------------------------------------------------------------------
|
|
115
106
|
show_error_with_source_context = async function(error, headline) {
|
|
116
107
|
/* TAINT use proper methods to format with multiple colors */
|
|
117
|
-
var arrowhead, arrowshaft, callsite, callsites, colnr, context_line, fname, fname_txt, i, j, len, len1, linenr, path, ref, ref1, ref2, relpath, width, width1;
|
|
118
|
-
/* From https://github.com/watson/stackman#gotchas: "This module works because V8 (the JavaScript engine
|
|
119
|
-
behind Node.js) allows us to hook into the stack trace generator function before that stack trace is
|
|
120
|
-
generated. It's triggered by accessing the .stack property on the Error object, so please don't do
|
|
121
|
-
that before parsing the error to stackman, else this will not work!" */
|
|
108
|
+
var arrowhead, arrowshaft, callsite, callsites, colnr, context_line, fname, fname_txt, i, j, len, len1, linenr, path, path_color, ref, ref1, ref2, relpath, width, width1;
|
|
122
109
|
alert('^77765-1^', reverse(bold(headline)));
|
|
123
110
|
arrowhead = white('▲');
|
|
124
111
|
arrowshaft = white('│');
|
|
@@ -150,17 +137,21 @@
|
|
|
150
137
|
continue;
|
|
151
138
|
}
|
|
152
139
|
//.......................................................................................................
|
|
153
|
-
|
|
154
|
-
|
|
140
|
+
if (/\/node_modules\//.test(path)) {
|
|
141
|
+
path_color = yellow;
|
|
142
|
+
} else {
|
|
143
|
+
path_color = gold;
|
|
144
|
+
}
|
|
145
|
+
//.......................................................................................................
|
|
155
146
|
fname = (ref = (ref1 = callsite.getFunctionName()) != null ? ref1 : callsite.getMethodName()) != null ? ref : null;
|
|
156
147
|
({path, linenr, colnr} = (await fetch_mapped_location(path, linenr, colnr)));
|
|
157
148
|
relpath = PATH.relative(process.cwd(), path);
|
|
158
149
|
if (fname != null) {
|
|
159
150
|
fname_txt = steel(fname);
|
|
160
151
|
width1 = width + (fname_txt.length - fname.length);
|
|
161
|
-
write_to_stderr(arrowhead,
|
|
152
|
+
write_to_stderr(arrowhead, path_color(`${relpath} @ ${linenr},${colnr}: ${fname_txt}() \x1b[38;05;234m`.padEnd(width1, '—')));
|
|
162
153
|
} else {
|
|
163
|
-
write_to_stderr(arrowhead,
|
|
154
|
+
write_to_stderr(arrowhead, path_color(`${relpath} @ ${linenr},${colnr}: \x1b[38;05;234m`.padEnd(width, '—')));
|
|
164
155
|
}
|
|
165
156
|
ref2 = (await get_context(path, linenr, colnr, width));
|
|
166
157
|
for (j = 0, len1 = ref2.length; j < len1; j++) {
|
|
@@ -169,26 +160,13 @@
|
|
|
169
160
|
}
|
|
170
161
|
}
|
|
171
162
|
alert('^77765-2^', reverse(bold(headline)));
|
|
172
|
-
// urge "^94843^ error.stack:", rpr error.stack
|
|
173
|
-
// urge "^94843^ error.message:", rpr error.message
|
|
174
|
-
// urge "^94843^ error.code:", rpr error.code
|
|
175
|
-
// urge "^94843^ error.name:", rpr error.name
|
|
176
|
-
// urge "^94843^ error.type:", rpr error.type
|
|
177
|
-
// urge "^94843^ error.toString():", rpr error.toString()
|
|
178
|
-
// urge "^94843^ error:", rpr error
|
|
179
|
-
// CATALOGUING = require '../../multimix/lib/cataloguing'
|
|
180
|
-
// urge "^94843^", ( CATALOGUING.all_keys_of error )
|
|
181
163
|
return null;
|
|
182
164
|
};
|
|
183
165
|
|
|
184
166
|
//-----------------------------------------------------------------------------------------------------------
|
|
185
167
|
_exit_handler = async function(error, origin) {
|
|
186
|
-
var message, ref, ref1, ref2, type;
|
|
187
168
|
/* TAINT origin never used */
|
|
188
|
-
|
|
189
|
-
// debug '^4488^', error
|
|
190
|
-
// debug '^4488^', await origin
|
|
191
|
-
// return null
|
|
169
|
+
var message, ref, ref1, ref2, type;
|
|
192
170
|
type = (ref = (ref1 = error.code) != null ? ref1 : error.name) != null ? ref : 'EXCEPTION';
|
|
193
171
|
message = ` ${type}: ` + ((ref2 = error != null ? error.message : void 0) != null ? ref2 : "an unrecoverable condition occurred");
|
|
194
172
|
await show_error_with_source_context(error, message);
|
|
@@ -204,61 +182,6 @@
|
|
|
204
182
|
return null;
|
|
205
183
|
};
|
|
206
184
|
|
|
207
|
-
//###########################################################################################################
|
|
208
|
-
//###########################################################################################################
|
|
209
|
-
//###########################################################################################################
|
|
210
|
-
get_stacktracey = function(error) {
|
|
211
|
-
var R, StackTracey, d, i, idx, ref, s, stack;
|
|
212
|
-
StackTracey = require('stacktracey');
|
|
213
|
-
stack = (new StackTracey(error)).withSources();
|
|
214
|
-
// stack = stack.clean()
|
|
215
|
-
R = [];
|
|
216
|
-
for (idx = i = ref = stack.items.length - 1; i >= 0; idx = i += -1) {
|
|
217
|
-
d = stack.items[idx];
|
|
218
|
-
// debug '^2798^', ( k for k of d )
|
|
219
|
-
s = {
|
|
220
|
-
// target_path: d.file
|
|
221
|
-
relpath: d.fileRelative, // fileShort
|
|
222
|
-
native: d.native,
|
|
223
|
-
// is_nodejs: d.native
|
|
224
|
-
is_other: d.thirdParty,
|
|
225
|
-
line: d.line,
|
|
226
|
-
column: d.column,
|
|
227
|
-
source: d.sourceLine,
|
|
228
|
-
error: d.error
|
|
229
|
-
};
|
|
230
|
-
// for k in [ 'sourceLine', 'native', 'file', 'line', 'column', 'calleeShort', 'fileRelative', 'fileShort', 'fileName', 'thirdParty', 'name',]
|
|
231
|
-
// debug k, rpr d[ k ]
|
|
232
|
-
R.push(s);
|
|
233
|
-
}
|
|
234
|
-
// info '\n' + stack.asTable()
|
|
235
|
-
return R;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
show_stacktracey = function(error) {
|
|
239
|
-
var d, i, len, ref, ref1;
|
|
240
|
-
ref = get_stacktracey(error);
|
|
241
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
|
242
|
-
d = ref[i];
|
|
243
|
-
echo(steel('^44872^ ' + `${d.relpath} @ ${d.line}:${d.column}`));
|
|
244
|
-
/* NOTE errors:
|
|
245
|
-
ENOENT: no such file or directory
|
|
246
|
-
EISDIR: illegal operation on a directory, read
|
|
247
|
-
'Cannot read property 'originalPositionFor' of undefined'
|
|
248
|
-
*/
|
|
249
|
-
if (d.error != null) {
|
|
250
|
-
echo(red('^44873^ ' + ((ref1 = d.error.message) != null ? ref1 : "an error occurred")));
|
|
251
|
-
} else {
|
|
252
|
-
echo(yellow('^44874^ ' + `${rpr(d.source.slice(0, 101))}`));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return null;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
//###########################################################################################################
|
|
259
|
-
//###########################################################################################################
|
|
260
|
-
//###########################################################################################################
|
|
261
|
-
|
|
262
185
|
//###########################################################################################################
|
|
263
186
|
if (global[Symbol.for('cnd-exception-handler')] == null) {
|
|
264
187
|
null;
|
|
@@ -267,33 +190,7 @@
|
|
|
267
190
|
process.once('unhandledRejection', exit_handler);
|
|
268
191
|
}
|
|
269
192
|
|
|
270
|
-
|
|
271
|
-
// process.stderr.on 'data', ( data ) => debug "^6863-1^ (stderr.on 'data'):", rpr data
|
|
272
|
-
// process.stdout.on 'data', ( data ) => debug "^6863-2^ (stdout.on 'data'):", rpr data
|
|
273
|
-
// process.stderr.on 'end', => debug "^6863-1^ (stderr.on 'end')"
|
|
274
|
-
// process.stdout.on 'end', => debug "^6863-2^ (stdout.on 'end')"
|
|
275
|
-
// debug '^6456^'
|
|
276
|
-
// echo "^4564^ echo to stdout"
|
|
277
|
-
// warn "^4564^ warn to stderr"
|
|
278
|
-
// process.stderr.write "this goes to stderr\n"
|
|
279
|
-
// process.stdout.write "this goes to stdout\n"
|
|
280
|
-
// process.on 'message', ( message ) -> debug "^6863-3^' (process.on 'message'):", rpr message
|
|
281
|
-
// process.on 'warning', ( warning ) -> debug "^6863-3^' (process.on 'warning'):", rpr warning
|
|
282
|
-
/*
|
|
283
|
-
callsite.getThis() - returns the value of this
|
|
284
|
-
callsite.getTypeName() - returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property.
|
|
285
|
-
callsite.getFunction() - returns the current function
|
|
286
|
-
callsite.getFunctionName() - returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
|
|
287
|
-
callsite.getMethodName() - returns the name of the property of this or one of its prototypes that holds the current function
|
|
288
|
-
callsite.getFileName() - if this function was defined in a script returns the name of the script
|
|
289
|
-
callsite.getLineNumber() - if this function was defined in a script returns the current line number
|
|
290
|
-
callsite.getColumnNumber() - if this function was defined in a script returns the current column number
|
|
291
|
-
callsite.getEvalOrigin() - if this function was created using a call to eval returns a CallSite object representing the location where eval was called
|
|
292
|
-
callsite.isToplevel() - is this a toplevel invocation, that is, is this the global object?
|
|
293
|
-
callsite.isEval() - does this call take place in code defined by a call to eval?
|
|
294
|
-
callsite.isNative() - is this call in native V8 code?
|
|
295
|
-
callsite.isConstructor() - is this a constructor c
|
|
296
|
-
*/
|
|
193
|
+
//###########################################################################################################
|
|
297
194
|
module.exports = {exit_handler, _exit_handler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AO,CAAC,IAAR,CAAa,GAAb;IAAH,CAAF,CAAb;AACA,WAAO;EAHM,EA7If;;;EAqJA,IAAO,mDAAP;IACE;IACA,MAAM,CAAE,MAAM,CAAC,GAAP,CAAW,uBAAX,CAAF,CAAN,GAA+C;IAC/C,OAAO,CAAC,IAAR,CAAa,mBAAb,EAAmC,YAAnC;IACA,OAAO,CAAC,IAAR,CAAa,oBAAb,EAAmC,YAAnC,EAJF;GArJA;;;EA6JA,MAAM,CAAC,OAAP,GAAiB,CAAE,YAAF,EAAgB,aAAhB;AA7JjB",
|
|
10
10
|
"sourcesContent": [
|
|
11
|
-
"\n'use strict'\n\n\n############################################################################################################\nGUY = require 'guy'\n{ alert\n debug\n help\n info\n plain\n praise\n urge\n warn\n whisper } = GUY.trm.get_loggers 'NODEXH'\n{ rpr\n inspect\n echo\n log } = GUY.trm\ntypes = new ( require 'intertype' ).Intertype()\n{ isa\n type_of } = types\n# stackman = ( require 'stackman' )()\nget_error_callsites = require 'error-callsites'\nload_source_map = ( require 'util' ).promisify ( require 'load-source-map' )\nFS = require 'fs'\nPATH = require 'path'\n{ red\n green\n steel\n grey\n cyan\n bold\n gold\n white\n yellow\n reverse\n underline\n bold } = GUY.trm\n\n#-----------------------------------------------------------------------------------------------------------\nwrite_to_stderr = ( P... ) -> process.stderr.write ' ' + ( GUY.trm.pen P... ) + '\\n'\n\n#-----------------------------------------------------------------------------------------------------------\nfetch_mapped_location = ( path, linenr, colnr ) ->\n try\n sourcemap = await load_source_map path\n smp = sourcemap.originalPositionFor { line: linenr, column: colnr, }\n catch error\n # warn '^7763-3^', \"!!!!!!!!!!!!!!!!!\", { path, }\n # warn '^7763-3^', \"!!!!!!!!!!!!!!!!!\", error.message\n return { path, linenr, colnr, }\n #.........................................................................................................\n if ( smp? ) and ( smp.source? ) and ( smp.source isnt '' ) and ( smp.line? ) and ( smp.column? )\n mapped_path = PATH.join ( PATH.dirname path ), smp.source\n return { path: mapped_path, linenr: smp.line, colnr: smp.column, }\n #.........................................................................................................\n return { path, linenr, colnr, }\n\n#-----------------------------------------------------------------------------------------------------------\nget_context = ( path, linenr, colnr, width ) ->\n try return ( _get_context path, linenr, colnr, width ) catch error\n throw error unless error.code is 'ENOENT'\n # return [ ( red \"!!! #{rpr error.message} !!!\" ), ]\n return []\n\n#-----------------------------------------------------------------------------------------------------------\n_get_context = ( path, linenr, colnr, width ) ->\n lines = ( FS.readFileSync path, { encoding: 'utf-8' } ).split '\\n'\n delta = 1\n coldelta = 5\n effect = reverse\n first_idx = Math.max 0, linenr - 1 - delta\n last_idx = Math.min lines.length - 1, linenr - 1 + delta\n R = []\n for line, idx in lines[ first_idx .. last_idx ]\n this_linenr = first_idx + idx + 1\n this_linenr_txt = ( this_linenr.toString().padStart 4 ) + '│ '\n if this_linenr isnt linenr\n ### TAINT should adjust overlong context lines as well ###\n R.push \"#{grey this_linenr_txt}#{grey line}\"\n continue\n ### TAINT perform line length adjustment, hiliting in dedicated method ###\n c0 = colnr - 1\n c1 = colnr + coldelta\n hilite = effect line[ c0 ... c1 ]\n line = line[ ... c0 ] + hilite + line[ c1 .. ]\n if c1 > width\n width2 = Math.floor width / 2\n line = '... ' + line[ c1 - width2 .. c1 + hilite.length - ( c1 - c0 ) + width2 ] + ' ...'\n else\n line = line[ .. width ]\n R.push \"#{grey this_linenr_txt}#{cyan line}\"\n # R = R.join '\\n'\n return R\n\n#-----------------------------------------------------------------------------------------------------------\nshow_error_with_source_context = ( error, headline ) ->\n ### From https://github.com/watson/stackman#gotchas: \"This module works because V8 (the JavaScript engine\n behind Node.js) allows us to hook into the stack trace generator function before that stack trace is\n generated. It's triggered by accessing the .stack property on the Error object, so please don't do\n that before parsing the error to stackman, else this will not work!\" ###\n alert '^77765-1^', reverse bold headline\n arrowhead = white '▲'\n arrowshaft = white '│'\n width = process.stdout.columns\n callsites = get_error_callsites error\n #.........................................................................................................\n if ( not callsites? ) or ( callsites.length is 0 )\n write_to_stderr red reverse \"^455756^ error has no associated callsites:\"\n write_to_stderr red reverse rpr error\n return null\n #.........................................................................................................\n callsites.reverse()\n #.........................................................................................................\n for callsite in callsites\n path = callsite.getFileName()\n #.......................................................................................................\n unless path?\n write_to_stderr grey '—'.repeat 108\n continue\n #.......................................................................................................\n linenr = callsite.getLineNumber()\n colnr = callsite.getColumnNumber()\n #.......................................................................................................\n if ( path.startsWith 'node:internal/' ) or ( path.startsWith 'internal/' )\n write_to_stderr arrowhead, grey \"#{path} @ #{linenr},#{colnr}\"\n continue\n #.......................................................................................................\n # write_to_stderr()\n # write_to_stderr steel bold reverse ( \"#{relpath} ##{linenr}:\" ).padEnd 108\n fname = callsite.getFunctionName() ? callsite.getMethodName() ? null\n { path\n linenr\n colnr } = await fetch_mapped_location path, linenr, colnr\n relpath = PATH.relative process.cwd(), path\n if fname?\n ### TAINT use proper methods to format with multiple colors ###\n fname_txt = steel fname\n width1 = width + ( fname_txt.length - fname.length )\n write_to_stderr arrowhead, gold ( \"#{relpath} @ #{linenr},#{colnr}: #{fname_txt}() \\x1b[38;05;234m\".padEnd width1, '—' )\n else\n write_to_stderr arrowhead, gold ( \"#{relpath} @ #{linenr},#{colnr}: \\x1b[38;05;234m\".padEnd width, '—' )\n for context_line in await get_context path, linenr, colnr, width\n write_to_stderr arrowshaft, context_line\n alert '^77765-2^', reverse bold headline\n # urge \"^94843^ error.stack:\", rpr error.stack\n # urge \"^94843^ error.message:\", rpr error.message\n # urge \"^94843^ error.code:\", rpr error.code\n # urge \"^94843^ error.name:\", rpr error.name\n # urge \"^94843^ error.type:\", rpr error.type\n # urge \"^94843^ error.toString():\", rpr error.toString()\n # urge \"^94843^ error:\", rpr error\n # CATALOGUING = require '../../multimix/lib/cataloguing'\n # urge \"^94843^\", ( CATALOGUING.all_keys_of error )\n return null\n\n#-----------------------------------------------------------------------------------------------------------\n_exit_handler = ( error, origin ) ->\n ### TAINT origin never used ###\n # show_stacktracey error\n # debug '^4488^', error\n # debug '^4488^', await origin\n # return null\n type = error.code ? error.name ? 'EXCEPTION'\n message = \" #{type}: \" + ( error?.message ? \"an unrecoverable condition occurred\" )\n await show_error_with_source_context error, message\n return null\n\n#-----------------------------------------------------------------------------------------------------------\nexit_handler = ( error, origin ) ->\n await _exit_handler error, origin\n setImmediate ( -> process.exit 111 )\n return null\n\n############################################################################################################\n############################################################################################################\n############################################################################################################\n\nget_stacktracey = ( error ) ->\n StackTracey = require 'stacktracey'\n stack = ( new StackTracey error ).withSources()\n # stack = stack.clean()\n R = []\n for idx in [ stack.items.length - 1 .. 0 ] by -1\n d = stack.items[ idx ]\n # debug '^2798^', ( k for k of d )\n s =\n # target_path: d.file\n relpath: d.fileRelative # fileShort\n native: d.native\n # is_nodejs: d.native\n is_other: d.thirdParty\n line: d.line\n column: d.column\n source: d.sourceLine\n error: d.error\n # for k in [ 'sourceLine', 'native', 'file', 'line', 'column', 'calleeShort', 'fileRelative', 'fileShort', 'fileName', 'thirdParty', 'name',]\n # debug k, rpr d[ k ]\n R.push s\n # info '\\n' + stack.asTable()\n return R\n\nshow_stacktracey = ( error ) ->\n for d in get_stacktracey error\n echo steel '^44872^ ' + \"#{d.relpath} @ #{d.line}:#{d.column}\"\n ### NOTE errors:\n ENOENT: no such file or directory\n EISDIR: illegal operation on a directory, read\n 'Cannot read property 'originalPositionFor' of undefined'\n ###\n if d.error? then echo red '^44873^ ' + ( d.error.message ? \"an error occurred\" )\n else echo yellow '^44874^ ' + \"#{rpr d.source[ .. 100 ]}\"\n return null\n\n############################################################################################################\n############################################################################################################\n############################################################################################################\n\n\n############################################################################################################\nunless global[ Symbol.for 'cnd-exception-handler' ]?\n null\n global[ Symbol.for 'cnd-exception-handler' ] = true\n process.once 'uncaughtException', exit_handler\n process.once 'unhandledRejection', exit_handler\n\n # do =>\n # process.stderr.on 'data', ( data ) => debug \"^6863-1^ (stderr.on 'data'):\", rpr data\n # process.stdout.on 'data', ( data ) => debug \"^6863-2^ (stdout.on 'data'):\", rpr data\n # process.stderr.on 'end', => debug \"^6863-1^ (stderr.on 'end')\"\n # process.stdout.on 'end', => debug \"^6863-2^ (stdout.on 'end')\"\n # debug '^6456^'\n # echo \"^4564^ echo to stdout\"\n # warn \"^4564^ warn to stderr\"\n # process.stderr.write \"this goes to stderr\\n\"\n # process.stdout.write \"this goes to stdout\\n\"\n # process.on 'message', ( message ) -> debug \"^6863-3^' (process.on 'message'):\", rpr message\n # process.on 'warning', ( warning ) -> debug \"^6863-3^' (process.on 'warning'):\", rpr warning\n###\ncallsite.getThis() - returns the value of this\ncallsite.getTypeName() - returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property.\ncallsite.getFunction() - returns the current function\ncallsite.getFunctionName() - returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context.\ncallsite.getMethodName() - returns the name of the property of this or one of its prototypes that holds the current function\ncallsite.getFileName() - if this function was defined in a script returns the name of the script\ncallsite.getLineNumber() - if this function was defined in a script returns the current line number\ncallsite.getColumnNumber() - if this function was defined in a script returns the current column number\ncallsite.getEvalOrigin() - if this function was created using a call to eval returns a CallSite object representing the location where eval was called\ncallsite.isToplevel() - is this a toplevel invocation, that is, is this the global object?\ncallsite.isEval() - does this call take place in code defined by a call to eval?\ncallsite.isNative() - is this call in native V8 code?\ncallsite.isConstructor() - is this a constructor c\n###\n\nmodule.exports = { exit_handler, _exit_handler, }\n"
|
|
11
|
+
"\n'use strict'\n\n\n############################################################################################################\nGUY = require 'guy'\n{ alert\n debug } = GUY.trm.get_loggers 'NODEXH'\n{ rpr\n inspect\n echo\n log } = GUY.trm\nget_error_callsites = require 'error-callsites'\nload_source_map = ( require 'util' ).promisify ( require 'load-source-map' )\nFS = require 'fs'\nPATH = require 'path'\n{ red\n green\n steel\n grey\n cyan\n bold\n gold\n white\n blue # Слава Україні\n yellow # Слава Україні\n reverse\n underline\n bold } = GUY.trm\n\n#-----------------------------------------------------------------------------------------------------------\nwrite_to_stderr = ( P... ) -> process.stderr.write ' ' + ( GUY.trm.pen P... ) + '\\n'\n\n#-----------------------------------------------------------------------------------------------------------\nfetch_mapped_location = ( path, linenr, colnr ) ->\n try\n sourcemap = await load_source_map path\n smp = sourcemap.originalPositionFor { line: linenr, column: colnr, }\n catch error\n return { path, linenr, colnr, }\n #.........................................................................................................\n if ( smp? ) and ( smp.source? ) and ( smp.source isnt '' ) and ( smp.line? ) and ( smp.column? )\n mapped_path = PATH.join ( PATH.dirname path ), smp.source\n return { path: mapped_path, linenr: smp.line, colnr: smp.column, }\n #.........................................................................................................\n return { path, linenr, colnr, }\n\n#-----------------------------------------------------------------------------------------------------------\nget_context = ( path, linenr, colnr, width ) ->\n try return ( _get_context path, linenr, colnr, width ) catch error\n throw error unless error.code is 'ENOENT'\n return []\n\n#-----------------------------------------------------------------------------------------------------------\n_get_context = ( path, linenr, colnr, width ) ->\n lines = ( FS.readFileSync path, { encoding: 'utf-8' } ).split '\\n'\n delta = 1\n coldelta = 5\n effect = reverse\n first_idx = Math.max 0, linenr - 1 - delta\n last_idx = Math.min lines.length - 1, linenr - 1 + delta\n R = []\n for line, idx in lines[ first_idx .. last_idx ]\n this_linenr = first_idx + idx + 1\n this_linenr_txt = ( this_linenr.toString().padStart 4 ) + '│ '\n if this_linenr isnt linenr\n ### TAINT should adjust overlong context lines as well ###\n R.push \"#{grey this_linenr_txt}#{grey line}\"\n continue\n ### TAINT perform line length adjustment, hiliting in dedicated method ###\n c0 = colnr - 1\n c1 = colnr + coldelta\n hilite = effect line[ c0 ... c1 ]\n line = line[ ... c0 ] + hilite + line[ c1 .. ]\n if c1 > width\n width2 = Math.floor width / 2\n line = '... ' + line[ c1 - width2 .. c1 + hilite.length - ( c1 - c0 ) + width2 ] + ' ...'\n else\n line = line[ .. width ]\n R.push \"#{grey this_linenr_txt}#{cyan line}\"\n return R\n\n#-----------------------------------------------------------------------------------------------------------\nshow_error_with_source_context = ( error, headline ) ->\n alert '^77765-1^', reverse bold headline\n arrowhead = white '▲'\n arrowshaft = white '│'\n width = process.stdout.columns\n callsites = get_error_callsites error\n #.........................................................................................................\n if ( not callsites? ) or ( callsites.length is 0 )\n write_to_stderr red reverse \"^455756^ error has no associated callsites:\"\n write_to_stderr red reverse rpr error\n return null\n #.........................................................................................................\n callsites.reverse()\n #.........................................................................................................\n for callsite in callsites\n path = callsite.getFileName()\n #.......................................................................................................\n unless path?\n write_to_stderr grey '—'.repeat 108\n continue\n #.......................................................................................................\n linenr = callsite.getLineNumber()\n colnr = callsite.getColumnNumber()\n #.......................................................................................................\n if ( path.startsWith 'node:internal/' ) or ( path.startsWith 'internal/' )\n write_to_stderr arrowhead, grey \"#{path} @ #{linenr},#{colnr}\"\n continue\n #.......................................................................................................\n if ( /\\/node_modules\\//.test path )\n path_color = yellow\n else\n path_color = gold\n #.......................................................................................................\n fname = callsite.getFunctionName() ? callsite.getMethodName() ? null\n { path\n linenr\n colnr } = await fetch_mapped_location path, linenr, colnr\n relpath = PATH.relative process.cwd(), path\n if fname?\n ### TAINT use proper methods to format with multiple colors ###\n fname_txt = steel fname\n width1 = width + ( fname_txt.length - fname.length )\n write_to_stderr arrowhead, path_color ( \"#{relpath} @ #{linenr},#{colnr}: #{fname_txt}() \\x1b[38;05;234m\".padEnd width1, '—' )\n else\n write_to_stderr arrowhead, path_color ( \"#{relpath} @ #{linenr},#{colnr}: \\x1b[38;05;234m\".padEnd width, '—' )\n for context_line in await get_context path, linenr, colnr, width\n write_to_stderr arrowshaft, context_line\n alert '^77765-2^', reverse bold headline\n return null\n\n#-----------------------------------------------------------------------------------------------------------\n_exit_handler = ( error, origin ) ->\n ### TAINT origin never used ###\n type = error.code ? error.name ? 'EXCEPTION'\n message = \" #{type}: \" + ( error?.message ? \"an unrecoverable condition occurred\" )\n await show_error_with_source_context error, message\n return null\n\n#-----------------------------------------------------------------------------------------------------------\nexit_handler = ( error, origin ) ->\n await _exit_handler error, origin\n setImmediate ( -> process.exit 111 )\n return null\n\n\n\n############################################################################################################\nunless global[ Symbol.for 'cnd-exception-handler' ]?\n null\n global[ Symbol.for 'cnd-exception-handler' ] = true\n process.once 'uncaughtException', exit_handler\n process.once 'unhandledRejection', exit_handler\n\n\n############################################################################################################\nmodule.exports = { exit_handler, _exit_handler, }\n\n"
|
|
12
12
|
]
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodexh",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "a wrapper around the `node` executable for better stacktraces with sourcemaps, sourcecode excerpts",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
"homepage": "https://github.com/loveencounterflow/nodexh",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"error-callsites": "^2.0.3",
|
|
27
|
-
"guy": "^
|
|
28
|
-
"
|
|
29
|
-
"load-source-map": "3.0.1",
|
|
30
|
-
"stacktracey": "^2.0.14"
|
|
27
|
+
"guy": "^13.7.1",
|
|
28
|
+
"load-source-map": "3.0.1"
|
|
31
29
|
},
|
|
32
30
|
"scripts": {
|
|
33
31
|
"build": "coffee --map -o lib -c src"
|
package/src/main.coffee
CHANGED
|
@@ -5,22 +5,11 @@
|
|
|
5
5
|
############################################################################################################
|
|
6
6
|
GUY = require 'guy'
|
|
7
7
|
{ alert
|
|
8
|
-
debug
|
|
9
|
-
help
|
|
10
|
-
info
|
|
11
|
-
plain
|
|
12
|
-
praise
|
|
13
|
-
urge
|
|
14
|
-
warn
|
|
15
|
-
whisper } = GUY.trm.get_loggers 'NODEXH'
|
|
8
|
+
debug } = GUY.trm.get_loggers 'NODEXH'
|
|
16
9
|
{ rpr
|
|
17
10
|
inspect
|
|
18
11
|
echo
|
|
19
12
|
log } = GUY.trm
|
|
20
|
-
types = new ( require 'intertype' ).Intertype()
|
|
21
|
-
{ isa
|
|
22
|
-
type_of } = types
|
|
23
|
-
# stackman = ( require 'stackman' )()
|
|
24
13
|
get_error_callsites = require 'error-callsites'
|
|
25
14
|
load_source_map = ( require 'util' ).promisify ( require 'load-source-map' )
|
|
26
15
|
FS = require 'fs'
|
|
@@ -33,7 +22,8 @@ PATH = require 'path'
|
|
|
33
22
|
bold
|
|
34
23
|
gold
|
|
35
24
|
white
|
|
36
|
-
|
|
25
|
+
blue # Слава Україні
|
|
26
|
+
yellow # Слава Україні
|
|
37
27
|
reverse
|
|
38
28
|
underline
|
|
39
29
|
bold } = GUY.trm
|
|
@@ -47,8 +37,6 @@ fetch_mapped_location = ( path, linenr, colnr ) ->
|
|
|
47
37
|
sourcemap = await load_source_map path
|
|
48
38
|
smp = sourcemap.originalPositionFor { line: linenr, column: colnr, }
|
|
49
39
|
catch error
|
|
50
|
-
# warn '^7763-3^', "!!!!!!!!!!!!!!!!!", { path, }
|
|
51
|
-
# warn '^7763-3^', "!!!!!!!!!!!!!!!!!", error.message
|
|
52
40
|
return { path, linenr, colnr, }
|
|
53
41
|
#.........................................................................................................
|
|
54
42
|
if ( smp? ) and ( smp.source? ) and ( smp.source isnt '' ) and ( smp.line? ) and ( smp.column? )
|
|
@@ -61,7 +49,6 @@ fetch_mapped_location = ( path, linenr, colnr ) ->
|
|
|
61
49
|
get_context = ( path, linenr, colnr, width ) ->
|
|
62
50
|
try return ( _get_context path, linenr, colnr, width ) catch error
|
|
63
51
|
throw error unless error.code is 'ENOENT'
|
|
64
|
-
# return [ ( red "!!! #{rpr error.message} !!!" ), ]
|
|
65
52
|
return []
|
|
66
53
|
|
|
67
54
|
#-----------------------------------------------------------------------------------------------------------
|
|
@@ -91,15 +78,10 @@ _get_context = ( path, linenr, colnr, width ) ->
|
|
|
91
78
|
else
|
|
92
79
|
line = line[ .. width ]
|
|
93
80
|
R.push "#{grey this_linenr_txt}#{cyan line}"
|
|
94
|
-
# R = R.join '\n'
|
|
95
81
|
return R
|
|
96
82
|
|
|
97
83
|
#-----------------------------------------------------------------------------------------------------------
|
|
98
84
|
show_error_with_source_context = ( error, headline ) ->
|
|
99
|
-
### From https://github.com/watson/stackman#gotchas: "This module works because V8 (the JavaScript engine
|
|
100
|
-
behind Node.js) allows us to hook into the stack trace generator function before that stack trace is
|
|
101
|
-
generated. It's triggered by accessing the .stack property on the Error object, so please don't do
|
|
102
|
-
that before parsing the error to stackman, else this will not work!" ###
|
|
103
85
|
alert '^77765-1^', reverse bold headline
|
|
104
86
|
arrowhead = white '▲'
|
|
105
87
|
arrowshaft = white '│'
|
|
@@ -127,8 +109,11 @@ show_error_with_source_context = ( error, headline ) ->
|
|
|
127
109
|
write_to_stderr arrowhead, grey "#{path} @ #{linenr},#{colnr}"
|
|
128
110
|
continue
|
|
129
111
|
#.......................................................................................................
|
|
130
|
-
|
|
131
|
-
|
|
112
|
+
if ( /\/node_modules\//.test path )
|
|
113
|
+
path_color = yellow
|
|
114
|
+
else
|
|
115
|
+
path_color = gold
|
|
116
|
+
#.......................................................................................................
|
|
132
117
|
fname = callsite.getFunctionName() ? callsite.getMethodName() ? null
|
|
133
118
|
{ path
|
|
134
119
|
linenr
|
|
@@ -138,30 +123,17 @@ show_error_with_source_context = ( error, headline ) ->
|
|
|
138
123
|
### TAINT use proper methods to format with multiple colors ###
|
|
139
124
|
fname_txt = steel fname
|
|
140
125
|
width1 = width + ( fname_txt.length - fname.length )
|
|
141
|
-
write_to_stderr arrowhead,
|
|
126
|
+
write_to_stderr arrowhead, path_color ( "#{relpath} @ #{linenr},#{colnr}: #{fname_txt}() \x1b[38;05;234m".padEnd width1, '—' )
|
|
142
127
|
else
|
|
143
|
-
write_to_stderr arrowhead,
|
|
128
|
+
write_to_stderr arrowhead, path_color ( "#{relpath} @ #{linenr},#{colnr}: \x1b[38;05;234m".padEnd width, '—' )
|
|
144
129
|
for context_line in await get_context path, linenr, colnr, width
|
|
145
130
|
write_to_stderr arrowshaft, context_line
|
|
146
131
|
alert '^77765-2^', reverse bold headline
|
|
147
|
-
# urge "^94843^ error.stack:", rpr error.stack
|
|
148
|
-
# urge "^94843^ error.message:", rpr error.message
|
|
149
|
-
# urge "^94843^ error.code:", rpr error.code
|
|
150
|
-
# urge "^94843^ error.name:", rpr error.name
|
|
151
|
-
# urge "^94843^ error.type:", rpr error.type
|
|
152
|
-
# urge "^94843^ error.toString():", rpr error.toString()
|
|
153
|
-
# urge "^94843^ error:", rpr error
|
|
154
|
-
# CATALOGUING = require '../../multimix/lib/cataloguing'
|
|
155
|
-
# urge "^94843^", ( CATALOGUING.all_keys_of error )
|
|
156
132
|
return null
|
|
157
133
|
|
|
158
134
|
#-----------------------------------------------------------------------------------------------------------
|
|
159
135
|
_exit_handler = ( error, origin ) ->
|
|
160
136
|
### TAINT origin never used ###
|
|
161
|
-
# show_stacktracey error
|
|
162
|
-
# debug '^4488^', error
|
|
163
|
-
# debug '^4488^', await origin
|
|
164
|
-
# return null
|
|
165
137
|
type = error.code ? error.name ? 'EXCEPTION'
|
|
166
138
|
message = " #{type}: " + ( error?.message ? "an unrecoverable condition occurred" )
|
|
167
139
|
await show_error_with_source_context error, message
|
|
@@ -173,49 +145,6 @@ exit_handler = ( error, origin ) ->
|
|
|
173
145
|
setImmediate ( -> process.exit 111 )
|
|
174
146
|
return null
|
|
175
147
|
|
|
176
|
-
############################################################################################################
|
|
177
|
-
############################################################################################################
|
|
178
|
-
############################################################################################################
|
|
179
|
-
|
|
180
|
-
get_stacktracey = ( error ) ->
|
|
181
|
-
StackTracey = require 'stacktracey'
|
|
182
|
-
stack = ( new StackTracey error ).withSources()
|
|
183
|
-
# stack = stack.clean()
|
|
184
|
-
R = []
|
|
185
|
-
for idx in [ stack.items.length - 1 .. 0 ] by -1
|
|
186
|
-
d = stack.items[ idx ]
|
|
187
|
-
# debug '^2798^', ( k for k of d )
|
|
188
|
-
s =
|
|
189
|
-
# target_path: d.file
|
|
190
|
-
relpath: d.fileRelative # fileShort
|
|
191
|
-
native: d.native
|
|
192
|
-
# is_nodejs: d.native
|
|
193
|
-
is_other: d.thirdParty
|
|
194
|
-
line: d.line
|
|
195
|
-
column: d.column
|
|
196
|
-
source: d.sourceLine
|
|
197
|
-
error: d.error
|
|
198
|
-
# for k in [ 'sourceLine', 'native', 'file', 'line', 'column', 'calleeShort', 'fileRelative', 'fileShort', 'fileName', 'thirdParty', 'name',]
|
|
199
|
-
# debug k, rpr d[ k ]
|
|
200
|
-
R.push s
|
|
201
|
-
# info '\n' + stack.asTable()
|
|
202
|
-
return R
|
|
203
|
-
|
|
204
|
-
show_stacktracey = ( error ) ->
|
|
205
|
-
for d in get_stacktracey error
|
|
206
|
-
echo steel '^44872^ ' + "#{d.relpath} @ #{d.line}:#{d.column}"
|
|
207
|
-
### NOTE errors:
|
|
208
|
-
ENOENT: no such file or directory
|
|
209
|
-
EISDIR: illegal operation on a directory, read
|
|
210
|
-
'Cannot read property 'originalPositionFor' of undefined'
|
|
211
|
-
###
|
|
212
|
-
if d.error? then echo red '^44873^ ' + ( d.error.message ? "an error occurred" )
|
|
213
|
-
else echo yellow '^44874^ ' + "#{rpr d.source[ .. 100 ]}"
|
|
214
|
-
return null
|
|
215
|
-
|
|
216
|
-
############################################################################################################
|
|
217
|
-
############################################################################################################
|
|
218
|
-
############################################################################################################
|
|
219
148
|
|
|
220
149
|
|
|
221
150
|
############################################################################################################
|
|
@@ -225,32 +154,7 @@ unless global[ Symbol.for 'cnd-exception-handler' ]?
|
|
|
225
154
|
process.once 'uncaughtException', exit_handler
|
|
226
155
|
process.once 'unhandledRejection', exit_handler
|
|
227
156
|
|
|
228
|
-
# do =>
|
|
229
|
-
# process.stderr.on 'data', ( data ) => debug "^6863-1^ (stderr.on 'data'):", rpr data
|
|
230
|
-
# process.stdout.on 'data', ( data ) => debug "^6863-2^ (stdout.on 'data'):", rpr data
|
|
231
|
-
# process.stderr.on 'end', => debug "^6863-1^ (stderr.on 'end')"
|
|
232
|
-
# process.stdout.on 'end', => debug "^6863-2^ (stdout.on 'end')"
|
|
233
|
-
# debug '^6456^'
|
|
234
|
-
# echo "^4564^ echo to stdout"
|
|
235
|
-
# warn "^4564^ warn to stderr"
|
|
236
|
-
# process.stderr.write "this goes to stderr\n"
|
|
237
|
-
# process.stdout.write "this goes to stdout\n"
|
|
238
|
-
# process.on 'message', ( message ) -> debug "^6863-3^' (process.on 'message'):", rpr message
|
|
239
|
-
# process.on 'warning', ( warning ) -> debug "^6863-3^' (process.on 'warning'):", rpr warning
|
|
240
|
-
###
|
|
241
|
-
callsite.getThis() - returns the value of this
|
|
242
|
-
callsite.getTypeName() - returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property.
|
|
243
|
-
callsite.getFunction() - returns the current function
|
|
244
|
-
callsite.getFunctionName() - returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
|
|
245
|
-
callsite.getMethodName() - returns the name of the property of this or one of its prototypes that holds the current function
|
|
246
|
-
callsite.getFileName() - if this function was defined in a script returns the name of the script
|
|
247
|
-
callsite.getLineNumber() - if this function was defined in a script returns the current line number
|
|
248
|
-
callsite.getColumnNumber() - if this function was defined in a script returns the current column number
|
|
249
|
-
callsite.getEvalOrigin() - if this function was created using a call to eval returns a CallSite object representing the location where eval was called
|
|
250
|
-
callsite.isToplevel() - is this a toplevel invocation, that is, is this the global object?
|
|
251
|
-
callsite.isEval() - does this call take place in code defined by a call to eval?
|
|
252
|
-
callsite.isNative() - is this call in native V8 code?
|
|
253
|
-
callsite.isConstructor() - is this a constructor c
|
|
254
|
-
###
|
|
255
157
|
|
|
158
|
+
############################################################################################################
|
|
256
159
|
module.exports = { exit_handler, _exit_handler, }
|
|
160
|
+
|