diff --git a/CHANGELOG.md b/CHANGELOG.md index efcfa340a..650e493ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Proper default for `"uncurried"` in V11 projects. https://github.com/rescript-lang/rescript-vscode/pull/867 - Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860 +- Fix `rescript-language-server --version` command. https://github.com/rescript-lang/rescript-vscode/pull/853 #### :nail_care: Polish diff --git a/server/src/cli.ts b/server/src/cli.ts index 4e7b7d451..fae2d9042 100644 --- a/server/src/cli.ts +++ b/server/src/cli.ts @@ -1,7 +1,5 @@ #!/usr/bin/env node -import fs from "fs"; -import server from "./server"; - +const server = require("./server") const args = process.argv.slice(2) const help = `ReScript Language Server @@ -23,7 +21,7 @@ Options: return server(false); case '--version': case '-v': - console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version); + console.log(require('../package.json').version); process.exit(0); case '--help': case '-h': diff --git a/tools/CHANGELOG.md b/tools/CHANGELOG.md index 7674479dc..106ee5dec 100644 --- a/tools/CHANGELOG.md +++ b/tools/CHANGELOG.md @@ -23,4 +23,5 @@ #### :bug: Bug Fix - Fix tagged variant for `Module` and add attr to interface files. https://github.com/rescript-lang/rescript-vscode/pull/866 +- Fix `rescript-tools --version` command. https://github.com/rescript-lang/rescript-vscode/pull/853 - Fix output truncate when run `rescript-tools doc path/to/file.res` in a separate process. https://github.com/rescript-lang/rescript-vscode/pull/868 diff --git a/tools/src/Cli.res b/tools/src/Cli.res index 0dfcc046d..d275fd1c9 100644 --- a/tools/src/Cli.res +++ b/tools/src/Cli.res @@ -1,6 +1,6 @@ @@directive("#!/usr/bin/env node") -@module("fs") external readFileSync: string => string = "readFileSync" +@val external require: string => Js.Dict.t = "require" @variadic @module("path") external join: array => string = "join" @module("path") external dirname: string => string = "dirname" @val external __dirname: string = "__dirname" @@ -89,9 +89,9 @@ switch args->Belt.List.fromArray { } | list{"-h" | "--help"} => logAndExit(~log=help, ~code=0) | list{"-v" | "--version"} => - switch readFileSync("./package.json")->Js.Json.parseExn->Js.Json.decodeObject { + switch require("../package.json")->Js.Dict.get("version") { | None => logAndExit(~log="error: failed to find version in package.json", ~code=1) - | Some(dict) => logAndExit(~log=dict->Js.Dict.unsafeGet("version"), ~code=0) + | Some(version) => logAndExit(~log=version, ~code=0) } | _ => logAndExit(~log=help, ~code=1) }