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

WIP: feat(remove): initial commit for lerna remove #1887

Closed
wants to merge 5 commits into from

Conversation

tanhauhau
Copy link
Contributor

@tanhauhau tanhauhau commented Jan 23, 2019

I copied some of the code from @lerna/add, supporting glob and scope for filtering folders

Description

Current state:

  • Filter packages to be changed, based on filterOptions and path matching with glob

  • Determine whether the dependencies is external or internal

    • Should determine this in package level, instead of project level, since if version doesn't match, it will not symlink
  • Update package.json

  • if the dependency is external:

    • Remove symlink
  • else:

    • call npm uninstall or yarn remove
    • taking care of hoist logic
  • test

  • documentation

Motivation and Context

#1886

How Has This Been Tested?

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.
  • All new and existing tests passed.

@tanhauhau tanhauhau changed the title WIP: initial commit for lerna remove WIP: feat(remove): initial commit for lerna remove Jan 23, 2019
@tanhauhau
Copy link
Contributor Author

There's a lot yet to be done, would like to listen to your input on this @evocateur

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.

We definitely don't need the npm-uninstall subpackage. Definitely needs some tests, and perhaps thinking about abstracting common patterns from lerna add as well...

"dependencies": {
"@lerna/command": "file:../../core/command",
"@lerna/filter-options": "file:../../core/filter-options",
"@lerna/npm-uninstall": "file:../../utils/npm-uninstall",
Copy link
Member

Choose a reason for hiding this comment

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

@lerna/npm-uninstall looks like a copypaste of @lerna/npm-install. Why do we need it? We're already removing the entry in the package.json, etc. Running lerna bootstrap (like the add command does) should be sufficient to clean up the other stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really, the bootstrap command will not update the lockfile, at least that's not happening in yarn, due to https://github.com/lerna/lerna/blob/master/commands/bootstrap/index.js#L171

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess that's the main motivation of the MR, because removing dep in package.json and running lerna bootstrap will not remove the dep from node_modules nor updating the lock file.

Copy link
Member

Choose a reason for hiding this comment

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

Err, that branch is only reached when you are attempting a filtered bootstrap. (scope, ignore, or since)

The chained bootstrap should have none of these options, thus the raw bootstrap should actually deal with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, my bad.
still, bootstrap will have early return if all the stated dependencies have been satisfied.
for our case (lerna remove), all stated dependencies is satisfied, but we have extraneous dependencies in node_modules, should we

  1. reuse bootstrap, but add a new flag, (something like Running lerna bootstrap with node_modules doesn't update lockfile #1883 (comment)) to bypass the early return of lerna bootstrap, thus able to trigger npm client to remove extraneous pacakges and update lockfile or
  2. use npm-uninstall that focuses on removing packages, by triggering npm client's remove/uninstall command rather than install/ci in lerna bootstrap

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right, I forgot Yarn doesn't want you to remove stuff when you modify package.json and run yarn install...

So yeah, I guess we do need npm-uninstall. I'd prefer it was less copypasta, but that's more work that isn't blocking.

We also, however, need to account for the --hoist case (the removed dependency doesn't exist at the leaf, but in the root) and relative file: specifiers, which need only re-run npm install in the root. lerna bootstrap already accounts for the file: specifier case, but I really don't want to burden that poor command with any more complexity...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the hoist case, how should we figure out whether the dependency to be removed is hoisted or installed in leaf node?

// args: [],
// cwd: this.project.rootPath,
// // silence initial cli version logging, etc
// composed: "add",
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 still be doing this, instead of calling npm uninstall. Ensuring that ci: false is also passed makes sure we run npm install which will synchronize the lockfile and node_modules appropriately?

});
}

removeSymlink() {
Copy link
Member

Choose a reason for hiding this comment

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

We're not removing the symlink, but the directory. In any case, I don't think we need this. Just bootstrap after serializing the modified dependencies.

commands/remove/yarn.lock Outdated Show resolved Hide resolved
@tanhauhau
Copy link
Contributor Author

@evocateur

  • i've did some refactoring, extracting out @lerna/use-temporary-manifest, so that can be use when npm install and npm uninstall.
    • I might have break some test, I'll fix those later
  • I've added some basic test for lerna remove
    • going to add accout to --hoist case, and file: case

But I would like to listen to your comments on the general directions of the change, and there will be definitely a lot of parts of code in lerna remove and lerna bootstrap & npm-uninstall, I am going to extract them out into packages, I am not sure the packages structure I have in mind align with your plans.

@tanhauhau
Copy link
Contributor Author

@evocateur what do you think?

@lucaasrojas
Copy link

This PR's idea is be able to remove packages from the monorepo?

@tanhauhau
Copy link
Contributor Author

tanhauhau commented Mar 21, 2019

@lucaasrojas yes

@evocateur evocateur added the WIP label Mar 31, 2019
@montogeek
Copy link

@evocateur What do you think?

@evocateur
Copy link
Member

I don't really see this going forward anymore, sorry. I appreciate all the effort spent on this PR, but modern monorepos should be using package managers with proper capabilities to deal with this sort of thing (pnpm recursive, npm v7, yarn i guess).

Given the minimal frequency of use for this sort of command, the maintenance burden far outweighs the benefit of inclusion in the core. Perfect opportunity for a third-party utility.

@davidmurdoch
Copy link

Given the minimal frequency of use for this sort of command, the maintenance burden far outweighs the benefit of inclusion in the core. Perfect opportunity for a third-party utility.

FWIW, I would have used this command every day this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants