mirror of https://github.com/status-im/metro.git
buck worker tool: catch errors thrown from commands, and respond with errors.
Reviewed By: cpojer Differential Revision: D4057884 fbshipit-source-id: acfe0cc57b541a534dd640380c69f591c1fb83c6
This commit is contained in:
parent
d60ac14fd0
commit
05d53084c1
|
@ -29,14 +29,8 @@ const defaultVariants = {default: {}};
|
||||||
const moduleFactoryParameters = ['require', 'module', 'global', 'exports'];
|
const moduleFactoryParameters = ['require', 'module', 'global', 'exports'];
|
||||||
|
|
||||||
function transformJSON(infile, options, outfile, callback) {
|
function transformJSON(infile, options, outfile, callback) {
|
||||||
let json, value;
|
const json = fs.readFileSync(infile, 'utf8');
|
||||||
try {
|
const value = JSON.parse(json);
|
||||||
json = fs.readFileSync(infile, 'utf8');
|
|
||||||
value = JSON.parse(json);
|
|
||||||
} catch (readError) {
|
|
||||||
callback(readError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filename = options.filename || infile;
|
const filename = options.filename || infile;
|
||||||
const code =
|
const code =
|
||||||
|
@ -71,13 +65,7 @@ function transformJSON(infile, options, outfile, callback) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
writeResult(outfile, result);
|
writeResult(outfile, result);
|
||||||
} catch (writeError) {
|
|
||||||
callback(writeError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,14 +75,8 @@ function transformModule(infile, options, outfile, callback) {
|
||||||
return transformJSON(infile, options, outfile, callback);
|
return transformJSON(infile, options, outfile, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
let code, transform;
|
const transform = require(options.transform);
|
||||||
try {
|
const code = fs.readFileSync(infile, 'utf8');
|
||||||
transform = require(options.transform);
|
|
||||||
code = fs.readFileSync(infile, 'utf8');
|
|
||||||
} catch (readError) {
|
|
||||||
callback(readError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const variants = options.variants || defaultVariants;
|
const variants = options.variants || defaultVariants;
|
||||||
const tasks = {};
|
const tasks = {};
|
||||||
|
@ -136,30 +118,18 @@ function transformModule(infile, options, outfile, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function optimizeModule(infile, outfile, options, callback) {
|
function optimizeModule(infile, outfile, options, callback) {
|
||||||
let data;
|
const data = JSON.parse(fs.readFileSync(infile, 'utf8'));
|
||||||
try {
|
|
||||||
data = JSON.parse(fs.readFileSync(infile, 'utf8'));
|
|
||||||
} catch (readError) {
|
|
||||||
callback(readError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const transformed = data.transformed;
|
const transformed = data.transformed;
|
||||||
const result = Object.assign({}, data);
|
const result = Object.assign({}, data);
|
||||||
result.transformed = {};
|
result.transformed = {};
|
||||||
|
|
||||||
const file = data.file;
|
const file = data.file;
|
||||||
const code = data.code;
|
const code = data.code;
|
||||||
try {
|
|
||||||
Object.keys(transformed).forEach(key => {
|
Object.keys(transformed).forEach(key => {
|
||||||
result.transformed[key] = optimize(transformed[key], file, code, options);
|
result.transformed[key] = optimize(transformed[key], file, code, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
writeResult(outfile, result);
|
writeResult(outfile, result);
|
||||||
} catch (error) {
|
|
||||||
callback(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue