-
Notifications
You must be signed in to change notification settings - Fork 639
feat: add default-packages file support for fnm install #1503
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
6
commits into
Schniz:master
Choose a base branch
from
amanthanvi:feat/default-packages
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c756518
feat: add default-packages file support for fnm install
amanthanvi 6079dc8
docs: update commands docs for default-packages
amanthanvi 56ecb63
docs: mention default-packages in install help
amanthanvi 0bb3019
fix: make default-packages specs single-arg
amanthanvi 225db07
fix: avoid exiting during default-packages install
amanthanvi cac77b7
Merge branch 'master' into feat/default-packages
amanthanvi 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,6 @@ | ||
| --- | ||
| "fnm": minor | ||
| --- | ||
|
|
||
| Added support for `default-packages` file. When present at `$FNM_DIR/default-packages`, packages listed in this file are automatically installed globally after every `fnm install`. Compatible with nvm's default-packages format. | ||
|
|
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
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,27 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Bash installs default packages: Bash 1`] = ` | ||
| "set -e | ||
| eval "$(fnm env)" | ||
| fnm install 18 | ||
| (fnm exec --using=18 npm list -g --depth=0) | grep 'fnm-default-packages-test' || (echo "Expected output to contain 'fnm-default-packages-test'" && exit 1)" | ||
| `; | ||
|
|
||
| exports[`Bash missing default-packages file does not error: Bash 1`] = ` | ||
| "set -e | ||
| eval "$(fnm env)" | ||
| fnm install 18" | ||
| `; | ||
|
|
||
| exports[`PowerShell installs default packages: PowerShell 1`] = ` | ||
| "$ErrorActionPreference = "Stop" | ||
| fnm env | Out-String | Invoke-Expression | ||
| fnm install 18 | ||
| $($__out__ = $(fnm exec --using=18 npm list -g --depth=0 | Select-String 'fnm-default-packages-test'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })" | ||
| `; | ||
|
|
||
| exports[`PowerShell missing default-packages file does not error: PowerShell 1`] = ` | ||
| "$ErrorActionPreference = "Stop" | ||
| fnm env | Out-String | Invoke-Expression | ||
| fnm install 18" | ||
| `; |
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,56 @@ | ||
| import fs from "fs" | ||
| import path from "path" | ||
| import { script } from "./shellcode/script.js" | ||
| import { Bash, PowerShell } from "./shellcode/shells.js" | ||
| import describe from "./describe.js" | ||
| import testTmpDir from "./shellcode/test-tmp-dir.js" | ||
|
|
||
| for (const shell of [Bash, PowerShell]) { | ||
| describe(shell, () => { | ||
| test(`installs default packages`, async () => { | ||
| const fnmDir = path.join(testTmpDir(), "fnm") | ||
| fs.mkdirSync(fnmDir, { recursive: true }) | ||
| const pkgDir = path.join(testTmpDir(), "default-packages-pkg") | ||
| fs.mkdirSync(pkgDir, { recursive: true }) | ||
| fs.writeFileSync( | ||
| path.join(pkgDir, "package.json"), | ||
| JSON.stringify( | ||
| { | ||
| name: "fnm-default-packages-test", | ||
| version: "1.0.0", | ||
| }, | ||
| null, | ||
| 2 | ||
| ) | ||
| ) | ||
| fs.writeFileSync(path.join(fnmDir, "default-packages"), `${pkgDir}\n`) | ||
|
|
||
| await script(shell) | ||
| .then(shell.env({})) | ||
| .then(shell.call("fnm", ["install", "18"])) | ||
| .then( | ||
| shell.scriptOutputContains( | ||
| shell.call("fnm", [ | ||
| "exec", | ||
| "--using=18", | ||
| "npm", | ||
| "list", | ||
| "-g", | ||
| "--depth=0", | ||
| ]), | ||
| "'fnm-default-packages-test'" | ||
| ) | ||
| ) | ||
| .takeSnapshot(shell) | ||
| .execute(shell) | ||
| }) | ||
|
|
||
| test(`missing default-packages file does not error`, async () => { | ||
| await script(shell) | ||
| .then(shell.env({})) | ||
| .then(shell.call("fnm", ["install", "18"])) | ||
| .takeSnapshot(shell) | ||
| .execute(shell) | ||
| }) | ||
| }) | ||
| } | ||
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
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
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.
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.
This e2e test installs
is-oddfrom the public npm registry, which introduces an external network dependency and can make CI flaky/offline-unfriendly. Prefer installing a local test package (e.g., create a minimal package in the temp dir and reference it via a file path indefault-packages) so the test is self-contained.