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