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

Add --only-updated option to exec and run subcommands #726

Merged
merged 12 commits into from May 18, 2017

Conversation

jameslnewell
Copy link
Contributor

@jameslnewell jameslnewell commented Apr 3, 2017

Description

I have added a new flag that only runs/execs packages that have been updated.

Works with scope so that only packages that match the scope AND that have been updated will be run/exec.

Motivation and Context

I have a situation where package B depends on package A. I've made a breaking change to package A and want to release package A, but I don't want/have-time to update package B to work with these changes yet. When lerna run typescript runs on package B, it will fail because the version of package A hasn't been bumped yet and lerna is symlinking the latest package A to package B.

lerna run --only-updated typescript will allow me to publish package A, re-run lerna bootstrap to install the previous version of package A in package B (instead of a symlink) and enable me to continue developing package B independently of package A.

How Has This Been Tested?

Minimal manual tests checking the run and exec commands, with and without the scope flag.

e.g.

lerna run --scope "my-component-*" --only-updated -- build
lerna exec --scope "my-component-*" --only-updated -- echo

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes. (there were no existing tests to copy from for filteredPackages - will happily add some with guidance)
  • All new and existing tests passed.

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

This needs unit tests to validate.

I've got some easier-to-grok unit tests coming in #714.

src/Command.js Outdated
@@ -182,6 +183,13 @@ export default class Command {
if (this.getOptions().includeFilteredDependencies) {
this.filteredPackages = PackageUtilities.addDependencies(this.filteredPackages, this.packageGraph);
}
if (this.flags.onlyUpdated) {
Copy link
Member

Choose a reason for hiding this comment

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

This belongs in ExecCommand and RunCommand, not the base class, yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it'll also work for clean, ls and bootstrap however I can move the logic to a utility fn and call it separately in exec and run if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

Well, consider that those other commands really have no use for this flag, and might even be considered broken if they were to adhere to it. I would recommend a separate shared file to encapsulate, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😎 will refactor

@@ -138,6 +139,14 @@ export default class PackageUtilities {
return packages;
}

static filterPackagesThatAreNotUpdated(packagesToFilter, 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.

Taking the whole command here feels a bit gross, but couldn't think of an alternative.

@jameslnewell
Copy link
Contributor Author

@evocateur I've thrown together some tests and moved the code into the specific commands (meaning there's now some duplication). Let me know if you'd like me to change anything else.

export const builder = {};
export const builder = {
"only-updated": {
"describe": "When exectuting scripts/commands, only run the script/command on packages which "

Choose a reason for hiding this comment

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

exectuting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

☺️

@@ -13,6 +13,10 @@ export const describe = "Run an npm script in each package that contains that sc
export const builder = {
"stream": {
describe: "Stream output with lines prefixed by package."
},
"only-updated": {
"describe": "When exectuting scripts/commands, only run the script/command on packages which "

Choose a reason for hiding this comment

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

exectuting

README.md Outdated
@@ -654,6 +654,18 @@ $ lerna bootstrap --scope "package-*" --ignore "package-util-*" --include-filter
# package matched by "package-*"
```

#### --only-updated

When exectuting a script or command, only run the script or command on packages that have been updated since the last release.

Choose a reason for hiding this comment

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

exectuting

README.md Outdated
@@ -654,6 +654,18 @@ $ lerna bootstrap --scope "package-*" --ignore "package-util-*" --include-filter
# package matched by "package-*"
```

#### --only-updated

When exectuting a script or command, only run the script or command on packages that have been updated since the last release.

Choose a reason for hiding this comment

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

It'd be nice to clarify the semantics of what updated means. Perhaps just add to this sentence:

A package is considered "updated" using the same rules as lerna updated.

@jameslnewell
Copy link
Contributor Author

jameslnewell commented Apr 27, 2017

@evocateur The tests are all passing but npm is getting an exit status of 0 on node v4 without any visible error. How can I re-run the tests or debug what's going wrong?

@evocateur
Copy link
Member

evocateur commented Apr 27, 2017 via email

expect(updatedPackages).toHaveLength(0);
});

it.only("should return only packages that are to be filtered and have been updated", () => {
Copy link
Member

Choose a reason for hiding this comment

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

we should definitely break lint when something like it.only is committed...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😱

@jameslnewell
Copy link
Contributor Author

jameslnewell commented May 3, 2017

The failures in node v4 appear to be in the ChildProcessUtilities.js which I haven't touched???

 PASS  test/ChildProcessUtilities.js
  ● Console

    console.error node_modules/core-js/modules/es6.promise.js:117
      Unhandled promise rejection { [Error: stdout maxBuffer exceeded] stream: 'stdout' }
    console.error node_modules/core-js/modules/es6.promise.js:117
      Unhandled promise rejection { [Error: spawn nowImTheModelOfAModernMajorGeneral ENOENT]
        code: 'ENOENT',
        errno: 'ENOENT',
        syscall: 'spawn nowImTheModelOfAModernMajorGeneral',
        path: 'nowImTheModelOfAModernMajorGeneral',
        spawnargs: [],
        killed: false,
        stdout: '',
        stderr: '',
        failed: true,
        signal: null,
        cmd: 'nowImTheModelOfAModernMajorGeneral',
        timedOut: false }
    console.error node_modules/core-js/modules/es6.promise.js:117
      Unhandled promise rejection { [Error: spawn theVeneratedVirginianVeteranWhoseMenAreAll ENOENT]
        code: 'ENOENT',
        errno: 'ENOENT',
        syscall: 'spawn theVeneratedVirginianVeteranWhoseMenAreAll',
        path: 'theVeneratedVirginianVeteranWhoseMenAreAll',
        spawnargs: [],
        killed: false,
        stdout: '',
        stderr: '',
        failed: true,
        signal: null,
        cmd: 'theVeneratedVirginianVeteranWhoseMenAreAll',
        timedOut: false }

Edit: @evocateur I get those same errors on master in node v4

@jameslnewell
Copy link
Contributor Author

hey @evocateur anything I can do to get this merged?

@evocateur evocateur changed the title added a new flag that only runs/execs packages that have been updated Add --only-updated option to exec and run subcommands May 18, 2017
@evocateur evocateur merged commit 22bad8b into lerna:master May 18, 2017
@evocateur
Copy link
Member

@jameslnewell Thanks for your patience!

@benoj
Copy link

benoj commented May 31, 2018

Is this still in the project? Don't see this in the README anymore and it is just what I am looking for!

@evocateur
Copy link
Member

evocateur commented May 31, 2018 via email

@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants