Skip to content

Commit 2f0949c

Browse files
committedMar 23, 2025
tsx: init at 4.19.3
1 parent 34fc9a0 commit 2f0949c

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
 

‎pkgs/by-name/ts/tsx/package.nix

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

0 commit comments

Comments
 (0)
Failed to load comments.