fix(global): install packages into final prefix#1698
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
21941bc to
3e97d03
Compare
3e97d03 to
a37bd9f
Compare
I've found the causes with the help of Codex. It is a little bit complex and related to the current snaptest architecture. Vite+ calls # The example cwd: ~
# Vite+'s temp directory
~/.vite-plus/tmp/packages/just-a-normal-package
tree ~/.vite-plus/tmp/packages/just-a-normal-package/lib/node_modules/
#~/.vite-plus/tmp/packages/just-a-normal-package/lib/node_modules/
#└── just-a-normal-package -> ../../../../../../
# This is linked to ~, 6 layers of parent directory (`../`)
# and if it is moved to ~/.vite-plus/packages/just-a-normal-package (not ~/.vite-plus/tmp)
tree ~/.vite-plus/packages/just-a-normal-package/lib/node_modules/
#~/.vite-plus/packages/just-a-normal-package/lib/node_modules/
#└── just-a-normal-package -> ../../../../../../
# It is still ../../../../../../ after moving (6 layers of `../`)
# So it will be linked to `~/../`, like `/Users`, instead of `~`. (We only need 5 layers of `../` there), make packages broken.However, the snap test runner doesn't use # The example cwd: /private ⚠️
# Vite+'s temp directory
~/.vite-plus/tmp/packages/just-a-normal-package
tree ~/.vite-plus/tmp/packages/just-a-normal-package/lib/node_modules/
#~/.vite-plus/tmp/packages/just-a-normal-package/lib/node_modules/
#└── just-a-normal-package -> ../../../../../../../../private
# This is linked to ~, 8 layers of `../`
# and if it is moved to ~/.vite-plus/packages/just-a-normal-package (not ~/.vite-plus/tmp)
tree ~/.vite-plus/packages/just-a-normal-package/lib/node_modules/
#~/.vite-plus/packages/just-a-normal-package/lib/node_modules/
#└── just-a-normal-package -> ../../../../../../../../private
# It is still ../../../../../../ after moving (still 8 layers of `../`)
# 👉 Different from the `~` case, one more `../` won't break the path because it hits the root `/` already.
# So it will be still linked to `/private`.This logic makes snap tests invalid for this fixes. @fengmk2, do you have any good idea to add validation tests for this fix? |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bdc9308081
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@liangmiQwQ If it's too much trouble, let's skip adding a snap test for this special case for now. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2169323d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
As #664 (comment) said, #1685 did not completely fix #664.
The current global package install flow runs
npm install -gin a temporary prefix and then moves the installed package prefix intoVP_HOME/packages.However,
npmand some packages'spostinstallscript may create files that links an absolute path to this temporary dir, or a relative path use the temp dir as the base dir, they will be invalid after moving, causing bugs like that.(It is quite strange that it can't be reproduced on local snap tests. I am still figuring out the reason now.)UPDATE: please refer to the comment below
So to fix this problem, this PR installs global packages directly into their final package prefix to avoid moving, to fix this problem.
There is another runtime behavior change worth mentioning: If one package in a multi-package install fails, this PR still finalizes shims for packages that already installed successfully instead of deleting them or leaving them without runnable bins. This is because if users are trying to reinstall a package or update, uninstall the installed packages can make problems. This problem only happens after the changes mentioned above, and it also follows
npm's behavior.🤖 Generated with Codex.