-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
There's a lot yet to be done, would like to listen to your input on this @evocateur |
There was a problem hiding this 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...
commands/remove/package.json
Outdated
"dependencies": { | ||
"@lerna/command": "file:../../core/command", | ||
"@lerna/filter-options": "file:../../core/filter-options", | ||
"@lerna/npm-uninstall": "file:../../utils/npm-uninstall", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
- 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
- use
npm-uninstall
that focuses on removing packages, by triggering npm client'sremove
/uninstall
command rather thaninstall
/ci
inlerna bootstrap
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
0e83ddf
to
04be5c5
Compare
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 |
@evocateur what do you think? |
This PR's idea is be able to remove packages from the monorepo? |
@lucaasrojas yes |
@evocateur What do you think? |
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. |
FWIW, I would have used this command every day this week. |
I copied some of the code from
@lerna/add
, supporting glob and scope for filtering foldersDescription
Current state:
Filter packages to be changed, based on
filterOptions
and path matching withglob
Determine whether the dependencies is external or internal
Update package.json
if the dependency is external:
else:
npm uninstall
oryarn remove
test
documentation
Motivation and Context
#1886
How Has This Been Tested?
Types of changes
Checklist: