bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
204 lines (156 loc) • 5.74 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = run;
function _bluebird() {
const data = require("bluebird");
_bluebird = function () {
return data;
};
return data;
}
function _serializeError() {
const data = require("serialize-error");
_serializeError = function () {
return data;
};
return data;
}
function _test() {
const data = require("../api/consumer/lib/test");
_test = function () {
return data;
};
return data;
}
function _loader() {
const data = _interopRequireDefault(require("../cli/loader"));
_loader = function () {
return data;
};
return data;
}
function _externalErrors() {
const data = _interopRequireDefault(require("../error/external-errors"));
_externalErrors = function () {
return data;
};
return data;
}
function _externalError() {
const data = _interopRequireDefault(require("../error/external-error"));
_externalError = function () {
return data;
};
return data;
}
const testOneComponent = verbose => /*#__PURE__*/function () {
var _ref = (0, _bluebird().coroutine)(function* (id) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const res = yield (0, _test().testInProcess)(id, false, verbose);
return res.results[0];
});
return function (_x) {
return _ref.apply(this, arguments);
};
}();
function run() {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const ids = process.env.__ids__ ? process.env.__ids__.split() : undefined; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const verbose = process.env.__verbose__ === true || process.env.__verbose__ === 'true';
const includeUnmodified = // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
process.env.__includeUnmodified__ === true || process.env.__includeUnmodified__ === 'true';
if (!ids || !ids.length) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
return (0, _test().testInProcess)(undefined, includeUnmodified, verbose).then(results => {
const serializedResults = serializeResults(results.results); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
process.send(serializedResults); // Make sure the child process will not hang
// This is inside timeout, since in rare cases the exit might happen before the send
// which cause the parent process to hang (since it never get the message)
setTimeout(() => {
process.exit();
}, 0);
}).catch(e => {
_loader().default.off();
const serializedResults = serializeResults(e); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
process.send(serializedResults); // Make sure the child process will not hang
// This is inside timeout, since in rare cases the exit might happen before the send
// which cause the parent process to hang (since it never get the message)
setTimeout(() => {
process.exit();
}, 0);
});
}
const testAllP = ids.map(testOneComponent(verbose));
return Promise.all(testAllP).then(results => {
const serializedResults = serializeResults(results); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
process.send(serializedResults); // Make sure the child process will not hang
// This is inside timeout, since in rare cases the exit might happen before the send
// which cause the parent process to hang (since it never get the message)
setTimeout(() => {
process.exit();
}, 0);
}).catch(e => {
_loader().default.off();
const serializedResults = serializeResults(e); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
process.send(serializedResults); // Make sure the child process will not hang
// This is inside timeout, since in rare cases the exit might happen before the send
// which cause the parent process to hang (since it never get the message)
setTimeout(() => {
process.exit();
}, 0);
});
}
run();
function serializeResults(results) {
// if (!results) return undefined;
if (!results) {
return {
type: 'results',
results: []
};
}
if (results instanceof Error) {
// In case of external error also serialize the original error
if (results instanceof _externalErrors().default) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
results.originalErrors = results.originalErrors.map(_serializeError().serializeError);
}
if (results instanceof _externalError().default) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
results.originalError = (0, _serializeError().serializeError)(results);
}
const serializedErr = (0, _serializeError().serializeError)(results);
const finalResults = {
type: 'error',
error: serializedErr
}; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
return finalResults;
}
const serializeFailure = failure => {
if (!failure) return undefined;
const serializedFailure = failure;
if (failure.err && failure.err instanceof Error) {
serializedFailure.err = (0, _serializeError().serializeError)(failure.err);
}
return serializedFailure;
};
const serializeSpec = spec => {
if (!spec.failures) return spec;
spec.failures = spec.failures.map(serializeFailure);
return spec;
};
const serializeResult = result => {
const specs = result.specs;
if (!specs || !Array.isArray(specs)) return result;
result.specs = specs.map(serializeSpec);
return result;
};
const serializedResults = results.map(serializeResult);
return {
type: 'results',
results: serializedResults
};
}
;