Skip to content

Commit

Permalink
feat(devDependencies): Checking both dependencies and dev dependencie…
Browse files Browse the repository at this point in the history
…s for fuzzy characters
  • Loading branch information
bahmutov committed Nov 18, 2015
1 parent c5f4b12 commit 42af9b7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 18 deletions.
84 changes: 71 additions & 13 deletions src/make-exact-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,88 @@ var check = require('check-more-types');

describe('make exact', function () {
var makeExact = require('./make-exact');

it('is a function', function () {
la(check.fn(makeExact));
});

it('returns false if there are no dependencies', function () {
var needSaving = makeExact({});
la(!needSaving);
});

it('returns false if empty dependencies', function () {
var needSaving = makeExact({
dependencies: {}
describe('dependencies', function () {
it('returns false if empty dependencies', function () {
var needSaving = makeExact({
dependencies: {}
});
la(!needSaving);
});

it('returns false is exact semver', function () {
var needSaving = makeExact({
dependencies: {
foo: '1.0.2',
bar: '2.0.1'
}
});
la(!needSaving);
});

it('returns true and cleans fuzzy dependencies', function () {
var pkg = {
dependencies: {
foo: '^1.0.2',
bar: '2.0.1'
}
};
var needSaving = makeExact(pkg);
la(needSaving, 'needs saving');
la(pkg.dependencies.foo === '1.0.2', 'removed fuzziness');
});

it('returns true and cleans two fuzzy dependencies', function () {
var pkg = {
dependencies: {
foo: '^1.0.2',
bar: '~2.0.1'
}
};
var needSaving = makeExact(pkg);
la(needSaving, 'needs saving');
la(pkg.dependencies.foo === '1.0.2', 'removed foo fuzziness');
la(pkg.dependencies.bar === '2.0.1', 'removed bar fuzziness');
});
la(!needSaving);
});

it('returns false is exact semver', function () {
var needSaving = makeExact({
dependencies: {
foo: '1.0.2',
bar: '2.0.1'
}
describe('dev dependencies', function () {
it('returns false if empty dev dependencies', function () {
var needSaving = makeExact({
dependencies: {},
devDependencies: {}
});
la(!needSaving);
});

it('returns false is exact semver', function () {
var needSaving = makeExact({
devDependencies: {
foo: '1.0.2',
bar: '2.0.1'
}
});
la(!needSaving);
});

it('returns true and cleans two fuzzy dependencies', function () {
var pkg = {
devDependencies: {
foo: '^1.0.2',
bar: '~2.0.1'
}
};
var needSaving = makeExact(pkg);
la(needSaving, 'needs saving');
la(pkg.devDependencies.foo === '1.0.2', 'removed foo fuzziness');
la(pkg.devDependencies.bar === '2.0.1', 'removed bar fuzziness');
});
la(!needSaving);
});
});
18 changes: 13 additions & 5 deletions src/make-exact.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var isStrictSemver = require('./is-strict-semver');
var toExact = require('./to-exact');

function makeExact(pkg) {
function makeExactDependencies(dependencies) {
var needSaving;
if (pkg.dependencies) {
Object.keys(pkg.dependencies).forEach(function (name) {
var version = pkg.dependencies[name];
if (dependencies) {
Object.keys(dependencies).forEach(function (name) {
var version = dependencies[name];
if (!isStrictSemver(version)) {
version = toExact(version);
pkg.dependencies[name] = version;
dependencies[name] = version;
needSaving = true;
}
});
Expand All @@ -17,4 +17,12 @@ function makeExact(pkg) {
return needSaving;
}

function makeExact(pkg) {
if (!pkg) {
throw new Error('Missing package object');
}
return makeExactDependencies(pkg.dependencies) ||
makeExactDependencies(pkg.devDependencies);
}

module.exports = makeExact;

0 comments on commit 42af9b7

Please sign in to comment.