-
Notifications
You must be signed in to change notification settings - Fork 12k
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
refactor(@angular/cli): improve update package discovery #18610
refactor(@angular/cli): improve update package discovery #18610
Conversation
0921dbc
to
f4df12d
Compare
f4df12d
to
13c5b32
Compare
13c5b32
to
146d032
Compare
If
The problem is with the use of
Here's a step by step explanation:
The problem is also described here: https://stackoverflow.com/questions/59865584/how-to-invalidate-cached-require-resolve-results A simpler repro is here: https://gist.github.com/andreialecu/748bb0e48396a3f217b3de912489af07 Replacing |
404d569
to
f16d985
Compare
I also included an E2E test for a |
bbca07c
to
6fe5758
Compare
There are still some potential problems and edge cases, which cannot be fixed just in this package. Particularly in this migration script: The script above depends on This causes problems if Here's the error it can produce:
However: "workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"**/@angular*",
"**/@angular*/**",
...
]
}, I could work around it by adding the above to my root The correct fix here would be for But even so, the changes in this PR should move this further along. |
Thank you for the extensive work on improving the update command. |
6fe5758
to
f6fc0ee
Compare
db3934f
to
c2c05b3
Compare
@clydin I have updated the PR as per your requirement. I'd like to also point out something that I think may be a fundamental problem in how
This migration script imports As per my previous comment, Now when a multi-version upgrade runs, the following can happen:
I think the only right solution would be to always start a fresh process after |
Further reading here: https://yarnpkg.com/advanced/rulebook#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies |
This is intentional. The framework libraries are web-only packages that cannot have additional dependencies. Improvements to schematics and migrations are in the planning/design stages that will help to alleviate these type of issues. |
The thing is they do have additional dependencies they just don't declare it |
That is correct but that part is the intentional aspect since they are only needed for one specific use case during development and not during runtime or outside the migration scenario of the CLI. It is not an ideal situation but it will be improved moving forward. One of the primary goals of the changes mentioned to schematics/migrations is to remove the situation of the hidden dependencies. |
packages/angular/cli/lib/init.ts
Outdated
@@ -20,7 +21,7 @@ const packageJson = require('../package.json'); | |||
|
|||
function _fromPackageJson(cwd = process.cwd()): SemVer | null { | |||
do { | |||
const packageJsonPath = path.join(cwd, 'node_modules/@angular/cli/package.json'); | |||
const packageJsonPath = resolve.sync('@angular/cli/package.json', { paths: [process.cwd()] }); |
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.
Can you remove this change? While this file could use some improvements, it is out of scope for the update related changes in this PR.
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.
@clydin so there is a bug here I introduced, thanks for catching it, it should be paths: [cwd]
instead.
However, this change can be related to this PR. Consider the following scenario:
/monorepo/package.json
/monorepo/node_modules/@angular/cli/... <- @angular/cli could be hoisted here by yarn (most commonly is, unless the monorepo contains multiple angular projects on different angular versions)
/monorepo/packages/webapp/package.json <- depends on @angular/cli
/monorepo/packages/webapp/node_modules/... <- other deps, but @angular/cli not stored here
Now, if a user runs ng update
while being cwd
to /monorepo/packages/webapp/
the logic above will fail to find the locally installed @angular/cli
and will use the global one.
ng update
will most commonly be run from within /monorepo/packages/webapp/
so this will occur basically every time, it just depends where yarn will hoist @angular/cli
(which is not predictable). So it can result in unexpected behavior in some projects, but not others.
Are you sure you want me to revert it?
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.
Please do. That function will not exist soon. The problem demonstrated above will be removed as a result as well.
tests/legacy-cli/e2e/utils/assets.ts
Outdated
@@ -4,7 +4,8 @@ import {getGlobalVariable} from './env'; | |||
import {relative} from 'path'; | |||
import {copyFile, writeFile} from './fs'; | |||
import {useBuiltPackages} from './project'; | |||
import { git, silentNpm } from './process'; | |||
import { git, silentNpm, silentYarn } from './process'; | |||
import { skip } from 'rxjs/operators'; |
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.
skip
doesn't appear to be used.
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.
Got it. Will force push a fix for this once a decision is made on the other comment.
c2c05b3
to
7840849
Compare
I'm not sure what happened with the tests. They were previously running fine. Maybe it's a flake? |
Master is currently red, we’re working on it 😊 |
7840849
to
dc63565
Compare
@alan-agius4 apologies, somehow I messed up to revert that file properly, hence the conflict. Should be good now I hope. PS: If you need to do any other minor changes (like variable names and what not) and can't wait for me, "Allow edits from maintainers" is enabled. |
A rebase against master should fix CI. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Removes the dependency on read-package-tree which is closely tied to
npm
.