-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnode-source-map-support.node.txt
100 lines (85 loc) · 6.6 KB
/
node-source-map-support.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ NODE-SOURCE-MAP-SUPPORT ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> # - --enable-source-maps (prefer for Node >=12.12.0)
# - Node only
# - built-in
# - node-source-map-support (prefer for Node <12.12.0):
# - Node or Browser (Chrome only)
# - high-profile
# - uses Error.prepareStackTrace()
# - stacktrace.js (prefered for browser):
# - Browser only
# - high-profile
# - good cross-browser and old browser support
# - good try to find functionName
# - sourcemapped-stacktrace:
# - Browser only
# - quite similar to stacktrace.js's STACKTRACE-GPS
# - stackman:
# - has source map support but mostly meant for stack parsing
# - stack-source-map:
# - copy of node-source-map-support but with only Chrome-related code
# - not well maintained
#All based on mozilla source-map
VERSION ==> #0.5.21
#Node or browser (will only have an effect on Chrome)
GOAL ==> #Source map support in stack traces
┌──────────┐
│ CORE │
└──────────┘
install([OPTS]) #Make ERROR.stack use source maps:
# - location (filename|line|column) from source file instead of compiled one
# - using the compiled file's source map
#OPTS:
# - environment 'node', 'browser' or 'auto' (def)
require
('source-map-support/register') #Calls install()
BABEL-PLUGIN-SOURCE-MAP-SUPPORT ##Babel plugin which automatically adds require('source-map-support/register') on top of each file
==> ##Version 2.2.0
┌───────────────┐
│ LOW-LEVEL │
└───────────────┘
wrapCallSite(CALL)->CALL #Underlying logic to install()
#Added through Error.prepareStackTrace()
#Patches CALL so it uses source file filename|line|column instead of compiled one
mapSourcePosition(OBJ)->OBJ #Underlying logic to wrapCallSite()
#Transform OBJ: source URI|PATH, line|column NUM from compiled to source file's position.
#Do it by:
# - retrieving the source map (with retrieveSourceMap())
# - parsing it with mozilla source-map (CONSUMER.originalPositionFor())
retrieveSourceMap('URI|PATH') #Retrieve source map from URI|PATH
->OBJ|null #Can be:
# - in browser: [X-]SourceMap [S]
# - in Node: sourceMappingURL: base64 data URI or normal PATH|'file://...'
#Returns OBJ:
# - map SOURCE_MAP
# - url STR: 'URI|PATH' (if inline) or absolute sourceMappingURL
#I.e. performs potentially two fetches: 'URI|PATH' then sourceMappingURL
#Fetches are:
# - in browser: sync XHR
# - in Node: FS.readFileSync()
# - if OPTS.hookRequire true (def: false), pre-emptively done on require()
# (which is monkey-patched)
# - can also require('source-map-support/register-hook-require')
# - cached by URI|PATH
# - reset after each OBJ.stack if OPTS.emptyCacheBetweenOperations true (def: false)
#Can customize:
# - how fetch is performed with OPTS.retrieveFile FUNC[_ARR]('URI|PATH')->VAL:
# - unless OPTS.overrideRetrieveFile true, only fired if default one did not work
# - can use FUNC_ARR, in which case the first non-falsy VAL will be used
# - retrieveSourceMap() as a whole with OPTS.retrieveSourceMap|overrideRetrieveSourceMap
# which follow same logic
# - can use resetRetrieveHandlers() to reset those options
┌─────────────────────────┐
│ UNCAUGHT EXCEPTIONS │
└─────────────────────────┘
UNCAUGHT EXCEPTIONS ==> #After install(), on uncaught exceptions (Node-only):
# - fixes location in the faulty line of code prepended to uncaught exceptions
# - using getErrorSource()
# - do it by monkey-patching process.emit()
# - not done if either:
# - OPTS.handleUncaughtExceptions false (def: true)
# - process.on('uncaughtException') is already defined
getErrorSource(ERROR)->STR|null #Retrieve line of source code from the stack's last call.
#Do it by parsing stack trace then fetching the file with FS.readFileSync()