feat(sourcemaps): refactored
This commit is contained in:
parent
4b0da35c6d
commit
f51e8bee19
4 changed files with 21 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
cd sourcemap-reader
|
||||
nohup npm start &> /tmp/sourcemap-reader.log &
|
||||
nohup npm start &
|
||||
cd ..
|
||||
uvicorn app:app --host 0.0.0.0 --port $LISTEN_PORT --reload --proxy-headers
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
sh env_vars.sh
|
||||
source /tmp/.env.override
|
||||
cd sourcemap-reader
|
||||
nohup npm start &> /tmp/sourcemap-reader.log &
|
||||
nohup npm start &
|
||||
cd ..
|
||||
uvicorn app:app --host 0.0.0.0 --port $LISTEN_PORT --reload --proxy-headers
|
||||
|
|
|
|||
1
sourcemap-reader/.gitignore
vendored
1
sourcemap-reader/.gitignore
vendored
|
|
@ -4,3 +4,4 @@ npm-debug.log
|
|||
.cache
|
||||
test.html
|
||||
/utils/
|
||||
mappings.wasm
|
||||
|
|
|
|||
|
|
@ -40,12 +40,21 @@ module.exports.sourcemapReader = async event => {
|
|||
Key: event.key
|
||||
};
|
||||
return new Promise(function (resolve, reject) {
|
||||
const getObjectStart = Date.now();
|
||||
s3.getObject(options, (err, data) => {
|
||||
if (err) {
|
||||
console.error("[SR] Get S3 object failed");
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
}
|
||||
const getObjectEnd = Date.now();
|
||||
const fileSize = (data.ContentLength / 1024) / 1024;
|
||||
options.fileSize = `${fileSize} Mb`;
|
||||
const downloadTime = (getObjectEnd - getObjectStart) / 1000;
|
||||
options.downloadTime = `${downloadTime} s`;
|
||||
if (fileSize >= 3) {
|
||||
console.log("[SR] large file:" + JSON.stringify(options));
|
||||
}
|
||||
let sourcemap = data.Body.toString();
|
||||
|
||||
return new sourceMap.SourceMapConsumer(sourcemap)
|
||||
|
|
@ -68,17 +77,15 @@ module.exports.sourcemapReader = async event => {
|
|||
preview = preview.slice(start, original.line + event.padding);
|
||||
}
|
||||
} else {
|
||||
console.log("[SR] source not found, null preview for:");
|
||||
console.log(original.source);
|
||||
console.log(`[SR] source not found, null preview for: ${original.source}`);
|
||||
preview = []
|
||||
}
|
||||
url = URL.parse(original.source);
|
||||
} else {
|
||||
console.log("[SR] couldn't find original position of:");
|
||||
console.log({
|
||||
console.log("[SR] couldn't find original position of: " + JSON.stringify({
|
||||
line: event.positions[i].line,
|
||||
column: event.positions[i].column
|
||||
});
|
||||
}));
|
||||
}
|
||||
let result = {
|
||||
"absPath": url.href,
|
||||
|
|
@ -92,6 +99,12 @@ module.exports.sourcemapReader = async event => {
|
|||
results.push(result);
|
||||
}
|
||||
consumer = undefined;
|
||||
|
||||
const sourcemapProcessingTime = (Date.now() - getObjectEnd) / 1000;
|
||||
options.sourcemapProcessingTime = `${sourcemapProcessingTime} s`
|
||||
if (fileSize >= 3 || sourcemapProcessingTime > 2) {
|
||||
console.log("[SR] " + JSON.stringify(options));
|
||||
}
|
||||
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
|
||||
return resolve(results);
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue