Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
70d6d2b
Replace semver with node-semver
amitdahan Oct 5, 2022
e32238a
Support package_json.engines.node when no dotfiles are available
amitdahan Oct 5, 2022
6d2f9ca
Fix clippy warnings (whatever that is)
amitdahan Oct 5, 2022
f11a760
Add missing snapshots
amitdahan Oct 5, 2022
00fa0e1
Merge branch 'master' into node-semver-rs
amitdahan Oct 21, 2022
5d290aa
Merge branch 'node-semver-rs' into support-engines
amitdahan Oct 21, 2022
305fae3
Don't clone in `node_range`
amitdahan Oct 21, 2022
66da695
fix lint
amitdahan Oct 21, 2022
68eba29
Merge branch 'master' into support-engines
amitdahan Jul 2, 2023
a6c7767
Rewrite tests in node
amitdahan Jul 2, 2023
d536594
remoev stale stuff
amitdahan Jul 2, 2023
b81072b
add test snapshots
amitdahan Jul 2, 2023
988df3e
fix basic.test.ts
amitdahan Jul 2, 2023
ffb3b68
make powershell be `currentlySupported` only on windows
amitdahan Jul 2, 2023
f96bcc7
Add `--resolve-engines` flag to opt-into resolving `engines.node` field
amitdahan Jul 2, 2023
f644e71
fix build
amitdahan Jul 2, 2023
55cea12
Merge branch 'master' into support-engines
Schniz Jul 4, 2023
2cb4c55
tweak help menu and use verbatim doc comment
amitdahan Jul 4, 2023
4d641c7
Add changeset
amitdahan Jul 4, 2023
9df0189
add to test
amitdahan Jul 4, 2023
b134d7d
update snapshots
amitdahan Jul 5, 2023
44307bb
Dummy commit because GH had issues
amitdahan Jul 5, 2023
47fe867
Update command docs
amitdahan Jul 5, 2023
6762e62
Tweak doc comment
amitdahan Jul 6, 2023
88bc36a
Update command docs
amitdahan Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-parrots-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": minor
---

Support resolving `engines.node` field via experimental `--resolve-engines` flag
91 changes: 91 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')

Expand Down Expand Up @@ -112,6 +119,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -162,6 +176,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -222,6 +243,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -282,6 +310,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -347,6 +382,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -402,6 +444,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -459,6 +508,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -513,6 +569,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -569,6 +632,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -619,6 +689,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -681,6 +758,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -737,6 +821,13 @@ Options:

[env: FNM_COREPACK_ENABLED]

--resolve-engines
Resolve `engines.node` field in `package.json` whenever a `.node-version` or `.nvmrc` file is not present.
Experimental: This feature is subject to change.
Note: `engines.node` can be any semver range, with the latest satisfying version being resolved.

[env: FNM_RESOLVE_ENGINES]

-h, --help
Print help (see a summary with '-h')
```
Expand Down
82 changes: 82 additions & 0 deletions e2e/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ if [ "$(node --version)" != "v8.11.3" ]; then
fi"
`;

exports[`Bash package.json engines.node with semver range: Bash 1`] = `
"set -e
eval "$(fnm env --resolve-engines)"
fnm install
fnm use
if [ "$(node --version)" != "v6.17.0" ]; then
echo "Expected node version to be v6.17.0. Got $(node --version)"
exit 1
fi"
`;

exports[`Bash package.json engines.node: Bash 1`] = `
"set -e
eval "$(fnm env --resolve-engines)"
fnm install
fnm use
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;

exports[`Bash resolves partial semver: Bash 1`] = `
"set -e
eval "$(fnm env)"
Expand Down Expand Up @@ -118,6 +140,28 @@ if test "$____test____" != "v8.11.3"
end"
`;

exports[`Fish package.json engines.node with semver range: Fish 1`] = `
"fnm env --resolve-engines | source
fnm install
fnm use
set ____test____ (node --version)
if test "$____test____" != "v6.17.0"
echo "Expected node version to be v6.17.0. Got $____test____"
exit 1
end"
`;

exports[`Fish package.json engines.node: Fish 1`] = `
"fnm env --resolve-engines | source
fnm install
fnm use
set ____test____ (node --version)
if test "$____test____" != "v8.11.3"
echo "Expected node version to be v8.11.3. Got $____test____"
exit 1
end"
`;

exports[`Fish resolves partial semver: Fish 1`] = `
"fnm env | source
fnm install 6
Expand Down Expand Up @@ -182,6 +226,22 @@ fnm use v8.11.3
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }"
`;

exports[`PowerShell package.json engines.node with semver range: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --resolve-engines | Out-String | Invoke-Expression
fnm install
fnm use
if ( "$(node --version)" -ne "v6.17.0" ) { echo "Expected node version to be v6.17.0. Got $(node --version)"; exit 1 }"
`;

exports[`PowerShell package.json engines.node: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --resolve-engines | Out-String | Invoke-Expression
fnm install
fnm use
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }"
`;

exports[`PowerShell resolves partial semver: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
Expand Down Expand Up @@ -249,6 +309,28 @@ if [ "$(node --version)" != "v8.11.3" ]; then
fi"
`;

exports[`Zsh package.json engines.node with semver range: Zsh 1`] = `
"set -e
eval "$(fnm env --resolve-engines)"
fnm install
fnm use
if [ "$(node --version)" != "v6.17.0" ]; then
echo "Expected node version to be v6.17.0. Got $(node --version)"
exit 1
fi"
`;

exports[`Zsh package.json engines.node: Zsh 1`] = `
"set -e
eval "$(fnm env --resolve-engines)"
fnm install
fnm use
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;

exports[`Zsh resolves partial semver: Zsh 1`] = `
"set -e
eval "$(fnm env)"
Expand Down
28 changes: 28 additions & 0 deletions e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) {
.execute(shell)
})

test(`package.json engines.node`, async () => {
await writeFile(
join(testCwd(), "package.json"),
JSON.stringify({ engines: { node: "8.11.3" } })
)
await script(shell)
.then(shell.env({ resolveEngines: true }))
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["use"]))
.then(testNodeVersion(shell, "v8.11.3"))
.takeSnapshot(shell)
.execute(shell)
})

test(`package.json engines.node with semver range`, async () => {
await writeFile(
join(testCwd(), "package.json"),
JSON.stringify({ engines: { node: "^6 < 6.17.1" } })
)
await script(shell)
.then(shell.env({ resolveEngines: true }))
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["use"]))
.then(testNodeVersion(shell, "v6.17.0"))
.takeSnapshot(shell)
.execute(shell)
})

test(`use on cd`, async () => {
await mkdir(join(testCwd(), "subdir"), { recursive: true })
await writeFile(join(testCwd(), "subdir", ".node-version"), "v12.22.12")
Expand Down
1 change: 1 addition & 0 deletions e2e/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) {
FNM_LOGLEVEL: "info",
FNM_MULTISHELL_PATH: expect.any(String),
FNM_NODE_DIST_MIRROR: expect.any(String),
FNM_RESOLVE_ENGINES: "false",
FNM_COREPACK_ENABLED: "false",
FNM_VERSION_FILE_STRATEGY: "local",
})
Expand Down
2 changes: 1 addition & 1 deletion e2e/shellcode/shells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const PowerShell = {
...define<Shell>({
binaryName: () => "pwsh",
forceFile: ".ps1",
currentlySupported: () => true,
currentlySupported: () => process.platform === "win32",
name: () => "PowerShell",
launchArgs: () => ["-NoProfile"],
escapeText: (x) => x,
Expand Down
4 changes: 3 additions & 1 deletion e2e/shellcode/shells/cmdEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ type EnvConfig = {
useOnCd: boolean
logLevel: string
corepackEnabled: boolean
resolveEngines: boolean
}
export type HasEnv = { env(cfg: Partial<EnvConfig>): ScriptLine }

function stringify(envConfig: Partial<EnvConfig> = {}) {
const { useOnCd, logLevel, corepackEnabled } = envConfig
const { useOnCd, logLevel, corepackEnabled, resolveEngines } = envConfig
return [
`fnm env`,
useOnCd && "--use-on-cd",
logLevel && `--log-level=${logLevel}`,
corepackEnabled && "--corepack-enabled",
resolveEngines && `--resolve-engines`,
]
.filter(Boolean)
.join(" ")
Expand Down
1 change: 1 addition & 0 deletions src/commands/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Command for Env {
"FNM_COREPACK_ENABLED",
config.corepack_enabled().to_string(),
),
("FNM_RESOLVE_ENGINES", config.resolve_engines().to_string()),
("FNM_ARCH", config.arch.to_string()),
]);

Expand Down
Loading