Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cli-version-checker

Package Overview
Dependencies
Maintainers
5
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-version-checker - npm Package Compare versions

Comparing version 5.0.2 to 5.1.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## v5.1.0 (2020-05-11)
* [#206](https://github.com/ember-cli/ember-cli-version-checker/pull/206) Add ProjectWideDependencyChecker `check` API([@stefanpenner](https://github.com/stefanpenner))
## v5.0.2 (2020-03-23)

@@ -2,0 +7,0 @@

21

package.json
{
"name": "ember-cli-version-checker",
"version": "5.0.2",
"version": "5.1.0",
"description": "Determine if your addon is being used by a minimum version of Ember CLI.",

@@ -25,4 +25,4 @@ "homepage": "https://github.com/ember-cli/ember-cli-version-checker",

"changelog": "lerna-changelog",
"test": "mocha tests",
"test:debug": "mocha debug tests"
"test": "mocha tests/*-tests.js",
"test:debug": "mocha debug tests/*-tests.js"
},

@@ -35,15 +35,16 @@ "prettier": {

"resolve-package-path": "^2.0.0",
"semver": "^7.1.3",
"semver": "^7.3.2",
"silent-error": "^1.1.1"
},
"devDependencies": {
"broccoli-test-helper": "^2.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"fixturify": "^2.1.0",
"fixturify-project": "^2.1.0",
"lerna-changelog": "^1.0.1",
"mocha": "^7.1.1",
"mocha": "^7.1.2",
"mocha-eslint": "^6.0.0",
"prettier": "^1.19.1",
"release-it": "^13.1.1",
"release-it-lerna-changelog": "^2.1.0"
"release-it": "^13.5.8",
"release-it-lerna-changelog": "^2.3.0"
},

@@ -50,0 +51,0 @@ "engines": {

@@ -239,3 +239,3 @@ # Ember CLI Version Checker

An iterator which gives acccess to all addon instances
An iterator which gives access to all addon instances

@@ -253,3 +253,3 @@ ```js

for (let { name, root } = checker.allAddons()) {
// access to the add-on, in this case root + name
// access to the addon, in this case name and root
}

@@ -260,2 +260,62 @@ }

### check
A utility to verify that addons are installed at appropriate versions. `npm`
and `yarn` resolve conflicting transitive dependency requirements by installing
multiple versions. They do not include a mechanism for packages to declare
that a dependency must be unique. This is, however, a practical constraint
when building Ember applications (for example, we would not want to build an
application that shipped two versions of Ember Data). [Related discussion on npm](https://github.com/npm/rfcs/pull/23)
Every addon in the ember ecosystem implicitly depends on `ember-source`, and
most likely a specific version range. If that dependency is specified as a
`package.json` dependency, a mismatch between application and addon would
result in duplicating `ember-source`. Instead of failing the build, we would
build an application with an unknown version of `ember-source`, subverting the
point of specifying dependency version ranges in the first place! The `check`
API provides a mechanism to avoid this and fail fast in the build step, instead
of building an invalid application with harder to debug runtime errors.
For example, as of today `ember-data` supports `ember-source` `>= 3.4.8`, if it
where to use this addon, it could specify this constraint and provide good
error messages to users.
```javascript
const VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
included() {
this._super.included.apply(this, arguments);
const checker = VersionChecker.forProject(this.project);
const check = checker.check({
'ember-source': '>= 3.4.8'
});
// if it would like to simply assert
check.assert('[awesome-addon] dependency check failed');
// will throw an error message similar to the following if the check was not satisfied:
// [awesome-addon] dependency check failed:
// - 'ember-source' expected version [>= 3.4.8] but got version: [2.0.0]
// if the requirements are more advanced, we can inspect the resulting check.
if (!check.isSatisfied) {
const altCheck = checker.check({
'magical-polyfil': '>= 1.0.0',
'ember-source': '>= 3.0.0'
})
check.assert('[awesome-addon] dependency check failed:');
// will throw error message similar to the following if the check was not satisfied:
// [awesome-addon] dependency check failed:
// - 'magical-polyfil' expected version [>= 1.0.0] but got version: [0.0.1]
// - 'ember-source' expected version [>= 3.0.0] but got version: [2.0.-]
}
}
};
```
## Note

@@ -262,0 +322,0 @@

@@ -6,4 +6,5 @@ 'use strict';

} = require('./utils/single-implementation');
const semver = require('semver');
const SilentError = require('silent-error');
const { EOL } = require('os');
/* global Set */

@@ -25,3 +26,3 @@

throw new TypeError(
`[ember-cli-version-checker]'s forProject must be provided an project instance whos addons have been initialized. This is typically outside the addon's init`
`[ember-cli-version-checker]'s forProject must be provided an project instance who's addons have been initialized. This is typically outside the addon's init`
);

@@ -53,2 +54,18 @@ }

filterAddonsByNames(names) {
const result = Object.create(null);
for (let name of names) {
result[name] = [];
}
for (let addon of this.allAddons()) {
const addonResult = result[addon.name];
if (addonResult !== undefined) {
addonResult.push(addon);
}
}
return result;
}
assertSingleImplementation(name, customMessage) {

@@ -83,2 +100,73 @@ const uniqueImplementations = new Set();

}
check(constraints) {
const names = Object.keys(constraints);
const addons = this.filterAddonsByNames(names);
const node_modules = Object.create(null);
for (let name in addons) {
const found = addons[name];
const versions = found.map(addon => addon.pkg.version);
const constraint = constraints[name];
const missing = versions.length === 0;
const isSatisfied =
!missing &&
versions.every(version => semver.satisfies(version, constraint));
let message;
if (isSatisfied) {
message = '';
} else if (missing) {
message = `'${name}' was not found, expected version: [${constraint}]`;
} else {
message = `'${name}' expected version: [${constraint}] but got version${
versions.length > 1 ? 's' : ''
}: [${versions.join(', ')}]`;
}
node_modules[name] = {
versions,
isSatisfied,
message,
};
}
return new Check(node_modules);
}
};
class Check {
constructor(node_modules) {
this.node_modules = node_modules;
Object.freeze(this);
}
get isSatisfied() {
return Object.values(this.node_modules).every(
node_module => node_module.isSatisfied
);
}
get message() {
let result = '';
for (const name in this.node_modules) {
const { message } = this.node_modules[name];
if (message !== '') {
result += ` - ${message}${EOL}`;
}
}
return result;
}
assert(description = 'Checker Assertion Failed') {
if (this.isSatisfied) {
return;
}
throw new Error(
`[Ember-cli-version-checker] ${description}\n${this.message}`
);
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc