Skip to content

Commit

Permalink
feat(has-npm-version): Remove unused makePredicate() export
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The makePredicate() export has been removed, memoization is now the responsibility of the caller.
  • Loading branch information
evocateur committed Dec 8, 2020
1 parent e2f1ec3 commit 56cba2f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 20 deletions.
2 changes: 0 additions & 2 deletions commands/__mocks__/@lerna/has-npm-version.js
@@ -1,7 +1,5 @@
"use strict";

const mockHasNpmVersion = jest.fn(() => true);
const mockMakePredicate = jest.fn(() => (range) => mockHasNpmVersion(range));

module.exports.hasNpmVersion = mockHasNpmVersion;
module.exports.makePredicate = mockMakePredicate;
12 changes: 1 addition & 11 deletions utils/has-npm-version/__tests__/has-npm-version.test.js
Expand Up @@ -3,7 +3,7 @@
jest.mock("@lerna/child-process");

const childProcess = require("@lerna/child-process");
const { hasNpmVersion, makePredicate } = require("../lib/has-npm-version");
const { hasNpmVersion } = require("../lib/has-npm-version");

childProcess.execSync.mockReturnValue("5.6.0");

Expand All @@ -13,13 +13,3 @@ test("hasNpmVersion() returns boolean if range is satisfied by npm --version", (

expect(childProcess.execSync).toHaveBeenLastCalledWith("npm", ["--version"]);
});

test("makePredicate() returns a predicate with cached version", () => {
const predicate = makePredicate();

childProcess.execSync.mockReturnValue("3.10.10");

// the predicate has cached the initial version, not the new version
expect(predicate(">=5")).toBe(true);
expect(hasNpmVersion(">=5")).toBe(false);
});
7 changes: 0 additions & 7 deletions utils/has-npm-version/lib/has-npm-version.js
Expand Up @@ -4,18 +4,11 @@ const semver = require("semver");
const childProcess = require("@lerna/child-process");

module.exports.hasNpmVersion = hasNpmVersion;
module.exports.makePredicate = makePredicate;

function hasNpmVersion(range) {
return rangeSatisfies(getNpmVersion(), range);
}

function makePredicate() {
const npmVersion = getNpmVersion();

return (range) => rangeSatisfies(npmVersion, range);
}

function rangeSatisfies(npmVersion, range) {
return Boolean(semver.satisfies(npmVersion, range));
}
Expand Down

0 comments on commit 56cba2f

Please sign in to comment.