summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/re/rescript-language-server/package.nix
blob: 50854367dbbdec366f5444eb33c8e507bd92258d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
  lib,
  stdenv,
  buildNpmPackage,
  fetchFromGitHub,
  esbuild,
  nix-update-script,
  versionCheckHook,
  vscode-extensions,
}:
let
  inherit (vscode-extensions.chenglou92.rescript-vscode) rescript-editor-analysis;
  platformDir =
    if stdenv.hostPlatform.isLinux then
      "linux"
    else if stdenv.hostPlatform.isDarwin then
      "darwin"
    else if stdenv.hostPlatform.isFreeBSD then
      "freebsd"
    else if stdenv.hostPlatform.isWindows then
      "win32"
    else
      throw "Unsupported system: ${stdenv.system}";
in
buildNpmPackage (finalAttrs: {
  # These have the same source, and must be the same version.
  inherit (rescript-editor-analysis) src version;
  pname = "rescript-language-server";

  sourceRoot = "${finalAttrs.src.name}/server";

  npmDepsFetcherVersion = 2;
  npmDepsHash = "sha256-BUR/gln9yyKGa05FvxOF6vIcCz8BCQWGr/fzfmOPdj0=";

  strictDeps = true;
  nativeBuildInputs = [ esbuild ];

  # Tries to do funny things (install all packages for the entire repo) if you don't override it. This is just a copy paste
  # from the package.json.
  buildPhase = ''
    runHook preBuild

    # https://github.com/rescript-lang/rescript-vscode/blob/1.72.0/package.json#L286
    esbuild src/cli.ts --bundle --sourcemap --outfile=out/cli.js --format=cjs --platform=node --loader:.node=file --minify

    runHook postBuild
  '';

  postInstall = ''
    DIR="$out/lib/node_modules/@rescript/language-server/analysis_binaries/${platformDir}"

    mkdir -p "$DIR"
    ln -s ${lib.getExe rescript-editor-analysis} "$DIR"/rescript-editor-analysis
  '';

  nativeInstallCheckInputs = [
    versionCheckHook
  ];
  doInstallCheck = true;

  passthru.updateScript = nix-update-script {
    extraArgs = [
      "--version-regex"
      "([0-9]+\\.[0-9]+\\.[0-9]+)"
    ];
  };

  meta = {
    description = "ReScript Language Server";
    homepage = "https://github.com/rescript-lang/rescript-vscode/tree/${finalAttrs.version}/server";
    changelog = "https://github.com/rescript-lang/rescript-vscode/releases/tag/${finalAttrs.version}";
    mainProgram = "rescript-language-server";
    license = lib.licenses.mit;
    # https://github.com/rescript-lang/rescript-vscode/blob/1.62.0/CONTRIBUTING.md?plain=1#L186
    platforms = with lib.platforms; linux ++ darwin ++ windows ++ freebsd;
    maintainers = [ ];
  };
})