Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(command): Do not mutate argv parameter
See babel/babel#10733 for details.

Fixes #2348
  • Loading branch information
evocateur committed Nov 19, 2019
1 parent 5344820 commit 8ca85a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/command/__tests__/command.test.js
Expand Up @@ -264,6 +264,15 @@ describe("core-command", () => {
}
}

it("does not mutate argv parameter", async () => {
const argv = { cwd: testDir, onRejected };
const instance = new TestACommand(argv);
await instance;

expect(argv).toEqual({ cwd: testDir, onRejected });
expect(instance.argv).not.toEqual(argv);
});

it("should pick up global options", async () => {
const instance = new TestACommand({ cwd: testDir, onRejected });
await instance;
Expand Down
4 changes: 3 additions & 1 deletion core/command/index.js
@@ -1,6 +1,7 @@
"use strict";

const _ = require("lodash");
const cloneDeep = require("clone-deep");
const dedent = require("dedent");
const execa = require("execa");
const log = require("npmlog");
Expand All @@ -18,10 +19,11 @@ const warnIfHanging = require("./lib/warn-if-hanging");
const DEFAULT_CONCURRENCY = os.cpus().length;

class Command {
constructor(argv) {
constructor(_argv) {
log.pause();
log.heading = "lerna";

const argv = cloneDeep(_argv);
log.silly("argv", argv);

// "FooCommand" => "foo"
Expand Down
1 change: 1 addition & 0 deletions core/command/package.json
Expand Up @@ -37,6 +37,7 @@
"@lerna/project": "file:../project",
"@lerna/validation-error": "file:../validation-error",
"@lerna/write-log-file": "file:../../utils/write-log-file",
"clone-deep": "^4.0.1",
"dedent": "^0.7.0",
"execa": "^1.0.0",
"is-ci": "^2.0.0",
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ca85a4

Please sign in to comment.