Skip to content

Commit

Permalink
feat: Expose named export
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 8, 2020
1 parent 5c680c8 commit c1303f1
Show file tree
Hide file tree
Showing 66 changed files with 103 additions and 30 deletions.
1 change: 1 addition & 0 deletions commands/__mocks__/@lerna/check-working-tree.js
Expand Up @@ -5,5 +5,6 @@ const mockThrowIfReleased = jest.fn(() => Promise.resolve());
const mockThrowIfUncommitted = jest.fn(() => Promise.resolve());

module.exports = mockCheckWorkingTree;
module.exports.checkWorkingTree = mockCheckWorkingTree;
module.exports.throwIfReleased = mockThrowIfReleased;
module.exports.throwIfUncommitted = mockThrowIfUncommitted;
2 changes: 2 additions & 0 deletions commands/__mocks__/@lerna/collect-updates.js
Expand Up @@ -21,6 +21,8 @@ afterEach(() => {
});

module.exports = mockCollectUpdates;
module.exports.collectUpdates = mockCollectUpdates;
module.exports.setUpdated = setUpdated;
module.exports.collectUpdates.setUpdated = setUpdated;
module.exports.collectPackages = collectPackages;
module.exports.getPackagesForOption = getPackagesForOption;
1 change: 1 addition & 0 deletions commands/__mocks__/@lerna/gitlab-client.js
Expand Up @@ -7,3 +7,4 @@ const client = {
};

module.exports = () => client;
module.exports.createGitLabClient = () => client;
1 change: 1 addition & 0 deletions commands/__mocks__/@lerna/has-npm-version.js
Expand Up @@ -4,4 +4,5 @@ const mockHasNpmVersion = jest.fn(() => true);
const mockMakePredicate = jest.fn(() => (range) => mockHasNpmVersion(range));

module.exports = mockHasNpmVersion;
module.exports.hasNpmVersion = mockHasNpmVersion;
module.exports.makePredicate = mockMakePredicate;
3 changes: 3 additions & 0 deletions commands/__mocks__/@lerna/npm-publish.js
Expand Up @@ -20,5 +20,8 @@ afterEach(() => {
});

