|
|
// 查找sourcemap
|
|
|
|
|
|
const request = require('superagent');
|
|
|
const sourceMap = require('source-map');
|
|
|
const config = require('../../../config/config');
|
|
|
const url = require('url');
|
|
|
const path = require('path');
|
|
|
const fs = require('fs');
|
|
|
|
|
|
const sourcesPathMap = {};
|
|
|
|
|
|
async function readFile(url) {
|
|
|
const filePath = path.join(config.sourceMap, url + '.map');
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
fs.readFile(filePath, function(err, data) {
|
|
|
if (err) {
|
|
|
reject(err);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
resolve(data);
|
|
|
})
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function fixPath(filepath) {
|
|
|
return filepath.replace(/\.[\.\/]+/g, "");
|
|
|
}
|
...
|
...
|
@@ -17,11 +34,7 @@ async function lookupSourceMap(fileUrl, line, column) { |
|
|
}
|
|
|
|
|
|
const urlPath = url.parse(fileUrl).pathname;
|
|
|
|
|
|
const {body: content} = await request.get(`${config.sourceMap.domain}/api/sourcemap/load`)
|
|
|
.responseType('blob')
|
|
|
.query({path: urlPath});
|
|
|
|
|
|
const {body: content} = await readFile(urlPath);
|
|
|
const fileContent = content.toString();
|
|
|
const fileObj = JSON.parse(fileContent);
|
|
|
const sources = fileObj.sources;
|
...
|
...
|
|