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
122 lines (89 loc) • 2.63 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Dependencies = exports.DependencyList = exports.ComponentDependency = exports.PackageDependency = exports.Dependency = exports.DependencyId = void 0;
function _bitId() {
const data = require("../../../bit-id");
_bitId = function () {
return data;
};
return data;
}
function _generalError() {
const data = _interopRequireDefault(require("../../../error/general-error"));
_generalError = function () {
return data;
};
return data;
}
/* eslint-disable max-classes-per-file */
const DEV_ENV = 'development';
const RUNTIME_ENV = 'runtime'; // type Environment = DEV_ENV | RUNTIME_ENV;
// type WrappingMethod = 'component' | 'package';
class DependencyId extends _bitId().BitId {}
exports.DependencyId = DependencyId;
class Dependency {
constructor(id) {
this.id = id;
}
}
exports.Dependency = Dependency;
class PackageDependency extends Dependency {}
exports.PackageDependency = PackageDependency;
class ComponentDependency extends Dependency {}
exports.ComponentDependency = ComponentDependency;
class DependencyList extends Array {
/**
* Get only package dependencies
*
* @readonly
* @memberof DependencyList
*/
get packages() {
return this.filter(dep => dep instanceof PackageDependency);
}
get components() {
return this.filter(dep => dep instanceof ComponentDependency);
}
static fromArray(dependencies) {
return new DependencyList(...dependencies);
}
}
exports.DependencyList = DependencyList;
class Dependencies {
constructor(runtime, dev, peer) {
this.runtime = runtime;
this.dev = dev;
this.peer = peer;
}
getByEnvironment(env) {
if (env === DEV_ENV) {
return DependencyList.fromArray(this.runtime.concat(this.dev).concat(this.peer));
}
if (env === RUNTIME_ENV) {
return DependencyList.fromArray(this.runtime.concat(this.peer));
}
throw new (_generalError().default)(`env ${env} is not supported`);
}
/**
* Get dependencies needed for development environnement such as runtime, dev and peer
*
* @returns {DependencyList}
* @memberof Dependencies
*/
computeDev() {
return this.getByEnvironment(DEV_ENV);
}
/**
* Get dependencies needed for runtime environnement such as runtime and peer
*
* @returns {DependencyList}
* @memberof Dependencies
*/
computeRuntime() {
return this.getByEnvironment(RUNTIME_ENV);
}
}
exports.Dependencies = Dependencies;
;