mirror of https://github.com/status-im/metro.git
File transform events
Summary: Correctly generate log entries for file transforms and ping telemetry using the new Logger API. Reviewed By: bestander, cpojer Differential Revision: D4081325 fbshipit-source-id: 7d50d54eb673a0276512db6ad5ff21c344495612
This commit is contained in:
parent
4d23c1f423
commit
1ac86b2304
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const Logger = require('../Logger');
|
||||||
const Promise = require('promise');
|
const Promise = require('promise');
|
||||||
|
|
||||||
const declareOpts = require('../lib/declareOpts');
|
const declareOpts = require('../lib/declareOpts');
|
||||||
|
@ -115,6 +116,8 @@ class Transformer {
|
||||||
return this
|
return this
|
||||||
._transform(this._transformModulePath, fileName, code, options)
|
._transform(this._transformModulePath, fileName, code, options)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
Logger.log(result.transformFileStartLogEntry);
|
||||||
|
Logger.log(result.transformFileEndLogEntry);
|
||||||
debug('done transforming file', fileName);
|
debug('done transforming file', fileName);
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,6 +24,14 @@ function transformCode(transform, filename, sourceCode, options, callback) {
|
||||||
const params = makeTransformParams(filename, sourceCode, options.transform);
|
const params = makeTransformParams(filename, sourceCode, options.transform);
|
||||||
const isJson = filename.endsWith('.json');
|
const isJson = filename.endsWith('.json');
|
||||||
|
|
||||||
|
const transformFileStartLogEntry = {
|
||||||
|
action_name: 'Transforming file',
|
||||||
|
action_phase: 'start',
|
||||||
|
file_name: filename,
|
||||||
|
log_entry_label: 'Transforming file',
|
||||||
|
start_timestamp: process.hrtime(),
|
||||||
|
};
|
||||||
|
|
||||||
transform(params, (error, transformed) => {
|
transform(params, (error, transformed) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
|
@ -52,8 +60,20 @@ function transformCode(transform, filename, sourceCode, options, callback) {
|
||||||
? {dependencies: [], dependencyOffsets: []}
|
? {dependencies: [], dependencyOffsets: []}
|
||||||
: extractDependencies(code);
|
: extractDependencies(code);
|
||||||
|
|
||||||
|
const timeDelta = process.hrtime(transformFileStartLogEntry.start_timestamp);
|
||||||
|
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
||||||
|
const transformFileEndLogEntry = {
|
||||||
|
action_name: 'Transforming file',
|
||||||
|
action_phase: 'end',
|
||||||
|
file_name: filename,
|
||||||
|
duration_ms: duration_ms,
|
||||||
|
log_entry_label: 'Transforming file',
|
||||||
|
};
|
||||||
|
|
||||||
result.code = code;
|
result.code = code;
|
||||||
result.map = map;
|
result.map = map;
|
||||||
|
result.transformFileStartLogEntry = transformFileStartLogEntry;
|
||||||
|
result.transformFileEndLogEntry = transformFileEndLogEntry;
|
||||||
|
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue