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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
{
lib,
buildGo126Module,
fetchFromGitHub,
_experimental-update-script-combinators,
versionCheckHook,
nix-update-script,
writeShellApplication,
nix,
gnugrep,
gnused,
}:
let
buildGoModule = buildGo126Module;
in
buildGoModule (finalAttrs: {
pname = "typescript";
version = "7.0.2";
__structuredAttrs = true;
src = fetchFromGitHub {
owner = "microsoft";
repo = "typescript";
tag = "v${finalAttrs.version}";
hash = "sha256-j1AY4sf/Jb6uwOah35lrYooc7BnSeaZ2NO6Fx1zMj60=";
};
modRoot = "tsc";
vendorHash = "sha256-q6dMb2ab4uZ3GTrcA7v2JzfmOM+ZzBcJN6gKOpLfM/k=";
tags = [
# Prevent LSP issues. In embed mode, "Go to Definition" fails for built-in types:
# - https://github.com/microsoft/typescript-go/pull/4197
# - https://github.com/microsoft/typescript-go/pull/3840
"noembed"
];
ldflags = [
"-s"
"-w"
];
env.CGO_ENABLED = 0;
subPackages = [
"cmd/tsgo"
];
# When built with the "noembed" tag, the executable must be under "lib/${pname}/" to resolve its paths.
postInstall = ''
lib_dir="$out/lib/${finalAttrs.pname}"
mkdir -p "$lib_dir"
cp -r internal/bundled/libs/. "$lib_dir"
mv "$out/bin/tsgo" "$lib_dir/tsc"
ln -s "$lib_dir/tsc" "$out/bin/tsc"
'';
nativeInstallCheckInputs = [
versionCheckHook
];
doInstallCheck = true;
passthru = {
updateScript = _experimental-update-script-combinators.sequence [
(nix-update-script {
extraArgs = [
"--use-github-releases"
"--version-regex=^v(7\\.[\\d.]+)$"
"--src-only"
];
})
(lib.getExe (writeShellApplication {
name = "typescript-go-version-updater";
runtimeInputs = [
nix
gnugrep
gnused
];
text = ''
new_src="$(nix-build --attr 'pkgs.typescript_7.src' --no-out-link)"
new_go_major_minor="$(grep --only-matching --perl-regexp '^go \K([0-9]+\.[0-9]+)' "$new_src/tsc/go.mod")"
sed -i -E "s/buildGo[0-9]+Module/buildGo''${new_go_major_minor//./}Module/g" '${toString ./package.nix}'
'';
}))
# Update vendorHash
(nix-update-script {
extraArgs = [ "--version=skip" ];
})
];
};
meta = {
description = "Superset of JavaScript that compiles to clean JavaScript output";
homepage = "https://www.typescriptlang.org/";
changelog = "https://github.com/microsoft/TypeScript/releases/tag/v${finalAttrs.version}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
kachick
];
mainProgram = "tsc";
};
})
|