diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a981e20e..e7ab801d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860 - Fix infinite loop when resolving inferred completions when several values in scope has the same name. https://github.com/rescript-lang/rescript-vscode/pull/869 - Fix crash when trying to print recursive polymorphic variants without a concrete definition. https://github.com/rescript-lang/rescript-vscode/pull/851 +- Fix `rescript-language-server --version` command. https://github.com/rescript-lang/rescript-vscode/pull/873 #### :nail_care: Polish diff --git a/server/src/cli.ts b/server/src/cli.ts index 4e7b7d451..749be0c6f 100644 --- a/server/src/cli.ts +++ b/server/src/cli.ts @@ -1,5 +1,6 @@ #!/usr/bin/env node import fs from "fs"; +import path from "path"; import server from "./server"; const args = process.argv.slice(2) @@ -23,7 +24,8 @@ Options: return server(false); case '--version': case '-v': - console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version); + const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json")).toString()) + console.log(version); process.exit(0); case '--help': case '-h': diff --git a/tools/CHANGELOG.md b/tools/CHANGELOG.md index 7674479dc..7e0c4752a 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/873 - 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..6e17a0851 100644 --- a/tools/src/Cli.res +++ b/tools/src/Cli.res @@ -5,18 +5,8 @@ @module("path") external dirname: string => string = "dirname" @val external __dirname: string = "__dirname" -module Buffer = { - type t - - @send external toString: t => string = "toString" -} - type processEnvOptions = {stdio?: string} -type spawnSyncResult = { - stdout: Buffer.t, - stderr: Buffer.t, - status: Js.Null.t, -} +type spawnSyncResult = {status: Js.Null.t} @module("child_process") external spawnSync: (string, array, option) => spawnSyncResult = @@ -89,9 +79,14 @@ 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 { + let packageJson = join([__dirname, "..", "package.json"]) + switch readFileSync(packageJson)->Js.Json.parseExn->Js.Json.decodeObject { | 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(dict) => + switch dict->Js.Dict.get("version") { + | Some(version) => logAndExit(~log=version, ~code=0) + | None => logAndExit(~log="error: failed to find version in package.json", ~code=1) + } } | _ => logAndExit(~log=help, ~code=1) }