nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 pnpm_9,
6 nodejs_22,
7 versionCheckHook,
8}:
9stdenv.mkDerivation rec {
10 pname = "tsx";
11 version = "4.19.3";
12
13 src = fetchFromGitHub {
14 owner = "privatenumber";
15 repo = "tsx";
16 tag = "v${version}";
17 hash = "sha256-wdv2oqJNc6U0Fyv4jT+0LUcYaDfodHk1vQZGMdyFF/E=";
18 };
19
20 pnpmDeps = pnpm_9.fetchDeps {
21 inherit pname version src;
22 fetcherVersion = 1;
23 hash = "sha256-57KDZ9cHb7uqnypC0auIltmYMmIhs4PWyf0HTRWEFiU=";
24 };
25
26 nativeBuildInputs = [
27 nodejs_22
28 pnpm_9.configHook
29 ];
30
31 buildInputs = [
32 nodejs_22
33 ];
34
35 patchPhase = ''
36 runHook prePatch
37
38 # by default pnpm builds the docs workspace and this was just
39 # the easiest way I found to stop that, as pnpmWorkspaces and
40 # other flags did not work
41 rm pnpm-workspace.yaml
42
43 # because tsx uses semantic-release, the package.json has a placeholder
44 # version number. this patches it to match the version of the nix package,
45 # which in turn is the release version in github.
46 substituteInPlace package.json --replace-fail "0.0.0-semantic-release" "${version}"
47
48 runHook postPatch
49 '';
50
51 buildPhase = ''
52 runHook preBuild
53
54 npm run build
55
56 # remove devDependencies that are only required to build
57 # and package the typescript code
58 pnpm prune --prod
59
60 # Clean up broken symlinks left behind by `pnpm prune`
61 # https://github.com/pnpm/pnpm/issues/3645
62 find node_modules -xtype l -delete
63
64 runHook postBuild
65 '';
66
67 installPhase = ''
68 runHook preInstall
69
70 mkdir -p $out/{bin,lib/tsx}
71 cp -r {dist,node_modules} $out/lib/tsx
72 chmod +x $out/lib/tsx/dist/cli.mjs
73 ln -s $out/lib/tsx/dist/cli.mjs $out/bin/tsx
74
75 runHook postInstall
76 '';
77
78 # 8 / 85 tests are failing, I do not know why, while regular usage shows no issues.
79 doCheck = false;
80 nativeInstallCheckInputs = [
81 versionCheckHook
82 ];
83 doInstallCheck = true;
84 versionCheckProgramArg = "--version";
85
86 meta = {
87 description = "TypeScript Execute (tsx): The easiest way to run TypeScript in Node.js";
88 homepage = "https://tsx.is";
89 license = lib.licenses.mit;
90 maintainers = [ lib.maintainers.sdedovic ];
91 mainProgram = "tsx";
92 };
93}