smipper 5.0.0 → 8.0.0
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/index.js +85 -41
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -2,10 +2,86 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
const fs = require("fs");
|
|
5
|
-
const
|
|
5
|
+
const got = require("got");
|
|
6
6
|
const sourceMap = require("source-map");
|
|
7
7
|
const url = require("url");
|
|
8
8
|
let verbose = false;
|
|
9
|
+
let stack;
|
|
10
|
+
let json = false;
|
|
11
|
+
let retries = 3;
|
|
12
|
+
let jsc = 0;
|
|
13
|
+
|
|
14
|
+
let hasInput = false;
|
|
15
|
+
for (let i=2; i<process.argv.length; ++i) {
|
|
16
|
+
try {
|
|
17
|
+
const arg = process.argv[i];
|
|
18
|
+
if (verbose)
|
|
19
|
+
console.error("got arg", arg);
|
|
20
|
+
if (arg === "-f" || arg === "--file") {
|
|
21
|
+
stack = fs.readFileSync(process.argv[++i]).toString();
|
|
22
|
+
} else if ( arg.startsWith("-f") === 0) {
|
|
23
|
+
stack = fs.readFileSync(arg.substr(2)).toString();
|
|
24
|
+
} else if (arg.startsWith("--file=") === 0) {
|
|
25
|
+
stack = fs.readFileSync(arg.substr(7)).toString();
|
|
26
|
+
} else if (arg === "--verbose" || arg === "-v") {
|
|
27
|
+
verbose = true;
|
|
28
|
+
} else if (arg === "--json") {
|
|
29
|
+
json = true;
|
|
30
|
+
} else if (arg === "--jsc") { // jsc has the wrong column for some reason
|
|
31
|
+
jsc = 1;
|
|
32
|
+
} else if (arg.startsWith("--retries")) {
|
|
33
|
+
retries = parseInt(arg.substr(9));
|
|
34
|
+
if (isNaN(retries) || retries < 0) {
|
|
35
|
+
console.error("smipper [stack|-h|--help|-v|--verbose|--retries=<number>|--jsc|--json|-f=@FILE@|-");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
39
|
+
console.error("smipper [stack|-h|--help|-v|--verbose|--retries=<number>|--jsc|--json|-f=@FILE@|-");
|
|
40
|
+
process.exit(0);
|
|
41
|
+
} else if (arg === "-") {
|
|
42
|
+
// stdin
|
|
43
|
+
} else {
|
|
44
|
+
stack = arg;
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("Error: " + err.toString());
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!stack) {
|
|
53
|
+
stack = fs.readFileSync("/dev/stdin").toString();
|
|
54
|
+
if (!stack) {
|
|
55
|
+
console.error("Nothing to do");
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function load(path)
|
|
61
|
+
{
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
if (path.startsWith("file:///")) {
|
|
64
|
+
try {
|
|
65
|
+
resolve(fs.readFileSync(path.substr(7), "utf8"));
|
|
66
|
+
} catch (err) {
|
|
67
|
+
reject(err);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let retryIndex = 0;
|
|
72
|
+
async function get()
|
|
73
|
+
{
|
|
74
|
+
try {
|
|
75
|
+
const response = await got.get(path, { retry: { limit: retries } });
|
|
76
|
+
return response.body;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
reject(err);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get().then(resolve, reject);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
9
85
|
|
|
10
86
|
const sourceMaps = {};
|
|
11
87
|
function loadUri(path) {
|
|
@@ -13,12 +89,14 @@ function loadUri(path) {
|
|
|
13
89
|
path = "file://" + path;
|
|
14
90
|
}
|
|
15
91
|
return new Promise((resolve, reject) => {
|
|
92
|
+
if (verbose)
|
|
93
|
+
console.log("loading", path);
|
|
16
94
|
if (!(path in sourceMaps)) {
|
|
17
95
|
sourceMaps[path] = {
|
|
18
96
|
resolvers: [ resolve ],
|
|
19
97
|
rejecters: [ reject ]
|
|
20
98
|
};
|
|
21
|
-
|
|
99
|
+
load(path).then(jsData => {
|
|
22
100
|
const idx = jsData.lastIndexOf("//# sourceMappingURL=");
|
|
23
101
|
if (verbose)
|
|
24
102
|
console.error("Got the file", jsData.length, idx);
|
|
@@ -31,7 +109,7 @@ function loadUri(path) {
|
|
|
31
109
|
}
|
|
32
110
|
return (new url.URL(mapUrl, path)).href;
|
|
33
111
|
}).then(mapUrl => {
|
|
34
|
-
return
|
|
112
|
+
return load(mapUrl);
|
|
35
113
|
}).then(sourceMapData => {
|
|
36
114
|
const parsed = JSON.parse(sourceMapData);
|
|
37
115
|
const smap = new sourceMap.SourceMapConsumer(parsed);
|
|
@@ -55,42 +133,6 @@ function loadUri(path) {
|
|
|
55
133
|
});
|
|
56
134
|
}
|
|
57
135
|
|
|
58
|
-
let stack;
|
|
59
|
-
let json = false;
|
|
60
|
-
for (let i=2; i<process.argv.length; ++i) {
|
|
61
|
-
try {
|
|
62
|
-
const arg = process.argv[i];
|
|
63
|
-
if (verbose)
|
|
64
|
-
console.error("got arg", arg);
|
|
65
|
-
if (arg === "-") {
|
|
66
|
-
stack = fs.readFileSync("/dev/stdin").toString();
|
|
67
|
-
} else if (arg === "-f" || arg === "--file") {
|
|
68
|
-
stack = fs.readFileSync(process.argv[++i]).toString();
|
|
69
|
-
} else if ( arg.lastIndexOf("-f", 0) === 0) {
|
|
70
|
-
stack = fs.readFileSync(arg.substr(2)).toString();
|
|
71
|
-
} else if (arg.lastIndexOf("--file=", 0) === 0) {
|
|
72
|
-
stack = fs.readFileSync(arg.substr(7)).toString();
|
|
73
|
-
} else if (arg === "--verbose" || arg === "-v") {
|
|
74
|
-
verbose = true;
|
|
75
|
-
} else if (arg === "--json") {
|
|
76
|
-
json = true;
|
|
77
|
-
} else if (arg === "-h" || arg === "--help") {
|
|
78
|
-
console.error("smipper [stack|-h|--help|-v|--verbose|--json|-f=@FILE@|-");
|
|
79
|
-
process.exit(0);
|
|
80
|
-
} else {
|
|
81
|
-
stack = arg;
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
console.error("Error: " + err.toString());
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!stack) {
|
|
90
|
-
console.error("Nothing to do");
|
|
91
|
-
process.exit(0);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
136
|
function processFrame(functionName, url, line, column)
|
|
95
137
|
{
|
|
96
138
|
if (verbose)
|
|
@@ -110,8 +152,7 @@ function processFrame(functionName, url, line, column)
|
|
|
110
152
|
|
|
111
153
|
// it appears that we're supposed to reduce the column
|
|
112
154
|
// number by 1 when we get this from jsc
|
|
113
|
-
|
|
114
|
-
const pos = smap.originalPositionFor({ line, column });
|
|
155
|
+
const pos = smap.originalPositionFor({ line, column: column - jsc });
|
|
115
156
|
if (!pos.source) {
|
|
116
157
|
if (verbose)
|
|
117
158
|
console.error("nothing here", pos);
|
|
@@ -204,6 +245,9 @@ if (json) {
|
|
|
204
245
|
}
|
|
205
246
|
return processFrame(match[1] || "", match[2], parseInt(match[3]), parseInt(match[4]));
|
|
206
247
|
})).then((results) => {
|
|
248
|
+
if (!results.length) {
|
|
249
|
+
throw new Error("Empty output");
|
|
250
|
+
}
|
|
207
251
|
results.forEach(str => {
|
|
208
252
|
console.log(str);
|
|
209
253
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smipper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "",
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"
|
|
15
|
+
"got": "^9.6.0",
|
|
16
16
|
"source-map": "^0.7.3"
|
|
17
17
|
}
|
|
18
18
|
}
|