-
Notifications
You must be signed in to change notification settings - Fork 639
feat: add --reinstall-packages-from flag to fnm install #1505
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
Open
amanthanvi
wants to merge
13
commits into
Schniz:master
Choose a base branch
from
amanthanvi:feat/reinstall-packages-from
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
327a1ef
feat: add --reinstall-packages-from flag to fnm install
amanthanvi 4171c5d
Merge branch 'master' into feat/reinstall-packages-from
Schniz 2c3fad3
fix: skip reinstall-packages-from when source and target versions are…
Schniz 6eecf2e
refactor: extract npm_env_for_version helper to reduce duplication
Schniz 5705657
fix: add Send + Sync bounds to ReinstallPackagesError source
Schniz 90f28ee
fix: warn when npm ls exits non-zero with partial output
Schniz 734650a
test: expand reinstall-packages-from e2e tests to cover Zsh and Fish
Schniz 780231b
refactor: use filesystem scan for reinstall package discovery
Schniz 9644e46
fix: skip symlinked globals in package reinstallation
Schniz 6f10b8b
fix: include APPDATA npm globals in reinstall scan
Schniz e57734a
fix: use npm ls for Windows global package discovery
Schniz 32789c1
chore: consolidate reinstall-packages changesets
Schniz f3c174f
fix: stabilize reinstall CI checks across platforms
Schniz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "fnm": minor | ||
| --- | ||
|
|
||
| Added `--reinstall-packages-from` flag to `fnm install`. When specified, global npm packages from the given Node version are automatically reinstalled on the newly installed version. Analogous to nvm's `--reinstall-packages-from` flag. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Bash errors when source version is not installed: Bash 1`] = ` | ||
| "set -e | ||
| eval "$(fnm env --log-level=error)" | ||
| (fnm install v20.11.0 --reinstall-packages-from=v18.20.0 2>&1) | grep 'Version v18.20.0 is not installed' || (echo "Expected output to contain 'Version v18.20.0 is not installed'" && exit 1)" | ||
| `; | ||
|
|
||
| exports[`Bash reinstall packages from another version: Bash 1`] = ` | ||
| "set -e | ||
| eval "$(fnm env)" | ||
| fnm install v18.20.0 | ||
| fnm use v18.20.0 | ||
| npm install -g is-odd | ||
| (npm list -g --depth=0) | grep 'is-odd' || (echo "Expected output to contain 'is-odd'" && exit 1) | ||
| __out__="$(fnm install v20.11.0 --reinstall-packages-from=v18.20.0 2>&1)" | ||
| echo "$__out__" | grep 'is-odd@' || (echo "Expected output to contain 'is-odd@'" && exit 1) | ||
| if echo "$__out__" | grep -q ' - npm@'; then | ||
| echo "Expected output to not contain 'npm@'" | ||
| exit 1 | ||
| fi | ||
| if echo "$__out__" | grep -q ' - corepack@'; then | ||
| echo "Expected output to not contain 'corepack@'" | ||
| exit 1 | ||
| fi | ||
| echo "$__out__" | grep 'Successfully reinstalled' || (echo "Expected output to contain 'Successfully reinstalled'" && exit 1) | ||
|
|
||
| fnm use v20.11.0 | ||
| (npm list -g --depth=0) | grep 'is-odd' || (echo "Expected output to contain 'is-odd'" && exit 1)" | ||
| `; | ||
|
|
||
| exports[`Bash source has no global packages: Bash 1`] = ` | ||
| "set -e | ||
| eval "$(fnm env)" | ||
| fnm install v18.20.0 | ||
| (fnm install v20.11.0 --reinstall-packages-from=v18.20.0) | grep 'No global packages found in' || (echo "Expected output to contain 'No global packages found in'" && exit 1)" | ||
| `; | ||
|
|
||
| exports[`PowerShell errors when source version is not installed: PowerShell 1`] = ` | ||
| "$ErrorActionPreference = "Stop" | ||
| fnm env --log-level=error | Out-String | Invoke-Expression | ||
| $($__out__ = $(fnm install v20.11.0 --reinstall-packages-from=v18.20.0 2>&1 | Select-String 'Version v18.20.0 is not installed'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })" | ||
| `; | ||
|
|
||
| exports[`PowerShell reinstall packages from another version: PowerShell 1`] = ` | ||
| "$ErrorActionPreference = "Stop" | ||
| fnm env | Out-String | Invoke-Expression | ||
| fnm install v18.20.0 | ||
| fnm use v18.20.0 | ||
| npm install -g is-odd | ||
| $($__out__ = $(npm list -g --depth=0 | Select-String 'is-odd'); if ($__out__ -eq $null) { exit 1 } else { $__out__ }) | ||
| $__out__ = fnm install v20.11.0 --reinstall-packages-from=v18.20.0 2>&1 | Out-String | ||
| if ($__out__ -notmatch "is-odd@") { exit 1 } | ||
| if ($__out__ -match " - npm@") { exit 1 } | ||
| if ($__out__ -match " - corepack@") { exit 1 } | ||
| if ($__out__ -notmatch "Successfully reinstalled") { exit 1 } | ||
|
|
||
| fnm use v20.11.0 | ||
| $($__out__ = $(npm list -g --depth=0 | Select-String 'is-odd'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })" | ||
| `; | ||
|
|
||
| exports[`PowerShell source has no global packages: PowerShell 1`] = ` | ||
| "$ErrorActionPreference = "Stop" | ||
| fnm env | Out-String | Invoke-Expression | ||
| fnm install v18.20.0 | ||
| $($__out__ = $(fnm install v20.11.0 --reinstall-packages-from=v18.20.0 | Select-String 'No global packages found in'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })" | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import getStderr from "./shellcode/get-stderr.js" | ||
| import { script } from "./shellcode/script.js" | ||
| import { Bash, PowerShell } from "./shellcode/shells.js" | ||
| import describe from "./describe.js" | ||
|
|
||
| const SOURCE_VERSION = "v18.20.0" | ||
| const TARGET_VERSION = "v20.11.0" | ||
|
|
||
| for (const shell of [Bash, PowerShell]) { | ||
| describe(shell, () => { | ||
| test(`reinstall packages from another version`, async () => { | ||
| const installTargetWithReinstall = | ||
| shell === Bash | ||
| ? `__out__="$(fnm install ${TARGET_VERSION} --reinstall-packages-from=${SOURCE_VERSION} 2>&1)" | ||
| echo "$__out__" | grep 'is-odd@' || (echo "Expected output to contain 'is-odd@'" && exit 1) | ||
| if echo "$__out__" | grep -q ' - npm@'; then | ||
| echo "Expected output to not contain 'npm@'" | ||
| exit 1 | ||
| fi | ||
| if echo "$__out__" | grep -q ' - corepack@'; then | ||
| echo "Expected output to not contain 'corepack@'" | ||
| exit 1 | ||
| fi | ||
| echo "$__out__" | grep 'Successfully reinstalled' || (echo "Expected output to contain 'Successfully reinstalled'" && exit 1) | ||
| ` | ||
| : `$__out__ = fnm install ${TARGET_VERSION} --reinstall-packages-from=${SOURCE_VERSION} 2>&1 | Out-String | ||
| if ($__out__ -notmatch "is-odd@") { exit 1 } | ||
| if ($__out__ -match " - npm@") { exit 1 } | ||
| if ($__out__ -match " - corepack@") { exit 1 } | ||
| if ($__out__ -notmatch "Successfully reinstalled") { exit 1 } | ||
| ` | ||
|
|
||
| await script(shell) | ||
| .then(shell.env({})) | ||
| .then(shell.call("fnm", ["install", SOURCE_VERSION])) | ||
| .then(shell.call("fnm", ["use", SOURCE_VERSION])) | ||
| .then(shell.call("npm", ["install", "-g", "is-odd"])) | ||
| .then( | ||
| shell.scriptOutputContains( | ||
| shell.call("npm", ["list", "-g", "--depth=0"]), | ||
| "'is-odd'" | ||
| ) | ||
| ) | ||
| .then(installTargetWithReinstall) | ||
| .then(shell.call("fnm", ["use", TARGET_VERSION])) | ||
| .then( | ||
| shell.scriptOutputContains( | ||
| shell.call("npm", ["list", "-g", "--depth=0"]), | ||
| "'is-odd'" | ||
| ) | ||
| ) | ||
| .takeSnapshot(shell) | ||
| .execute(shell) | ||
| }) | ||
|
|
||
| test(`errors when source version is not installed`, async () => { | ||
| await script(shell) | ||
| .then(shell.env({ logLevel: "error" })) | ||
| .then( | ||
| shell.scriptOutputContains( | ||
| getStderr( | ||
| shell.call("fnm", [ | ||
| "install", | ||
| TARGET_VERSION, | ||
| `--reinstall-packages-from=${SOURCE_VERSION}`, | ||
| ]) | ||
| ), | ||
| "'Version v18.20.0 is not installed'", | ||
| ) | ||
| ) | ||
| .takeSnapshot(shell) | ||
| .execute(shell) | ||
| }) | ||
|
|
||
| test(`source has no global packages`, async () => { | ||
| await script(shell) | ||
| .then(shell.env({})) | ||
| .then(shell.call("fnm", ["install", SOURCE_VERSION])) | ||
| .then( | ||
| shell.scriptOutputContains( | ||
| shell.call("fnm", [ | ||
| "install", | ||
| TARGET_VERSION, | ||
| `--reinstall-packages-from=${SOURCE_VERSION}`, | ||
| ]), | ||
| "'No global packages found in'", | ||
| ) | ||
| ) | ||
| .takeSnapshot(shell) | ||
| .execute(shell) | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.