1
|
// 查找sourcemap
|
1
|
// 查找sourcemap
|
2
|
|
2
|
|
3
|
-const request = require('superagent');
|
|
|
4
|
const sourceMap = require('source-map');
|
3
|
const sourceMap = require('source-map');
|
5
|
const config = require('../../../config/config');
|
4
|
const config = require('../../../config/config');
|
6
|
const url = require('url');
|
5
|
const url = require('url');
|
|
|
6
|
+const path = require('path');
|
|
|
7
|
+const fs = require('fs');
|
7
|
|
8
|
|
8
|
const sourcesPathMap = {};
|
9
|
const sourcesPathMap = {};
|
9
|
|
10
|
|
|
|
11
|
+async function readFile(url) {
|
|
|
12
|
+ const filePath = path.join(config.sourceMap, url + '.map');
|
|
|
13
|
+
|
|
|
14
|
+ return new Promise(function(resolve, reject) {
|
|
|
15
|
+ fs.readFile(filePath, function(err, data) {
|
|
|
16
|
+ if (err) {
|
|
|
17
|
+ reject(err);
|
|
|
18
|
+ return;
|
|
|
19
|
+ }
|
|
|
20
|
+
|
|
|
21
|
+ resolve(data);
|
|
|
22
|
+ })
|
|
|
23
|
+
|
|
|
24
|
+ });
|
|
|
25
|
+}
|
|
|
26
|
+
|
10
|
function fixPath(filepath) {
|
27
|
function fixPath(filepath) {
|
11
|
return filepath.replace(/\.[\.\/]+/g, "");
|
28
|
return filepath.replace(/\.[\.\/]+/g, "");
|
12
|
}
|
29
|
}
|
|
@@ -17,11 +34,7 @@ async function lookupSourceMap(fileUrl, line, column) { |
|
@@ -17,11 +34,7 @@ async function lookupSourceMap(fileUrl, line, column) { |
17
|
}
|
34
|
}
|
18
|
|
35
|
|
19
|
const urlPath = url.parse(fileUrl).pathname;
|
36
|
const urlPath = url.parse(fileUrl).pathname;
|
20
|
-
|
|
|
21
|
- const {body: content} = await request.get(`${config.sourceMap.domain}/api/sourcemap/load`)
|
|
|
22
|
- .responseType('blob')
|
|
|
23
|
- .query({path: urlPath});
|
|
|
24
|
-
|
37
|
+ const {body: content} = await readFile(urlPath);
|
25
|
const fileContent = content.toString();
|
38
|
const fileContent = content.toString();
|
26
|
const fileObj = JSON.parse(fileContent);
|
39
|
const fileObj = JSON.parse(fileContent);
|
27
|
const sources = fileObj.sources;
|
40
|
const sources = fileObj.sources;
|