smipper 6.0.0 → 7.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.
Files changed (2) hide show
  1. package/index.js +55 -13
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -2,10 +2,39 @@
2
2
  "use strict";
3
3
 
4
4
  const fs = require("fs");
5
- const loader = require("path-loader");
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
+
13
+ function load(path)
14
+ {
15
+ return new Promise((resolve, reject) => {
16
+ if (path.startsWith("file:///")) {
17
+ try {
18
+ resolve(fs.readFileSync(path.substr(7), "utf8"));
19
+ } catch (err) {
20
+ reject(err);
21
+ }
22
+ return;
23
+ }
24
+ let retryIndex = 0;
25
+ async function get()
26
+ {
27
+ try {
28
+ const response = await got.get(path, { retry: { limit: retries } });
29
+ return response.body;
30
+ } catch (err) {
31
+ reject(err);
32
+ }
33
+ }
34
+
35
+ get().then(resolve, reject);
36
+ });
37
+ }
9
38
 
10
39
  const sourceMaps = {};
11
40
  function loadUri(path) {
@@ -13,12 +42,14 @@ function loadUri(path) {
13
42
  path = "file://" + path;
14
43
  }
15
44
  return new Promise((resolve, reject) => {
45
+ if (verbose)
46
+ console.log("loading", path);
16
47
  if (!(path in sourceMaps)) {
17
48
  sourceMaps[path] = {
18
49
  resolvers: [ resolve ],
19
50
  rejecters: [ reject ]
20
51
  };
21
- loader.load(path).then(jsData => {
52
+ load(path).then(jsData => {
22
53
  const idx = jsData.lastIndexOf("//# sourceMappingURL=");
23
54
  if (verbose)
24
55
  console.error("Got the file", jsData.length, idx);
@@ -31,7 +62,7 @@ function loadUri(path) {
31
62
  }
32
63
  return (new url.URL(mapUrl, path)).href;
33
64
  }).then(mapUrl => {
34
- return loader.load(mapUrl);
65
+ return load(mapUrl);
35
66
  }).then(sourceMapData => {
36
67
  const parsed = JSON.parse(sourceMapData);
37
68
  const smap = new sourceMap.SourceMapConsumer(parsed);
@@ -55,28 +86,33 @@ function loadUri(path) {
55
86
  });
56
87
  }
57
88
 
58
- let stack;
59
- let json = false;
89
+ let hasInput = false;
60
90
  for (let i=2; i<process.argv.length; ++i) {
61
91
  try {
62
92
  const arg = process.argv[i];
63
93
  if (verbose)
64
94
  console.error("got arg", arg);
65
- if (arg === "-") {
66
- stack = fs.readFileSync("/dev/stdin").toString();
67
- } else if (arg === "-f" || arg === "--file") {
95
+ if (arg === "-f" || arg === "--file") {
68
96
  stack = fs.readFileSync(process.argv[++i]).toString();
69
- } else if ( arg.lastIndexOf("-f", 0) === 0) {
97
+ } else if ( arg.startsWith("-f") === 0) {
70
98
  stack = fs.readFileSync(arg.substr(2)).toString();
71
- } else if (arg.lastIndexOf("--file=", 0) === 0) {
99
+ } else if (arg.startsWith("--file=") === 0) {
72
100
  stack = fs.readFileSync(arg.substr(7)).toString();
73
101
  } else if (arg === "--verbose" || arg === "-v") {
74
102
  verbose = true;
75
103
  } else if (arg === "--json") {
76
104
  json = true;
105
+ } else if (arg.startsWith("--retries")) {
106
+ retries = parseInt(arg.substr(9));
107
+ if (isNaN(retries) || retries < 0) {
108
+ console.error("smipper [stack|-h|--help|-v|--verbose|--retries=<number>|--json|-f=@FILE@|-");
109
+ process.exit(1);
110
+ }
77
111
  } else if (arg === "-h" || arg === "--help") {
78
- console.error("smipper [stack|-h|--help|-v|--verbose|--json|-f=@FILE@|-");
112
+ console.error("smipper [stack|-h|--help|-v|--verbose|--retries=<number>|--json|-f=@FILE@|-");
79
113
  process.exit(0);
114
+ } else if (arg === "-") {
115
+ // stdin
80
116
  } else {
81
117
  stack = arg;
82
118
  }
@@ -87,8 +123,11 @@ for (let i=2; i<process.argv.length; ++i) {
87
123
  }
88
124
 
89
125
  if (!stack) {
90
- console.error("Nothing to do");
91
- process.exit(0);
126
+ stack = fs.readFileSync("/dev/stdin").toString();
127
+ if (!stack) {
128
+ console.error("Nothing to do");
129
+ process.exit(0);
130
+ }
92
131
  }
93
132
 
94
133
  function processFrame(functionName, url, line, column)
@@ -204,6 +243,9 @@ if (json) {
204
243
  }
205
244
  return processFrame(match[1] || "", match[2], parseInt(match[3]), parseInt(match[4]));
206
245
  })).then((results) => {
246
+ if (!results.length) {
247
+ throw new Error("Empty output");
248
+ }
207
249
  results.forEach(str => {
208
250
  console.log(str);
209
251
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smipper",
3
- "version": "6.0.0",
3
+ "version": "7.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
- "path-loader": "^1.0.10",
15
+ "got": "^9.6.0",
16
16
  "source-map": "^0.7.3"
17
17
  }
18
18
  }