What is ember-cli-version-checker?
The ember-cli-version-checker package is a utility for checking the versions of npm and bower dependencies in Ember CLI projects. It helps ensure compatibility and manage dependencies effectively.
What are ember-cli-version-checker's main functionalities?
Check Dependency Version
This feature allows you to check if a specific dependency version is less than a given version. In this example, it checks if the 'ember-source' version is less than '3.0.0'.
const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let dep = checker.for('ember-source', 'npm');
if (dep.lt('3.0.0')) {
console.log('ember-source version is less than 3.0.0');
}
Check Multiple Dependencies
This feature allows you to check multiple dependencies at once. In this example, it checks if both 'ember-source' and 'jquery' versions are less than '3.0.0'.
const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let emberDep = checker.for('ember-source', 'npm');
let jqueryDep = checker.for('jquery', 'bower');
if (emberDep.lt('3.0.0') && jqueryDep.lt('3.0.0')) {
console.log('Both ember-source and jquery versions are less than 3.0.0');
}
Check Dependency Range
This feature allows you to check if a dependency version falls within a specified range. In this example, it checks if the 'ember-source' version is between '2.0.0' and '3.0.0'.
const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let dep = checker.for('ember-source', 'npm');
if (dep.satisfies('>=2.0.0 <3.0.0')) {
console.log('ember-source version is between 2.0.0 and 3.0.0');
}
Other packages similar to ember-cli-version-checker
semver
The 'semver' package is a widely-used utility for parsing, validating, and comparing semantic versioning (semver) strings. It provides similar functionality for version checking but is not specific to Ember CLI projects. It is more general-purpose and can be used in any JavaScript project.
npm-check
The 'npm-check' package is a tool for checking for outdated, incorrect, and unused dependencies in npm projects. While it provides some overlapping functionality with ember-cli-version-checker, it is more focused on overall dependency management and maintenance rather than specific version checks within Ember CLI projects.
yarn
The 'yarn' package manager includes built-in functionality for checking and managing dependency versions. It provides a more comprehensive solution for dependency management, including version checks, but is not specific to Ember CLI projects. It is an alternative to npm with additional features for dependency resolution and management.
Ember CLI Version Checker
Makes it easier to determine if a compatible version of a given NPM or Bower package is present.
Usage
assertAbove
Throws an error with the given message if a minimum version isn't met.
let VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
this._super && this._super.init.apply(this, arguments);
let checker = new VersionChecker(this);
checker.for('ember-cli').assertAbove('2.0.0');
}
};
You can also provide a specific message as the third argument to assertAbove
if you'd like to customize the output.
let VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
let checker = new VersionChecker(this);
checker.for('ember-cli').assertAbove('2.0.0', 'To use awesome-addon you must have ember-cli 2.0.0');
}
};
isAbove
Returns true
if the packages version is above the specified comparison range.
let VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
let checker = new VersionChecker(this);
let dep = checker.for('ember-cli');
if (dep.isAbove('2.0.0')) {
} else {
};
}
};
Real World Example
You want to provide two different sets of templates, based on the currently running Ember version.
let path = require('path');
let VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
treeForAddonTemplates: function(tree) {
let checker = new VersionChecker(this);
let dep = checker.for('ember', 'bower');
let baseTemplatesPath = path.join(this.root, 'addon/templates');
if (dep.satisfies('>= 1.13.0') {
return this.treeGenerator(path.join(baseTemplatesPath, 'current'));
} else {
return this.treeGenerator(path.join(baseTemplatesPath, 'legacy'));
}
}
};
forEmber
Since ember introduced the ember-source
from NPM, ember has two ways to be
shipped. One from bower ember
and other from NPM ember-source
. The
function forEmber
will look for ember-source
from NPM, if it doesn't
find it, it will look for ember
in bower.
let VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
let checker = new VersionChecker(this);
let ember = checker.forEmber();
if (ember.isAbove('2.10.0')) {
};
}
};