Browse Source

Add support for .node-version files (#42)

adding support for `.node-version` files, along with `.nvmrc` files

Resolves #8
remotes/origin/add-simple-redirecting-site
Dean Merchant 6 years ago committed by Gal Schlezinger
parent
commit
fd86d8ca6a
  1. 4
      README.md
  2. 72
      esy.lock/index.json
  3. 4
      esy.lock/opam/dune.1.7.1/opam
  4. 4
      esy.lock/opam/yojson.1.7.0/opam
  5. 0
      esy.lock/overrides/opam__s__dune_opam__c__1.7.1_opam_override/package.json
  6. 2
      executable/FnmApp.re
  7. 2
      executable/Install.re
  8. 6
      executable/Use.re
  9. 1
      feature_tests/matching-dotfiles/.node-version
  10. 1
      feature_tests/matching-dotfiles/.nvmrc
  11. 11
      feature_tests/matching-dotfiles/run.sh
  12. 1
      feature_tests/node-version/.node-version
  13. 10
      feature_tests/node-version/run.sh
  14. 30
      library/Dotfiles.re
  15. 14
      library/Nvmrc.re

4
README.md

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
:rocket: Built with speed in mind
:thinking: Works with `.nvmrc` files
:thinking: Works with `.nvmrc` and `.node-version` files
## Installation
@ -54,7 +54,7 @@ Installs `[VERSION]`. If no version provided, it will install the version specif @@ -54,7 +54,7 @@ Installs `[VERSION]`. If no version provided, it will install the version specif
### `fnm use [VERSION]`
Activates `[VERSION]` as the current Node version. If no version provided, it will activate the version specified in the `.nvmrc` file located in the current working directory.
Activates `[VERSION]` as the current Node version. If no version provided, it will activate the version specified in the `.nvmrc` or `.node-version` file located in the current working directory.
### `fnm ls`

72
esy.lock/index.json

@ -841,7 +841,7 @@ @@ -841,7 +841,7 @@
"dependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/re@opam:1.7.3@83095efd",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/reason@3.4.0@d41d8cd9"
],
"devDependencies": []
@ -1601,14 +1601,14 @@ @@ -1601,14 +1601,14 @@
],
"devDependencies": []
},
"lint-staged@8.1.3@d41d8cd9": {
"id": "lint-staged@8.1.3@d41d8cd9",
"lint-staged@8.1.4@d41d8cd9": {
"id": "lint-staged@8.1.4@d41d8cd9",
"name": "lint-staged",
"version": "8.1.3",
"version": "8.1.4",
"source": {
"type": "install",
"source": [
"archive:https://registry.npmjs.org/lint-staged/-/lint-staged-8.1.3.tgz#sha1:bb069db5466c0fe16710216e633a84f2b362fa60"
"archive:https://registry.npmjs.org/lint-staged/-/lint-staged-8.1.4.tgz#sha1:a726592c0e55231116af295e730643bb711c169b"
]
},
"overrides": [],
@ -2498,14 +2498,14 @@ @@ -2498,14 +2498,14 @@
"@opam/lwt_ppx@opam:1.2.1@db1172a7",
"@opam/lwt@opam:4.1.0@111fc2bf",
"@opam/lambdasoup@opam:0.6.3@b8ef0a81",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@opam/core@opam:v0.11.3@ac79d7b5",
"@opam/cmdliner@opam:1.0.3@96d31520",
"@esy-ocaml/reason@3.4.0@d41d8cd9"
],
"devDependencies": [
"prettier@1.16.4@d41d8cd9",
"lint-staged@8.1.3@d41d8cd9",
"lint-staged@8.1.4@d41d8cd9",
"jest-diff@24.0.0@d41d8cd9",
"@opam/merlin@opam:3.2.2@829ee6dd"
]
@ -3574,7 +3574,7 @@ @@ -3574,7 +3574,7 @@
"ocaml@4.6.10@d41d8cd9",
"@reason-native/pastel@0.1.0@d41d8cd9",
"@reason-native/file-context-printer@0.0.2@d41d8cd9",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/reason@3.4.0@d41d8cd9"
],
"devDependencies": []
@ -3592,7 +3592,7 @@ @@ -3592,7 +3592,7 @@
"overrides": [],
"dependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/reason@3.4.0@d41d8cd9"
],
"devDependencies": []
@ -3612,7 +3612,7 @@ @@ -3612,7 +3612,7 @@
"ocaml@4.6.10@d41d8cd9",
"@reason-native/pastel@0.1.0@d41d8cd9",
"@opam/re@opam:1.7.3@83095efd",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/reason@3.4.0@d41d8cd9"
],
"devDependencies": []
@ -3630,32 +3630,32 @@ @@ -3630,32 +3630,32 @@
"overrides": [],
"dependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/reason@3.4.0@d41d8cd9"
],
"devDependencies": []
},
"@opam/yojson@opam:1.6.0@f7ec7c12": {
"id": "@opam/yojson@opam:1.6.0@f7ec7c12",
"@opam/yojson@opam:1.7.0@2d92307e": {
"id": "@opam/yojson@opam:1.7.0@2d92307e",
"name": "@opam/yojson",
"version": "opam:1.6.0",
"version": "opam:1.7.0",
"source": {
"type": "install",
"source": [
"archive:https://opam.ocaml.org/cache/md5/8c/8ca16557d3068253cc375452af3bde96#md5:8ca16557d3068253cc375452af3bde96",
"archive:https://github.com/ocaml-community/yojson/releases/download/1.6.0/yojson-1.6.0.tbz#md5:8ca16557d3068253cc375452af3bde96"
"archive:https://opam.ocaml.org/cache/md5/b8/b89d39ca3f8c532abe5f547ad3b8f84d#md5:b89d39ca3f8c532abe5f547ad3b8f84d",
"archive:https://github.com/ocaml-community/yojson/releases/download/1.7.0/yojson-1.7.0.tbz#md5:b89d39ca3f8c532abe5f547ad3b8f84d"
],
"opam": {
"name": "yojson",
"version": "1.6.0",
"path": "esy.lock/opam/yojson.1.6.0"
"version": "1.7.0",
"path": "esy.lock/opam/yojson.1.7.0"
}
},
"overrides": [],
"dependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/easy-format@opam:1.3.1@9abfd4ed",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@opam/cppo@opam:1.6.5@bec3dbd9",
"@opam/biniou@opam:1.2.0@c8516f18",
"@esy-ocaml/substs@0.0.1@d41d8cd9"
@ -4047,7 +4047,7 @@ @@ -4047,7 +4047,7 @@
"@opam/ppx_derivers@opam:1.0@78655ff8",
"@opam/ocaml-migrate-parsetree@opam:1.2.0@5b3aa0d3",
"@opam/ocaml-compiler-libs@opam:v0.11.0@7e9ced39",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@opam/base@opam:v0.11.1@0e54024e",
"@esy-ocaml/substs@0.0.1@d41d8cd9"
],
@ -5104,7 +5104,7 @@ @@ -5104,7 +5104,7 @@
"ocaml@4.6.10@d41d8cd9",
"@opam/result@opam:1.3@bee8bf2e",
"@opam/ppx_derivers@opam:1.0@78655ff8",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/substs@0.0.1@d41d8cd9"
],
"devDependencies": [
@ -5213,14 +5213,14 @@ @@ -5213,14 +5213,14 @@
"overrides": [],
"dependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/yojson@opam:1.6.0@f7ec7c12",
"@opam/yojson@opam:1.7.0@2d92307e",
"@opam/ocamlfind@opam:1.8.0@96572762",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/substs@0.0.1@d41d8cd9"
],
"devDependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/yojson@opam:1.6.0@f7ec7c12",
"@opam/yojson@opam:1.7.0@2d92307e",
"@opam/ocamlfind@opam:1.8.0@96572762"
]
},
@ -5270,7 +5270,7 @@ @@ -5270,7 +5270,7 @@
"ocaml@4.6.10@d41d8cd9",
"@opam/uutf@opam:1.0.2@4440868f",
"@opam/uchar@opam:0.0.2@c8218eea",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/substs@0.0.1@d41d8cd9"
],
"devDependencies": [
@ -5387,12 +5387,12 @@ @@ -5387,12 +5387,12 @@
"overrides": [],
"dependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee",
"@esy-ocaml/substs@0.0.1@d41d8cd9"
],
"devDependencies": [
"ocaml@4.6.10@d41d8cd9",
"@opam/dune@opam:1.6.3@a7d7baed"
"@opam/dune@opam:1.7.1@6f40bfee"
]
},
"@opam/jane-street-headers@opam:v0.11.0@f1cada02": {
@ -5475,25 +5475,25 @@ @@ -5475,25 +5475,25 @@
],
"devDependencies": ["ocaml@4.6.10@d41d8cd9"]
},
"@opam/dune@opam:1.6.3@a7d7baed": {
"id": "@opam/dune@opam:1.6.3@a7d7baed",
"@opam/dune@opam:1.7.1@6f40bfee": {
"id": "@opam/dune@opam:1.7.1@6f40bfee",
"name": "@opam/dune",
"version": "opam:1.6.3",
"version": "opam:1.7.1",
"source": {
"type": "install",
"source": [
"archive:https://opam.ocaml.org/cache/md5/12/1212a36547d25269675d767c38fecf5f#md5:1212a36547d25269675d767c38fecf5f",
"archive:https://github.com/ocaml/dune/releases/download/1.6.3/dune-1.6.3.tbz#md5:1212a36547d25269675d767c38fecf5f"
"archive:https://opam.ocaml.org/cache/md5/7b/7b184c8d74ec5177f9bb2f4c4a035c4f#md5:7b184c8d74ec5177f9bb2f4c4a035c4f",
"archive:https://github.com/ocaml/dune/releases/download/1.7.1/dune-1.7.1.tbz#md5:7b184c8d74ec5177f9bb2f4c4a035c4f"
],
"opam": {
"name": "dune",
"version": "1.6.3",
"path": "esy.lock/opam/dune.1.6.3"
"version": "1.7.1",
"path": "esy.lock/opam/dune.1.7.1"
}
},
"overrides": [
{
"opamoverride": "esy.lock/overrides/opam__s__dune_opam__c__1.6.3_opam_override"
"opamoverride": "esy.lock/overrides/opam__s__dune_opam__c__1.7.1_opam_override"
}
],
"dependencies": [
@ -5924,7 +5924,7 @@ @@ -5924,7 +5924,7 @@
"@opam/ocaml-migrate-parsetree@opam:1.2.0@5b3aa0d3",
"@opam/merlin-extend@opam:0.3@e1fc0d08",
"@opam/menhir@opam:20181113@0c8257a8",
"@opam/dune@opam:1.6.3@a7d7baed"
"@opam/dune@opam:1.7.1@6f40bfee"
],
"devDependencies": []
},

4
esy.lock/opam/dune.1.6.3/opam → esy.lock/opam/dune.1.7.1/opam

@ -42,6 +42,6 @@ packages across several versions of OCaml and gives cross-compilation @@ -42,6 +42,6 @@ packages across several versions of OCaml and gives cross-compilation
for free.
"""
url {
src: "https://github.com/ocaml/dune/releases/download/1.6.3/dune-1.6.3.tbz"
checksum: "md5=1212a36547d25269675d767c38fecf5f"
src: "https://github.com/ocaml/dune/releases/download/1.7.1/dune-1.7.1.tbz"
checksum: "md5=7b184c8d74ec5177f9bb2f4c4a035c4f"
}

4
esy.lock/opam/yojson.1.6.0/opam → esy.lock/opam/yojson.1.7.0/opam

@ -33,6 +33,6 @@ The program atdgen can be used to derive OCaml-JSON serializers and @@ -33,6 +33,6 @@ The program atdgen can be used to derive OCaml-JSON serializers and
deserializers from type definitions."""
url {
src:
"https://github.com/ocaml-community/yojson/releases/download/1.6.0/yojson-1.6.0.tbz"
checksum: "md5=8ca16557d3068253cc375452af3bde96"
"https://github.com/ocaml-community/yojson/releases/download/1.7.0/yojson-1.7.0.tbz"
checksum: "md5=b89d39ca3f8c532abe5f547ad3b8f84d"
}

0
esy.lock/overrides/opam__s__dune_opam__c__1.6.3_opam_override/package.json → esy.lock/overrides/opam__s__dune_opam__c__1.7.1_opam_override/package.json

2
executable/FnmApp.re

@ -92,7 +92,7 @@ let use = { @@ -92,7 +92,7 @@ let use = {
};
let selectedVersion = {
let doc = "Switch to version $(docv).\nLeave empty to look for value from `.nvmrc`";
let doc = "Switch to version $(docv).\nLeave empty to look for value from an `.nvmrc` or `.node-version` file";
Arg.(
value & pos(0, some(string), None) & info([], ~docv="VERSION", ~doc)
);

2
executable/Install.re

@ -23,7 +23,7 @@ let main = (~version as versionName) => { @@ -23,7 +23,7 @@ let main = (~version as versionName) => {
and versionName =
switch (versionName) {
| Some(versionName) => Lwt.return(versionName)
| None => Nvmrc.getVersion()
| None => Dotfiles.getVersion()
};
let versionName = Versions.format(versionName);

6
executable/Use.re

@ -55,7 +55,7 @@ let main = (~version as providedVersion, ~quiet) => { @@ -55,7 +55,7 @@ let main = (~version as providedVersion, ~quiet) => {
let%lwt version =
switch (providedVersion) {
| Some(version) => Lwt.return(version)
| None => Nvmrc.getVersion()
| None => Dotfiles.getVersion()
};
switchVersion(~version, ~quiet);
};
@ -71,11 +71,11 @@ let run = (~version, ~quiet) => @@ -71,11 +71,11 @@ let run = (~version, ~quiet) =>
</Pastel>,
)
|> Lwt.return
| Nvmrc.Version_Not_Provided =>
| Dotfiles.Version_Not_Provided =>
log(
~quiet,
<Pastel color=Pastel.Red>
"No .nvmrc was found in the current directory. Please provide a version number."
"No .nvmrc or .node-version file was found in the current directory. Please provide a version number."
</Pastel>,
)
|> Lwt.return

1
feature_tests/matching-dotfiles/.node-version

@ -0,0 +1 @@ @@ -0,0 +1 @@
11.10.0

1
feature_tests/matching-dotfiles/.nvmrc

@ -0,0 +1 @@ @@ -0,0 +1 @@
11.10.0

11
feature_tests/matching-dotfiles/run.sh

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
#!/bin/bash
eval $(fnm env)
fnm install
fnm use
echo node --version
if [ "$(node --version)" != "v11.10.0" ]; then
echo "Expected Node version is not v11.10.0!"
exit 1
fi

1
feature_tests/node-version/.node-version

@ -0,0 +1 @@ @@ -0,0 +1 @@
11.10.0

10
feature_tests/node-version/run.sh

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
#!/bin/bash
eval $(fnm env)
fnm install
fnm use
if [ "$(node --version)" != "v11.10.0" ]; then
echo "Node version is not v11.10.0!"
exit 1
fi

30
library/Dotfiles.re

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
exception Version_Not_Provided;
let versionString = fileName => {
try%lwt (
Lwt_io.lines_of_file(fileName)
|> Lwt_stream.to_list
|> Lwt.map(List.hd)
|> Lwt.map(String.trim)
|> Lwt.map(versionString => Some(versionString))
) {
| Unix.Unix_error(Unix.ENOENT, _, _) => Lwt.return(None)
};
};
let getVersion = () => {
let%lwt cwd = Lwt_unix.getcwd();
let%lwt nodeVersion = versionString(Filename.concat(cwd, ".node-version"))
and nvmrc = versionString(Filename.concat(cwd, ".nvmrc"));
switch (nodeVersion, nvmrc) {
| (None, None) => Lwt.fail(Version_Not_Provided)
| (Some(v1), Some(v2)) when v1 != v2 =>
Lwt.fail_with(
"You have both .node-version and .nvmrc with differing version strings!",
)
| (Some(version), Some(_))
| (Some(version), None)
| (None, Some(version)) => Lwt.return(version)
};
};

14
library/Nvmrc.re

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
exception Version_Not_Provided;
let getVersion = () => {
let%lwt cwd = Lwt_unix.getcwd();
let nvmrcFile = Filename.concat(cwd, ".nvmrc");
try%lwt (
Lwt_io.lines_of_file(nvmrcFile)
|> Lwt_stream.to_list
|> Lwt.map(List.hd)
|> Lwt.map(String.trim)
) {
| Unix.Unix_error(Unix.ENOENT, _, _) => Lwt.fail(Version_Not_Provided)
};
};
Loading…
Cancel
Save