module.exports = mockNpmPublish;
module.exports.npmPublish = mockNpmPublish;
module.exports.order = order;
module.exports.registry = registry;
module.exports.npmPublish.order = order;
module.exports.npmPublish.registry = registry;
2 changes: 2 additions & 0 deletions commands/__mocks__/@lerna/output.js
Expand Up @@ -15,3 +15,5 @@ function logged() {

module.exports = mockOutput;
module.exports.logged = logged;
module.exports.output = mockOutput;
module.exports.output.logged = logged;
2 changes: 2 additions & 0 deletions commands/__mocks__/@lerna/pack-directory.js
Expand Up @@ -17,4 +17,6 @@ afterEach(() => {
});

module.exports = mockPackDirectory;
module.exports.packDirectory = mockPackDirectory;
module.exports.registry = registry;
module.exports.packDirectory.registry = registry;
2 changes: 2 additions & 0 deletions commands/__mocks__/@lerna/run-lifecycle.js
Expand Up @@ -15,5 +15,7 @@ function getOrderedCalls() {
}

module.exports = mockRunLifecycle;
module.exports.runLifecycle = mockRunLifecycle;
module.exports.createRunner = mockCreateRunner;
module.exports.getOrderedCalls = getOrderedCalls;
module.exports.runLifecycle.getOrderedCalls = getOrderedCalls;
1 change: 1 addition & 0 deletions core/command/index.js
Expand Up @@ -288,3 +288,4 @@ class Command {
}

module.exports = Command;
module.exports.Command = Command;
1 change: 1 addition & 0 deletions core/filter-options/index.js
Expand Up @@ -5,6 +5,7 @@ const dedent = require("dedent");
const { getFilteredPackages } = require("./lib/get-filtered-packages");

module.exports = filterOptions;
module.exports.filterOptions = filterOptions;
module.exports.getFilteredPackages = getFilteredPackages;

function filterOptions(yargs) {
Expand Down
1 change: 1 addition & 0 deletions core/global-options/index.js
Expand Up @@ -3,6 +3,7 @@
const os = require("os");

module.exports = globalOptions;
module.exports.globalOptions = globalOptions;

function globalOptions(yargs) {
// the global options applicable to _every_ command
Expand Down
1 change: 1 addition & 0 deletions core/otplease/otplease.js
Expand Up @@ -36,6 +36,7 @@ const semaphore = {
};

module.exports = otplease;
module.exports.otplease = otplease;
module.exports.getOneTimePassword = getOneTimePassword;

/**
Expand Down
1 change: 1 addition & 0 deletions core/package-graph/index.js
Expand Up @@ -299,3 +299,4 @@ class PackageGraph extends Map {
}

module.exports = PackageGraph;
module.exports.PackageGraph = PackageGraph;
1 change: 1 addition & 0 deletions core/package/index.js
Expand Up @@ -248,4 +248,5 @@ function lazy(ref, dir = ".") {
}

module.exports = Package;
module.exports.Package = Package;
module.exports.lazy = lazy;
1 change: 1 addition & 0 deletions core/project/index.js
Expand Up @@ -206,5 +206,6 @@ Project.PACKAGE_GLOB = "packages/*";
Project.LICENSE_GLOB = "LICEN{S,C}E{,.*}";

module.exports = Project;
module.exports.Project = Project;
module.exports.getPackages = (cwd) => new Project(cwd).getPackages();
module.exports.getPackagesSync = (cwd) => new Project(cwd).getPackagesSync();
1 change: 1 addition & 0 deletions core/validation-error/validation-error.js
Expand Up @@ -13,3 +13,4 @@ class ValidationError extends Error {
}

module.exports = ValidationError;
module.exports.ValidationError = ValidationError;
1 change: 1 addition & 0 deletions helpers/calls-back/index.js
@@ -1,6 +1,7 @@
"use strict";

module.exports = callsBack;
module.exports.callsBack = callsBack;

// for mocking the behaviour of methods that accept a callback
function callsBack(err, val) {
Expand Down
5 changes: 3 additions & 2 deletions helpers/cli-runner/index.js
Expand Up @@ -5,9 +5,10 @@ const execa = require("execa");
// eslint-disable-next-line node/no-unpublished-require
const LERNA_BIN = require.resolve("../../core/lerna/cli");

module.exports = runner;
module.exports = cliRunner;
module.exports.cliRunner = cliRunner;

function runner(cwd, env) {
function cliRunner(cwd, env) {
const opts = {
cwd,
env: Object.assign(
Expand Down
1 change: 1 addition & 0 deletions helpers/commit-change-to-package/index.js
Expand Up @@ -7,6 +7,7 @@ const gitAdd = require("@lerna-test/git-add");
const gitCommit = require("@lerna-test/git-commit");

module.exports = commitChangeToPackage;
module.exports.commitChangeToPackage = commitChangeToPackage;

function commitChangeToPackage(cwd, packageName, commitMsg, data) {
const packageJSONPath = path.join(cwd, "packages", packageName, "package.json");
Expand Down
1 change: 1 addition & 0 deletions helpers/copy-fixture/index.js
Expand Up @@ -4,6 +4,7 @@ const findFixture = require("@lerna-test/find-fixture");
const fs = require("fs-extra");

module.exports = copyFixture;
module.exports.copyFixture = copyFixture;

function copyFixture(targetDir, fixtureName, cwd) {
return findFixture(cwd, fixtureName).then((fp) => fs.copy(fp, targetDir));
Expand Down
1 change: 1 addition & 0 deletions helpers/find-fixture/index.js
Expand Up @@ -4,6 +4,7 @@ const findUp = require("find-up");
const path = require("path");

module.exports = findFixture;
module.exports.findFixture = findFixture;

function findFixture(cwd, fixtureName) {
return findUp(path.join("__fixtures__", fixtureName), { cwd, type: "directory" }).then((fixturePath) => {
Expand Down
1 change: 1 addition & 0 deletions helpers/get-commit-message/index.js
Expand Up @@ -3,6 +3,7 @@
const execa = require("execa");

module.exports = getCommitMessage;
module.exports.getCommitMessage = getCommitMessage;

function getCommitMessage(cwd, format = "%B") {
return execa("git", ["log", "-1", `--pretty=format:${format}`], { cwd }).then((result) => result.stdout);
Expand Down
1 change: 1 addition & 0 deletions helpers/git-add/index.js
Expand Up @@ -3,6 +3,7 @@
const execa = require("execa");

module.exports = gitAdd;
module.exports.gitAdd = gitAdd;

function gitAdd(cwd, ...files) {
return execa("git", ["add", ...files], { cwd });
Expand Down
1 change: 1 addition & 0 deletions helpers/git-checkout/index.js
Expand Up @@ -3,6 +3,7 @@
const execa = require("execa");

module.exports = gitCheckout;
module.exports.gitCheckout = gitCheckout;

function gitCheckout(cwd, args) {
return execa("git", ["checkout", ...args], { cwd });
Expand Down
1 change: 1 addition & 0 deletions helpers/git-commit/index.js
Expand Up @@ -5,6 +5,7 @@ const execa = require("execa");
const tempWrite = require("temp-write");

module.exports = gitCommit;
module.exports.gitCommit = gitCommit;

function gitCommit(cwd, message) {
if (message.indexOf(os.EOL) > -1) {
Expand Down
1 change: 1 addition & 0 deletions helpers/git-init/index.js
Expand Up @@ -7,6 +7,7 @@ const execa = require("execa");
const TEMPLATE = path.resolve(__dirname, "template");

module.exports = gitInit;
module.exports.gitInit = gitInit;

function gitInit(cwd, ...args) {
return execa("git", ["init", "--template", TEMPLATE, ...args], { cwd }).then(() =>
Expand Down
1 change: 1 addition & 0 deletions helpers/git-merge/index.js
Expand Up @@ -3,6 +3,7 @@
const execa = require("execa");

module.exports = gitMerge;
module.exports.gitMerge = gitMerge;

function gitMerge(cwd, args) {
return execa("git", ["merge", ...args], { cwd });
Expand Down
1 change: 1 addition & 0 deletions helpers/git-status/index.js
Expand Up @@ -3,6 +3,7 @@
const cp = require("child_process");

module.exports = gitStatus;
module.exports.gitStatus = gitStatus;

function gitStatus(cwd) {
return cp.spawnSync("git", ["status", "--porcelain"], { cwd, encoding: "utf8" });
Expand Down
1 change: 1 addition & 0 deletions helpers/git-tag/index.js
Expand Up @@ -3,6 +3,7 @@
const execa = require("execa");

module.exports = gitTag;
module.exports.gitTag = gitTag;

function gitTag(cwd, tagName) {
return execa("git", ["tag", tagName, "-m", tagName], { cwd });
Expand Down
5 changes: 3 additions & 2 deletions helpers/load-manifests/index.js
Expand Up @@ -3,9 +3,10 @@
const globby = require("globby");
const loadJsonFile = require("load-json-file");

module.exports = loadPkgManifests;
module.exports = loadManifests;
module.exports.loadManifests = loadManifests;

function loadPkgManifests(cwd) {
function loadManifests(cwd) {
return globby(
[
// all child packages, at any level
Expand Down
1 change: 1 addition & 0 deletions helpers/logging-output/index.js
Expand Up @@ -4,6 +4,7 @@ const log = require("npmlog");
const multiLineTrimRight = require("@lerna-test/multi-line-trim-right");

module.exports = loggingOutput;
module.exports.loggingOutput = loggingOutput;

// clear logs between tests
afterEach(() => {
Expand Down
3 changes: 2 additions & 1 deletion helpers/multi-line-trim-right/index.js
Expand Up @@ -3,8 +3,9 @@
const normalizeNewline = require("normalize-newline");

module.exports = multiLineTrimRight;
module.exports.multiLineTrimRight = multiLineTrimRight;

// const multiLineTrimRight = require("@lerna-test/multi-line-trim-right");
// const { multiLineTrimRight } = require("@lerna-test/multi-line-trim-right");
function multiLineTrimRight(str) {
return normalizeNewline(str)
.split("\n")
Expand Down
1 change: 1 addition & 0 deletions helpers/normalize-relative-dir/index.js
Expand Up @@ -4,6 +4,7 @@ const path = require("path");
const normalizePath = require("normalize-path");

module.exports = normalizeRelativeDir;
module.exports.normalizeRelativeDir = normalizeRelativeDir;

function normalizeRelativeDir(testDir, filePath) {
return normalizePath(path.relative(testDir, filePath));
Expand Down
1 change: 1 addition & 0 deletions helpers/show-commit/index.js
Expand Up @@ -4,6 +4,7 @@ const execa = require("execa");
const gitSHA = require("@lerna-test/serialize-git-sha");

module.exports = showCommit;
module.exports.showCommit = showCommit;

function showCommit(cwd, ...args) {
return execa(
Expand Down
1 change: 1 addition & 0 deletions helpers/update-lerna-config/index.js
Expand Up @@ -4,6 +4,7 @@
const Project = require("@lerna/project");

module.exports = updateLernaConfig;
module.exports.updateLernaConfig = updateLernaConfig;

/**
* Update lerna config inside a test case.
Expand Down
1 change: 1 addition & 0 deletions utils/check-working-tree/lib/check-working-tree.js
Expand Up @@ -5,6 +5,7 @@ const ValidationError = require("@lerna/validation-error");
const collectUncommitted = require("@lerna/collect-uncommitted");

module.exports = checkWorkingTree;
module.exports.checkWorkingTree = checkWorkingTree;
module.exports.mkThrowIfUncommitted = mkThrowIfUncommitted;
module.exports.throwIfReleased = throwIfReleased;
module.exports.throwIfUncommitted = mkThrowIfUncommitted();
Expand Down
10 changes: 5 additions & 5 deletions utils/collect-uncommitted/__tests__/collect-uncommitted.test.js
Expand Up @@ -10,7 +10,7 @@ const gitAdd = require("@lerna-test/git-add");
const initFixture = require("@lerna-test/init-fixture")(__dirname);

// file under test
const collectUncommitted = require("../lib/collect-uncommitted");
const { collectUncommitted, collectUncommittedSync } = require("../lib/collect-uncommitted");

// primary assertion setup
const GREEN_A = chalk.green("A");
Expand Down Expand Up @@ -114,10 +114,10 @@ describe("collectUncommitted()", () => {
});
});

describe("collectUncommitted.sync()", () => {
describe("collectUncommittedSync()", () => {
it("resolves empty array on clean repo", async () => {
const cwd = await initFixture("normal");
const result = collectUncommitted.sync({ cwd });
const result = collectUncommittedSync({ cwd });

expect(result).toEqual([]);
});
Expand All @@ -127,7 +127,7 @@ describe("collectUncommitted.sync()", () => {

await setupChanges(cwd);

const result = collectUncommitted.sync({ cwd });
const result = collectUncommittedSync({ cwd });

expect(result).toEqual(colorizedAry);
});
Expand All @@ -136,7 +136,7 @@ describe("collectUncommitted.sync()", () => {
// re-uses previous cwd
const log = { silly: jest.fn() };

const result = collectUncommitted.sync({ log });
const result = collectUncommittedSync({ log });

expect(log.silly).toHaveBeenCalled();
expect(result).toEqual(colorizedAry);
Expand Down
6 changes: 4 additions & 2 deletions utils/collect-uncommitted/lib/collect-uncommitted.js
Expand Up @@ -5,7 +5,9 @@ const npmlog = require("npmlog");
const { exec, execSync } = require("@lerna/child-process");

module.exports = collectUncommitted;
module.exports.sync = sync;
module.exports.collectUncommitted = collectUncommitted;
module.exports.sync = collectUncommittedSync;
module.exports.collectUncommittedSync = collectUncommittedSync;

/**
* @typedef {object} UncommittedConfig
Expand Down Expand Up @@ -46,7 +48,7 @@ function collectUncommitted({ cwd, log = npmlog }) {
* @param {UncommittedConfig} options
* @returns {string[]} A list of uncommitted files
*/
function sync({ cwd, log = npmlog }) {
function collectUncommittedSync({ cwd, log = npmlog }) {
log.silly("collect-uncommitted", "git status --porcelain (sync)");

const stdout = execSync("git", ["status", "--porcelain"], { cwd });
Expand Down
1 change: 1 addition & 0 deletions utils/collect-updates/collect-updates.js
Expand Up @@ -9,6 +9,7 @@ const getPackagesForOption = require("./lib/get-packages-for-option");
const makeDiffPredicate = require("./lib/make-diff-predicate");

module.exports = collectUpdates;
module.exports.collectUpdates = collectUpdates;
module.exports.collectPackages = collectPackages;
module.exports.getPackagesForOption = getPackagesForOption;

Expand Down
1 change: 1 addition & 0 deletions utils/create-symlink/create-symlink.js
Expand Up @@ -6,6 +6,7 @@ const log = require("npmlog");
const path = require("path");

module.exports = createSymlink;
module.exports.createSymlink = createSymlink;

function createSymlink(src, dest, type) {
log.silly("createSymlink", [src, dest, type]);
Expand Down
10 changes: 5 additions & 5 deletions utils/describe-ref/__tests__/describe-ref.test.js
Expand Up @@ -3,7 +3,7 @@
jest.mock("@lerna/child-process");

const childProcess = require("@lerna/child-process");
const describeRef = require("../lib/describe-ref");
const { describeRef, describeRefSync } = require("../lib/describe-ref");

const DEFAULT_ARGS = ["describe", "--always", "--long", "--dirty", "--first-parent"];

Expand Down Expand Up @@ -53,9 +53,9 @@ describe("describeRef()", () => {
});
});

describe("describeRef.sync()", () => {
describe("describeRefSync()", () => {
it("returns parsed metadata", () => {
const result = describeRef.sync();
const result = describeRefSync();

expect(childProcess.execSync).toHaveBeenLastCalledWith("git", DEFAULT_ARGS, {});
expect(result).toEqual({
Expand All @@ -69,14 +69,14 @@ describe("describeRef.sync()", () => {

it("accepts options.cwd", () => {
const options = { cwd: "foo" };
describeRef.sync(options);
describeRefSync(options);

expect(childProcess.execSync).toHaveBeenLastCalledWith("git", DEFAULT_ARGS, options);
});

it("accepts options.match", () => {
const options = { match: "v*.*.*" };
describeRef.sync(options);
describeRefSync(options);

expect(childProcess.execSync).toHaveBeenLastCalledWith(
"git",
Expand Down

0 comments on commit c1303f1

Please sign in to comment.