Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: Consume named exports of sibling modules
  • Loading branch information
evocateur committed Dec 8, 2020
1 parent c489810 commit 63499e3
Show file tree
Hide file tree
Showing 156 changed files with 413 additions and 413 deletions.
2 changes: 1 addition & 1 deletion commands/__mocks__/@lerna/output.js
@@ -1,7 +1,7 @@
"use strict";

const chalk = require("chalk");
const multiLineTrimRight = require("@lerna-test/multi-line-trim-right");
const { multiLineTrimRight } = require("@lerna-test/multi-line-trim-right");

// keep snapshots stable cross-platform
chalk.level = 0;
Expand Down
2 changes: 1 addition & 1 deletion commands/add/command.js
@@ -1,6 +1,6 @@
"use strict";

const filterOptions = require("@lerna/filter-options");
const { filterOptions } = require("@lerna/filter-options");

/**
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
Expand Down
4 changes: 2 additions & 2 deletions commands/add/index.js
Expand Up @@ -7,10 +7,10 @@ const path = require("path");
const pacote = require("pacote");
const semver = require("semver");

const Command = require("@lerna/command");
const { Command } = require("@lerna/command");
const npmConf = require("@lerna/npm-conf");
const bootstrap = require("@lerna/bootstrap");
const ValidationError = require("@lerna/validation-error");
const { ValidationError } = require("@lerna/validation-error");
const { getFilteredPackages } = require("@lerna/filter-options");
const getRangeToReference = require("./lib/get-range-to-reference");

Expand Down
56 changes: 28 additions & 28 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Expand Up @@ -9,23 +9,23 @@ const fs = require("fs-extra");
const path = require("path");

// mocked or stubbed modules
const rimrafDir = require("@lerna/rimraf-dir");
const npmInstall = require("@lerna/npm-install");
const runLifecycle = require("@lerna/run-lifecycle");
const createSymlink = require("@lerna/create-symlink");
const hasNpmVersion = require("@lerna/has-npm-version");
const { rimrafDir } = require("@lerna/rimraf-dir");
const { npmInstall, npmInstallDependencies } = require("@lerna/npm-install");
const { runLifecycle } = require("@lerna/run-lifecycle");
const { createSymlink } = require("@lerna/create-symlink");
const { hasNpmVersion } = require("@lerna/has-npm-version");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const normalizeRelativeDir = require("@lerna-test/normalize-relative-dir");
const updateLernaConfig = require("@lerna-test/update-lerna-config");
const { normalizeRelativeDir } = require("@lerna-test/normalize-relative-dir");
const { updateLernaConfig } = require("@lerna-test/update-lerna-config");

// file under test
const lernaBootstrap = require("@lerna-test/command-runner")(require("../command"));

// assertion helpers
const installedPackagesInDirectories = (testDir) =>
npmInstall.dependencies.mock.calls.reduce((obj, [pkg, dependencies]) => {
npmInstallDependencies.mock.calls.reduce((obj, [pkg, dependencies]) => {
const relative = normalizeRelativeDir(testDir, pkg.location);
obj[relative || "ROOT"] = dependencies;
return obj;
Expand Down Expand Up @@ -64,7 +64,7 @@ describe("BootstrapCommand", () => {
// we stub npmInstall in most tests because
// we already have enough tests of npmInstall
npmInstall.mockResolvedValue();
npmInstall.dependencies.mockResolvedValue();
npmInstallDependencies.mockResolvedValue();

// stub runLifecycle because it is a huge source
// of slowness when running tests for no good reason
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("BootstrapCommand", () => {
await lernaBootstrap(testDir)("--ignore-scripts");

expect(runLifecycle).not.toHaveBeenCalled();
expect(npmInstall.dependencies).toHaveBeenCalledWith(
expect(npmInstallDependencies).toHaveBeenCalledWith(
expect.objectContaining({
name: "package-prepare",
}),
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("BootstrapCommand", () => {
expect(removedDirectories(testDir)).toMatchSnapshot();

// root includes explicit dependencies and hoisted from leaves
expect(npmInstall.dependencies).toHaveBeenCalledWith(
expect(npmInstallDependencies).toHaveBeenCalledWith(
expect.objectContaining({
name: "basic",
}),
Expand All @@ -159,7 +159,7 @@ describe("BootstrapCommand", () => {
);

// foo@0.1.2 differs from the more common foo@^1.0.0
expect(npmInstall.dependencies).toHaveBeenLastCalledWith(
expect(npmInstallDependencies).toHaveBeenLastCalledWith(
expect.objectContaining({
name: "package-3",
}),
Expand Down Expand Up @@ -219,7 +219,7 @@ describe("BootstrapCommand", () => {
await lernaBootstrap(testDir)("--ci");

expect(hasNpmVersion).toHaveBeenLastCalledWith(">=5.7.0");
expect(npmInstall.dependencies.mock.calls[0][2]).toEqual({
expect(npmInstallDependencies.mock.calls[0][2]).toEqual({
subCommand: "ci",
registry: undefined,
npmClient: "npm",
Expand All @@ -236,7 +236,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--ci");

expect(npmInstall.dependencies.mock.calls[0][2]).toEqual({
expect(npmInstallDependencies.mock.calls[0][2]).toEqual({
registry: undefined,
npmClient: "npm",
npmClientArgs: [],
Expand All @@ -250,7 +250,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--hoist", "package-*", "--ci");

expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
subCommand: "install", // not "ci"
npmClient: "npm",
npmClientArgs: ["--no-save"],
Expand All @@ -270,7 +270,7 @@ describe("BootstrapCommand", () => {
await lernaBootstrap(testDir)();

expect(hasNpmVersion).not.toHaveBeenCalled();
expect(npmInstall.dependencies.mock.calls[0][2]).toEqual({
expect(npmInstallDependencies.mock.calls[0][2]).toEqual({
registry: undefined,
npmClient: "npm",
npmClientArgs: [],
Expand Down Expand Up @@ -350,7 +350,7 @@ describe("BootstrapCommand", () => {

expect(installedPackagesInDirectories(testDir)).toMatchSnapshot();
expect(symlinkedDirectories(testDir)).toMatchSnapshot();
expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
subCommand: "install", // not "ci"
npmClient: "npm",
npmClientArgs: ["--no-save"],
Expand All @@ -362,7 +362,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--scope", "@test/package-2", "--npm-client", "yarn", "--ci");

expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
npmClient: "yarn",
npmClientArgs: ["--pure-lockfile"],
});
Expand All @@ -373,7 +373,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)();

expect(npmInstall.dependencies).toHaveBeenCalledWith(
expect(npmInstallDependencies).toHaveBeenCalledWith(
expect.objectContaining({
name: "@test/package-2",
}),
Expand Down Expand Up @@ -450,7 +450,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--npm-client", "yarn");

expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
npmClient: "yarn",
mutex: expect.stringMatching(/^network:\d+$/),
});
Expand All @@ -461,7 +461,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--npm-client", "yarn", "--mutex", "file:/test/this/path");

expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
npmClient: "yarn",
mutex: "file:/test/this/path",
});
Expand All @@ -486,7 +486,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)();

expect(npmInstall.dependencies).not.toHaveBeenCalled();
expect(npmInstallDependencies).not.toHaveBeenCalled();
});

it("hoists appropriately", async () => {
Expand Down Expand Up @@ -531,7 +531,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)();

expect(npmInstall.dependencies).not.toHaveBeenCalled();
expect(npmInstallDependencies).not.toHaveBeenCalled();
});
});

Expand All @@ -542,7 +542,7 @@ describe("BootstrapCommand", () => {
await lernaBootstrap(testDir)();

expect(installedPackagesInDirectories(testDir)).toMatchSnapshot();
expect(npmInstall.dependencies).toHaveBeenLastCalledWith(
expect(npmInstallDependencies).toHaveBeenLastCalledWith(
expect.objectContaining({
name: "@test/package-1",
}),
Expand All @@ -563,7 +563,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--", "--no-optional", "--production");

expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
npmClientArgs: ["--no-optional", "--production"],
});
});
Expand All @@ -575,7 +575,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--", "--no-optional");

expect(npmInstall.dependencies.mock.calls[0][2]).toMatchObject({
expect(npmInstallDependencies.mock.calls[0][2]).toMatchObject({
npmClientArgs: ["--production", "--no-optional"],
});
});
Expand All @@ -588,7 +588,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)();

expect(npmInstall.dependencies).not.toHaveBeenCalled();
expect(npmInstallDependencies).not.toHaveBeenCalled();
expect(npmInstall).toHaveBeenLastCalledWith(
expect.objectContaining({ name: "root" }),
expect.objectContaining({
Expand All @@ -614,7 +614,7 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)();

expect(npmInstall.dependencies).not.toHaveBeenCalled();
expect(npmInstallDependencies).not.toHaveBeenCalled();
expect(npmInstall).toHaveBeenLastCalledWith(
expect.objectContaining({ name: "relative-file-specs" }),
expect.objectContaining({
Expand Down
2 changes: 1 addition & 1 deletion commands/bootstrap/command.js
@@ -1,6 +1,6 @@
"use strict";

const filterOptions = require("@lerna/filter-options");
const { filterOptions } = require("@lerna/filter-options");

/**
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
Expand Down
24 changes: 12 additions & 12 deletions commands/bootstrap/index.js
Expand Up @@ -8,18 +8,18 @@ const pMap = require("p-map");
const pMapSeries = require("p-map-series");
const pWaterfall = require("p-waterfall");

const Command = require("@lerna/command");
const rimrafDir = require("@lerna/rimraf-dir");
const hasNpmVersion = require("@lerna/has-npm-version");
const npmInstall = require("@lerna/npm-install");
const { Command } = require("@lerna/command");
const { rimrafDir } = require("@lerna/rimraf-dir");
const { hasNpmVersion } = require("@lerna/has-npm-version");
const { npmInstall, npmInstallDependencies } = require("@lerna/npm-install");
const { createRunner } = require("@lerna/run-lifecycle");
const runTopologically = require("@lerna/run-topologically");
const symlinkBinary = require("@lerna/symlink-binary");
const symlinkDependencies = require("@lerna/symlink-dependencies");
const ValidationError = require("@lerna/validation-error");
const { runTopologically } = require("@lerna/run-topologically");
const { symlinkBinary } = require("@lerna/symlink-binary");
const { symlinkDependencies } = require("@lerna/symlink-dependencies");
const { ValidationError } = require("@lerna/validation-error");
const { getFilteredPackages } = require("@lerna/filter-options");
const PackageGraph = require("@lerna/package-graph");
const pulseTillDone = require("@lerna/pulse-till-done");
const { PackageGraph } = require("@lerna/package-graph");
const { pulseTillDone } = require("@lerna/pulse-till-done");

const hasDependencyInstalled = require("./lib/has-dependency-installed");
const isHoistedPackage = require("./lib/is-hoisted-package");
Expand Down Expand Up @@ -478,7 +478,7 @@ class BootstrapCommand extends Command {
tracker.info("hoist", "Installing hoisted dependencies into root");
}

const promise = npmInstall.dependencies(rootPkg, depsToInstallInRoot, this.npmConfig);
const promise = npmInstallDependencies(rootPkg, depsToInstallInRoot, this.npmConfig);

return pulseTillDone(promise)
.then(() =>
Expand Down Expand Up @@ -557,7 +557,7 @@ class BootstrapCommand extends Command {
if (deps.some(({ isSatisfied }) => !isSatisfied)) {
actions.push(() => {
const dependencies = deps.map(({ dependency }) => dependency);
const promise = npmInstall.dependencies(leafNode.pkg, dependencies, leafNpmConfig);
const promise = npmInstallDependencies(leafNode.pkg, dependencies, leafNpmConfig);

return pulseTillDone(promise).then(() => {
tracker.verbose("installed leaf", leafNode.name);
Expand Down
8 changes: 4 additions & 4 deletions commands/changed/__tests__/changed-command.test.js
@@ -1,13 +1,13 @@
"use strict";

// mocked modules
const collectUpdates = require("@lerna/collect-updates");
const output = require("@lerna/output");
const { collectUpdates } = require("@lerna/collect-updates");
const { output } = require("@lerna/output");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const loggingOutput = require("@lerna-test/logging-output");
const updateLernaConfig = require("@lerna-test/update-lerna-config");
const { loggingOutput } = require("@lerna-test/logging-output");
const { updateLernaConfig } = require("@lerna-test/update-lerna-config");

// file under test
const lernaChanged = require("@lerna-test/command-runner")(require("../command"));
Expand Down
6 changes: 3 additions & 3 deletions commands/changed/index.js
@@ -1,9 +1,9 @@
"use strict";

const Command = require("@lerna/command");
const collectUpdates = require("@lerna/collect-updates");
const { Command } = require("@lerna/command");
const { collectUpdates } = require("@lerna/collect-updates");
const listable = require("@lerna/listable");
const output = require("@lerna/output");
const { output } = require("@lerna/output");

module.exports = factory;

Expand Down
4 changes: 2 additions & 2 deletions commands/clean/__tests__/clean-command.test.js
Expand Up @@ -7,12 +7,12 @@ const fs = require("fs-extra");
const path = require("path");

// mocked or stubbed modules
const rimrafDir = require("@lerna/rimraf-dir");
const { rimrafDir } = require("@lerna/rimraf-dir");
const PromptUtilities = require("@lerna/prompt");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const normalizeRelativeDir = require("@lerna-test/normalize-relative-dir");
const { normalizeRelativeDir } = require("@lerna-test/normalize-relative-dir");

// file under test
const lernaClean = require("@lerna-test/command-runner")(require("../command"));
Expand Down
2 changes: 1 addition & 1 deletion commands/clean/command.js
@@ -1,6 +1,6 @@
"use strict";

const filterOptions = require("@lerna/filter-options");
const { filterOptions } = require("@lerna/filter-options");

/**
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
Expand Down
6 changes: 3 additions & 3 deletions commands/clean/index.js
Expand Up @@ -3,11 +3,11 @@
const path = require("path");
const pMap = require("p-map");

const Command = require("@lerna/command");
const rimrafDir = require("@lerna/rimraf-dir");
const { Command } = require("@lerna/command");
const { rimrafDir } = require("@lerna/rimraf-dir");
const PromptUtilities = require("@lerna/prompt");
const { getFilteredPackages } = require("@lerna/filter-options");
const pulseTillDone = require("@lerna/pulse-till-done");
const { pulseTillDone } = require("@lerna/pulse-till-done");

module.exports = factory;

Expand Down
2 changes: 1 addition & 1 deletion commands/create/__tests__/create-command.test.js
Expand Up @@ -12,7 +12,7 @@ const pacote = require("pacote");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const gitAdd = require("@lerna-test/git-add");
const { gitAdd } = require("@lerna-test/git-add");

// file under test
const lernaCreate = require("@lerna-test/command-runner")(require("../command"));
Expand Down
4 changes: 2 additions & 2 deletions commands/create/index.js
Expand Up @@ -12,10 +12,10 @@ const npa = require("npm-package-arg");
const pReduce = require("p-reduce");
const slash = require("slash");

const Command = require("@lerna/command");
const { Command } = require("@lerna/command");
const ChildProcessUtilities = require("@lerna/child-process");
const npmConf = require("@lerna/npm-conf");
const ValidationError = require("@lerna/validation-error");
const { ValidationError } = require("@lerna/validation-error");
const builtinNpmrc = require("./lib/builtin-npmrc");
const catFile = require("./lib/cat-file");

Expand Down

0 comments on commit 63499e3

Please sign in to comment.