Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shell option when spawning lerna exec #761

Merged
merged 8 commits into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ $ lerna exec --scope my-component -- ls -la
You may also get the name of the current package through the environment variable `LERNA_PACKAGE_NAME`:

```sh
$ lerna exec -- npm view $LERNA_PACKAGE_NAME
$ lerna exec -- npm view \$LERNA_PACKAGE_NAME
```

> Hint: The commands are spawned in parallel, using the concurrency given.
Expand Down
1 change: 1 addition & 0 deletions src/commands/ExecCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class ExecCommand extends Command {
getOpts(pkg) {
return {
cwd: pkg.location,
shell: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this property is necessary, as execa is handling this for us.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lerna exec -- npm view \$LERNA_PACKAGE_NAME works perfectly fine as-is on master, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was broken with spawn...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm view reports on the package in the current directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I just reproduced it locally.

  test.concurrent("$LERNA_PACKAGE_NAME", () => {
    return initFixture("ExecCommand/basic").then((cwd) => {
      const args = [
        "exec",
        "echo",
        "\$LERNA_PACKAGE_NAME",
        "--concurrency=1",
      ];

      return execa(LERNA_BIN, args, { cwd }).then((result) => {
        expect(result.stdout).toMatchSnapshot("echo: $LERNA_PACKAGE_NAME");
      });
    });
  });

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, it doesn't seem to matter if you pass "$LERNA_PACKAGE_NAME", or "\$LERNA_PACKAGE_NAME", in the integration test, but it certainly matters in the CLI command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration test isn't evaluating the variables before sending the arguments to lerna.

env: Object.assign({}, process.env, {
LERNA_PACKAGE_NAME: pkg.name,
}),
Expand Down
1 change: 1 addition & 0 deletions test/ExecCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe("ExecCommand", () => {
env: expect.objectContaining({
LERNA_PACKAGE_NAME: "package-2",
}),
shell: true,
}, expect.any(Function));

done();
Expand Down