Skip to content

Commit 4acff59

Browse files
committed
refactor: Synchronize import ChildProcessUtilities -> childProcess
1 parent a02e12e commit 4acff59

File tree

18 files changed

+104
-108
lines changed

18 files changed

+104
-108
lines changed

Diff for: commands/create/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const pReduce = require("p-reduce");
1313
const slash = require("slash");
1414

1515
const { Command } = require("@lerna/command");
16-
const ChildProcessUtilities = require("@lerna/child-process");
16+
const childProcess = require("@lerna/child-process");
1717
const npmConf = require("@lerna/npm-conf");
1818
const { ValidationError } = require("@lerna/validation-error");
1919
const { builtinNpmrc } = require("./lib/builtin-npmrc");
@@ -178,7 +178,7 @@ class CreateCommand extends Command {
178178
}
179179

180180
gitConfig(prop) {
181-
return ChildProcessUtilities.execSync("git", ["config", "--get", prop], this.execOpts);
181+
return childProcess.execSync("git", ["config", "--get", prop], this.execOpts);
182182
}
183183

184184
collectExternalVersions() {
@@ -358,7 +358,7 @@ class CreateCommand extends Command {
358358

359359
setRepository() {
360360
try {
361-
const url = ChildProcessUtilities.execSync("git", ["remote", "get-url", "origin"], this.execOpts);
361+
const url = childProcess.execSync("git", ["remote", "get-url", "origin"], this.execOpts);
362362

363363
this.conf.set("repository", url);
364364
} catch (err) {

Diff for: commands/diff/__tests__/diff-command.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require("path");
66
const { getPackages } = require("@lerna/project");
77

88
// mocked modules
9-
const ChildProcessUtilities = require("@lerna/child-process");
9+
const childProcess = require("@lerna/child-process");
1010

1111
// helpers
1212
const initFixture = require("@lerna-test/init-fixture")(__dirname);
@@ -23,7 +23,7 @@ expect.addSnapshotSerializer(require("@lerna-test/serialize-git-sha"));
2323

2424
describe("DiffCommand", () => {
2525
// overwrite spawn so we get piped stdout, not inherited
26-
ChildProcessUtilities.spawn = jest.fn((...args) => execa(...args));
26+
childProcess.spawn = jest.fn((...args) => execa(...args));
2727

2828
it("should diff packages from the first commit", async () => {
2929
const cwd = await initFixture("basic");
@@ -102,7 +102,7 @@ describe("DiffCommand", () => {
102102
it("should error when git diff exits non-zero", async () => {
103103
const cwd = await initFixture("basic");
104104

105-
ChildProcessUtilities.spawn.mockImplementationOnce(() => {
105+
childProcess.spawn.mockImplementationOnce(() => {
106106
const nonZero = new Error("An actual non-zero, not git diff pager SIGPIPE");
107107
nonZero.exitCode = 1;
108108

Diff for: commands/diff/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const ChildProcessUtilities = require("@lerna/child-process");
3+
const childProcess = require("@lerna/child-process");
44
const { Command } = require("@lerna/command");
55
const { ValidationError } = require("@lerna/validation-error");
66
const { getLastCommit } = require("./lib/get-last-commit");
@@ -49,7 +49,7 @@ class DiffCommand extends Command {
4949
}
5050

5151
execute() {
52-
return ChildProcessUtilities.spawn("git", this.args, this.execOpts).catch((err) => {
52+
return childProcess.spawn("git", this.args, this.execOpts).catch((err) => {
5353
if (err.exitCode) {
5454
// quitting the diff viewer is not an error
5555
throw err;

Diff for: commands/exec/__tests__/exec-command.test.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fs = require("fs-extra");
55
const globby = require("globby");
66

77
// mocked modules
8-
const ChildProcessUtilities = require("@lerna/child-process");
8+
const childProcess = require("@lerna/child-process");
99

1010
// helpers
1111
const initFixture = require("@lerna-test/init-fixture")(__dirname);
@@ -16,20 +16,19 @@ const { normalizeRelativeDir } = require("@lerna-test/normalize-relative-dir");
1616
const lernaExec = require("@lerna-test/command-runner")(require("../command"));
1717

1818
// assertion helpers
19-
const calledInPackages = () =>
20-
ChildProcessUtilities.spawn.mock.calls.map(([, , opts]) => path.basename(opts.cwd));
19+
const calledInPackages = () => childProcess.spawn.mock.calls.map(([, , opts]) => path.basename(opts.cwd));
2120

2221
const execInPackagesStreaming = (testDir) =>
23-
ChildProcessUtilities.spawnStreaming.mock.calls.reduce((arr, [command, params, opts, prefix]) => {
22+
childProcess.spawnStreaming.mock.calls.reduce((arr, [command, params, opts, prefix]) => {
2423
const dir = normalizeRelativeDir(testDir, opts.cwd);
2524
arr.push([dir, command, `(prefix: ${prefix})`].concat(params).join(" "));
2625
return arr;
2726
}, []);
2827

2928
describe("ExecCommand", () => {
3029
// TODO: it's very suspicious that mockResolvedValue() doesn't work here
31-
ChildProcessUtilities.spawn = jest.fn(() => Promise.resolve({ exitCode: 0 }));
32-
ChildProcessUtilities.spawnStreaming = jest.fn(() => Promise.resolve({ exitCode: 0 }));
30+
childProcess.spawn = jest.fn(() => Promise.resolve({ exitCode: 0 }));
31+
childProcess.spawnStreaming = jest.fn(() => Promise.resolve({ exitCode: 0 }));
3332

3433
afterEach(() => {
3534
process.exitCode = undefined;
@@ -50,7 +49,7 @@ describe("ExecCommand", () => {
5049
});
5150

5251
it("rejects with execution error", async () => {
53-
ChildProcessUtilities.spawn.mockImplementationOnce((cmd, args) => {
52+
childProcess.spawn.mockImplementationOnce((cmd, args) => {
5453
const boom = new Error("execution error");
5554

5655
boom.failed = true;
@@ -72,7 +71,7 @@ describe("ExecCommand", () => {
7271
});
7372

7473
it("should ignore execution errors with --no-bail", async () => {
75-
ChildProcessUtilities.spawn.mockImplementationOnce((cmd, args, { pkg }) => {
74+
childProcess.spawn.mockImplementationOnce((cmd, args, { pkg }) => {
7675
const boom = new Error(pkg.name);
7776

7877
boom.failed = true;
@@ -88,8 +87,8 @@ describe("ExecCommand", () => {
8887
// command doesn't throw, but it _does_ set exitCode
8988
expect(process.exitCode).toBe(456);
9089

91-
expect(ChildProcessUtilities.spawn).toHaveBeenCalledTimes(2);
92-
expect(ChildProcessUtilities.spawn).toHaveBeenLastCalledWith(
90+
expect(childProcess.spawn).toHaveBeenCalledTimes(2);
91+
expect(childProcess.spawn).toHaveBeenLastCalledWith(
9392
"boom",
9493
["--shaka", "--lakka"],
9594
expect.objectContaining({
@@ -101,8 +100,8 @@ describe("ExecCommand", () => {
101100
it("should filter packages with `ignore`", async () => {
102101
await lernaExec(testDir)("ls", "--ignore", "package-1");
103102

104-
expect(ChildProcessUtilities.spawn).toHaveBeenCalledTimes(1);
105-
expect(ChildProcessUtilities.spawn).toHaveBeenLastCalledWith("ls", [], {
103+
expect(childProcess.spawn).toHaveBeenCalledTimes(1);
104+
expect(childProcess.spawn).toHaveBeenLastCalledWith("ls", [], {
106105
cwd: path.join(testDir, "packages/package-2"),
107106
pkg: expect.objectContaining({
108107
name: "package-2",
@@ -120,15 +119,15 @@ describe("ExecCommand", () => {
120119
it("should run a command", async () => {
121120
await lernaExec(testDir)("ls");
122121

123-
expect(ChildProcessUtilities.spawn).toHaveBeenCalledTimes(2);
122+
expect(childProcess.spawn).toHaveBeenCalledTimes(2);
124123
expect(calledInPackages()).toEqual(["package-1", "package-2"]);
125124
});
126125

127126
it("should run a command with parameters", async () => {
128127
await lernaExec(testDir)("ls", "--", "-la");
129128

130-
expect(ChildProcessUtilities.spawn).toHaveBeenCalledTimes(2);
131-
expect(ChildProcessUtilities.spawn).toHaveBeenLastCalledWith("ls", ["-la"], expect.any(Object));
129+
expect(childProcess.spawn).toHaveBeenCalledTimes(2);
130+
expect(childProcess.spawn).toHaveBeenLastCalledWith("ls", ["-la"], expect.any(Object));
132131
});
133132

134133
it("runs a command for a given scope", async () => {

Diff for: commands/exec/index.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const pMap = require("p-map");
44

5-
const ChildProcessUtilities = require("@lerna/child-process");
5+
const childProcess = require("@lerna/child-process");
66
const { Command } = require("@lerna/command");
77
const { Profiler } = require("@lerna/profiler");
88
const { runTopologically } = require("@lerna/run-topologically");
@@ -164,16 +164,11 @@ class ExecCommand extends Command {
164164
}
165165

166166
runCommandInPackageStreaming(pkg) {
167-
return ChildProcessUtilities.spawnStreaming(
168-
this.command,
169-
this.args,
170-
this.getOpts(pkg),
171-
this.prefix && pkg.name
172-
);
167+
return childProcess.spawnStreaming(this.command, this.args, this.getOpts(pkg), this.prefix && pkg.name);
173168
}
174169

175170
runCommandInPackageCapturing(pkg) {
176-
return ChildProcessUtilities.spawn(this.command, this.args, this.getOpts(pkg));
171+
return childProcess.spawn(this.command, this.args, this.getOpts(pkg));
177172
}
178173
}
179174

Diff for: commands/import/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fs = require("fs-extra");
55
const path = require("path");
66
const pMapSeries = require("p-map-series");
77

8-
const ChildProcessUtilities = require("@lerna/child-process");
8+
const childProcess = require("@lerna/child-process");
99
const { Command } = require("@lerna/command");
1010
const { promptConfirmation } = require("@lerna/prompt");
1111
const { ValidationError } = require("@lerna/validation-error");
@@ -138,11 +138,11 @@ class ImportCommand extends Command {
138138
}
139139

140140
execSync(cmd, args) {
141-
return ChildProcessUtilities.execSync(cmd, args, this.execOpts);
141+
return childProcess.execSync(cmd, args, this.execOpts);
142142
}
143143

144144
externalExecSync(cmd, args) {
145-
return ChildProcessUtilities.execSync(cmd, args, this.externalExecOpts);
145+
return childProcess.execSync(cmd, args, this.externalExecOpts);
146146
}
147147

148148
createPatchForCommit(sha) {
@@ -226,7 +226,7 @@ class ImportCommand extends Command {
226226
//
227227
// Fall back to three-way merge, which can help with duplicate commits
228228
// due to merge history.
229-
const proc = ChildProcessUtilities.exec("git", procArgs, this.execOpts);
229+
const proc = childProcess.exec("git", procArgs, this.execOpts);
230230

231231
proc.stdin.end(patch);
232232

@@ -241,7 +241,7 @@ class ImportCommand extends Command {
241241
tracker.completeWork(1);
242242

243243
// Automatically skip empty commits
244-
return ChildProcessUtilities.exec("git", ["am", "--skip"], this.execOpts);
244+
return childProcess.exec("git", ["am", "--skip"], this.execOpts);
245245
}
246246

247247
err.sha = sha;

Diff for: commands/version/__tests__/git-commit.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,43 @@ jest.mock("temp-write");
44
jest.mock("@lerna/child-process");
55

66
const { EOL } = require("os");
7-
const { sync: mockWrite } = require("temp-write");
8-
const { exec: mockExec } = require("@lerna/child-process");
7+
const tempWrite = require("temp-write");
8+
const childProcess = require("@lerna/child-process");
99
const { gitCommit } = require("../lib/git-commit");
1010

1111
describe("git commit", () => {
12-
mockExec.mockResolvedValue();
13-
mockWrite.mockReturnValue("temp-file-path");
12+
childProcess.exec.mockResolvedValue();
13+
tempWrite.sync.mockReturnValue("temp-file-path");
1414

1515
test("--message", async () => {
1616
const opts = { cwd: "message" };
1717
await gitCommit("subject", {}, opts);
18-
expect(mockExec).toHaveBeenLastCalledWith("git", ["commit", "-m", "subject"], opts);
18+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "-m", "subject"], opts);
1919
});
2020

2121
test("--message <multiline>", async () => {
2222
const message = `subject${EOL}${EOL}body`;
2323
const opts = { cwd: "multi-line" };
2424
await gitCommit(message, {}, opts);
25-
expect(mockWrite).toHaveBeenLastCalledWith(message, "lerna-commit.txt");
26-
expect(mockExec).toHaveBeenLastCalledWith("git", ["commit", "-F", "temp-file-path"], opts);
25+
expect(tempWrite.sync).toHaveBeenLastCalledWith(message, "lerna-commit.txt");
26+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "-F", "temp-file-path"], opts);
2727
});
2828

2929
test("--amend", async () => {
3030
const opts = { cwd: "no-edit" };
3131
await gitCommit("whoops", { amend: true }, opts);
32-
expect(mockExec).toHaveBeenLastCalledWith("git", ["commit", "--amend", "--no-edit"], opts);
32+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--amend", "--no-edit"], opts);
3333
});
3434

3535
test("--no-commit-hooks", async () => {
3636
const opts = { cwd: "no-verify" };
3737
await gitCommit("yolo", { commitHooks: false }, opts);
38-
expect(mockExec).toHaveBeenLastCalledWith("git", ["commit", "--no-verify", "-m", "yolo"], opts);
38+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--no-verify", "-m", "yolo"], opts);
3939
});
4040

4141
test("--sign-git-commit", async () => {
4242
const opts = { cwd: "signed" };
4343
await gitCommit("nice", { signGitCommit: true }, opts);
44-
expect(mockExec).toHaveBeenLastCalledWith("git", ["commit", "--gpg-sign", "-m", "nice"], opts);
44+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--gpg-sign", "-m", "nice"], opts);
4545
});
4646
});

Diff for: commands/version/__tests__/git-tag.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
jest.mock("@lerna/child-process");
44

5-
const { exec: mockExec } = require("@lerna/child-process");
5+
const childProcess = require("@lerna/child-process");
66
const { gitTag } = require("../lib/git-tag");
77

88
describe("gitTag", () => {
9-
mockExec.mockResolvedValue();
9+
childProcess.exec.mockResolvedValue();
1010

1111
it("creates an annotated git tag", async () => {
1212
const tag = "v1.2.3";
1313
const opts = { cwd: "default" };
1414

1515
await gitTag(tag, {}, opts);
1616

17-
expect(mockExec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag], opts);
17+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag], opts);
1818
});
1919

2020
it("signs the tag when configured", async () => {
@@ -23,7 +23,7 @@ describe("gitTag", () => {
2323

2424
await gitTag(tag, { signGitTag: true }, opts);
2525

26-
expect(mockExec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag, "--sign"], opts);
26+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag, "--sign"], opts);
2727
});
2828

2929
it("forces the tag when configured", async () => {
@@ -32,6 +32,6 @@ describe("gitTag", () => {
3232

3333
await gitTag(tag, { forceGitTag: true }, opts);
3434

35-
expect(mockExec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag, "--force"], opts);
35+
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag, "--force"], opts);
3636
});
3737
});

0 commit comments

Comments
 (0)