nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 112 lines 2.6 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 pnpm_10, 6 fetchPnpmDeps, 7 pnpmConfigHook, 8 nodejs_22, 9 versionCheckHook, 10 nix-update-script, 11}: 12let 13 pnpm' = pnpm_10.override { nodejs = nodejs_22; }; 14in 15stdenv.mkDerivation (finalAttrs: { 16 pname = "tsx"; 17 version = "4.21.0"; 18 19 src = fetchFromGitHub { 20 owner = "privatenumber"; 21 repo = "tsx"; 22 tag = "v${finalAttrs.version}"; 23 hash = "sha256-vlVRq637l84xi9Og0ryzYuu+1b/eBq13jQJIptY0u0o="; 24 }; 25 26 pnpmDeps = fetchPnpmDeps { 27 inherit (finalAttrs) 28 pname 29 version 30 src 31 ; 32 pnpm = pnpm'; 33 fetcherVersion = 1; 34 hash = "sha256-6ZizQtZC43yXrz634VXksRCKGkDKryICvT3Q+JCuIEw="; 35 }; 36 37 nativeBuildInputs = [ 38 nodejs_22 39 pnpmConfigHook 40 pnpm' 41 ]; 42 43 buildInputs = [ 44 nodejs_22 45 ]; 46 47 patchPhase = '' 48 runHook prePatch 49 50 # by default pnpm builds the docs workspace and this was just 51 # the easiest way I found to stop that, as pnpmWorkspaces and 52 # other flags did not work 53 rm pnpm-workspace.yaml 54 55 # because tsx uses semantic-release, the package.json has a placeholder 56 # version number. this patches it to match the version of the nix package, 57 # which in turn is the release version in github. 58 substituteInPlace package.json --replace-fail "0.0.0-semantic-release" "${finalAttrs.version}" 59 60 runHook postPatch 61 ''; 62 63 buildPhase = '' 64 runHook preBuild 65 66 pnpm run build 67 68 # remove unneeded files 69 find dist -type f \( -name '*.cts' -or -name '*.mts' -or -name '*.ts' \) -delete 70 71 # remove devDependencies that are only required to build 72 # and package the typescript code 73 CI=true pnpm prune --prod 74 75 # Clean up broken symlinks left behind by `pnpm prune` 76 # https://github.com/pnpm/pnpm/issues/3645 77 find node_modules -xtype l -delete 78 79 runHook postBuild 80 ''; 81 82 installPhase = '' 83 runHook preInstall 84 85 mkdir -p $out/{bin,lib/tsx} 86 cp -r {dist,node_modules} $out/lib/tsx 87 chmod +x $out/lib/tsx/dist/cli.mjs 88 ln -s $out/lib/tsx/dist/cli.mjs $out/bin/tsx 89 90 runHook postInstall 91 ''; 92 93 # 8 / 85 tests are failing, I do not know why, while regular usage shows no issues. 94 doCheck = false; 95 nativeInstallCheckInputs = [ 96 versionCheckHook 97 ]; 98 doInstallCheck = true; 99 100 passthru.updateScript = nix-update-script { }; 101 102 meta = { 103 description = "TypeScript Execute (tsx): The easiest way to run TypeScript in Node.js"; 104 homepage = "https://tsx.is"; 105 license = lib.licenses.mit; 106 maintainers = with lib.maintainers; [ 107 sdedovic 108 higherorderlogic 109 ]; 110 mainProgram = "tsx"; 111 }; 112})