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
141 lines (104 loc) • 3.6 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _bluebird() {
const data = require("bluebird");
_bluebird = function () {
return data;
};
return data;
}
function _scope() {
const data = require("../../../scope");
_scope = function () {
return data;
};
return data;
}
function _consumer() {
const data = require("../../../consumer");
_consumer = function () {
return data;
};
return data;
}
function _logger() {
const data = _interopRequireDefault(require("../../../logger/logger"));
_logger = function () {
return data;
};
return data;
}
function _scopeComponentsImporter() {
const data = _interopRequireDefault(require("../../../scope/component-ops/scope-components-importer"));
_scopeComponentsImporter = function () {
return data;
};
return data;
}
function _isolator() {
const data = _interopRequireDefault(require("../../../environment/isolator"));
_isolator = function () {
return data;
};
return data;
}
var _default = /*#__PURE__*/function () {
var _isolate = (0, _bluebird().coroutine)(function* (componentId, scopePath, opts) {
if (opts.useCapsule) {
return isolateUsingCapsule(componentId, opts);
}
_logger().default.debugAndAddBreadCrumb('isolate', 'starting isolation process');
if (opts.verbose) console.log('starting isolation process'); // eslint-disable-line no-console
let scope; // If a scope path provided we will take the component from that scope
if (scopePath) {
scope = yield (0, _scope().loadScope)(scopePath);
const bitId = yield scope.getParsedId(componentId);
return isolateComponent(scope, bitId, opts);
} // If a scope path was not provided we will get the consumer's scope
const consumer = yield (0, _consumer().loadConsumer)();
scope = consumer.scope;
const bitId = consumer.getParsedId(componentId);
return isolateComponent(scope, bitId, opts);
});
function isolate(_x, _x2, _x3) {
return _isolate.apply(this, arguments);
}
return isolate;
}();
exports.default = _default;
function isolateUsingCapsule(_x4, _x5) {
return _isolateUsingCapsule.apply(this, arguments);
}
/**
* import a component end to end. Including importing the dependencies and installing the npm
* packages.
*
* @param {BitId} bitId - the component id to isolate
* @param {IsolateOptions} opts
* @return {Promise.<string>} - the path to the isolated component
*/
function _isolateUsingCapsule() {
_isolateUsingCapsule = (0, _bluebird().coroutine)(function* (componentId, opts) {
opts.applyExtensionsAddedConfig = true;
const consumer = yield (0, _consumer().loadConsumer)();
const bitId = consumer.getParsedId(componentId);
const isolator = yield _isolator().default.getInstance('fs', consumer.scope, consumer, opts.writeToPath);
return isolator.isolate(bitId, opts);
});
return _isolateUsingCapsule.apply(this, arguments);
}
function isolateComponent(_x6, _x7, _x8) {
return _isolateComponent.apply(this, arguments);
}
function _isolateComponent() {
_isolateComponent = (0, _bluebird().coroutine)(function* (scope, bitId, opts) {
const scopeComponentsImporter = _scopeComponentsImporter().default.getInstance(scope);
const component = yield scopeComponentsImporter.loadComponent(bitId); // @ts-ignore
return component.isolate(scope, opts);
});
return _isolateComponent.apply(this, arguments);
}