Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions pkgs/by-name/wr/wrangler/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,33 @@
autoPatchelfHook,
cacert,
llvmPackages,
jq,
moreutils,
musl,
xorg,
gitUpdater,
versionCheckHook,
}:

stdenv.mkDerivation (finalAttrs: {
pname = "wrangler";
version = "3.80.1";
version = "4.16.0";

src = fetchFromGitHub {
owner = "cloudflare";
repo = "workers-sdk";
rev = "wrangler@${finalAttrs.version}";
hash = "sha256-9ClosoDIT+yP2dvNenHW2RSxLimOT3znXD+Pq+N6cQA=";
hash = "sha256-H/ds5NfOjyTZ4AcsCAP0wbalgOljOUtLSjkjEn+atVk=";
};

pnpmDeps = pnpm_9.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-8EItfBV2n2rnXPCTYjDZlr/tdlEn8YOdIzOsj35w5gQ=";
inherit (finalAttrs)
pname
version
src
postPatch
;
hash = "sha256-msIXeN8t8Dm3RUkw4woZIMn7wXxw/0jVl8oFmkPJbrA=";
};

passthru.updateScript = gitUpdater { rev-prefix = "wrangler@"; };
Expand All @@ -45,15 +54,22 @@ stdenv.mkDerivation (finalAttrs: {
makeWrapper
nodejs
pnpm_9.configHook
jq
moreutils
]
++ lib.optionals (stdenv.hostPlatform.isLinux) [
autoPatchelfHook
];

# pnpm packageManager version in workers-sdk root package.json may not match nixpkgs
postPatch = ''
jq 'del(.packageManager)' package.json | sponge package.json
'';

# @cloudflare/vitest-pool-workers wanted to run a server as part of the build process
# so I simply removed it
postBuild = ''
rm -fr packages/vitest-pool-workers
mv packages/vitest-pool-workers packages/~vitest-pool-workers
NODE_ENV="production" pnpm --filter workers-shared run build
NODE_ENV="production" pnpm --filter miniflare run build
NODE_ENV="production" pnpm --filter wrangler run build
Expand All @@ -65,19 +81,17 @@ stdenv.mkDerivation (finalAttrs: {
# - the build process builds a version of miniflare which is used by wrangler; for this reason, the miniflare package is copied also
# - pnpm stores all content in the top-level node_modules directory, but it is linked to from a node_modules directory inside wrangler
# - as they are linked via symlinks, the relative location of them on the filesystem should be maintained
# - Update: Now we're copying everything over due to broken symlink errors
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/lib $out/lib/packages/wrangler
rm -rf node_modules/typescript node_modules/eslint node_modules/prettier node_modules/bin node_modules/.bin node_modules/**/bin node_modules/**/.bin
mv packages/~vitest-pool-workers packages/vitest-pool-workers
cp -r fixtures $out/lib
cp -r packages $out/lib
cp -r node_modules $out/lib
cp -r packages/miniflare $out/lib/packages
cp -r packages/workers-tsconfig $out/lib/packages
cp -r packages/workers-shared $out/lib/packages
cp -r packages/wrangler/node_modules $out/lib/packages/wrangler
cp -r packages/wrangler/templates $out/lib/packages/wrangler
cp -r packages/wrangler/wrangler-dist $out/lib/packages/wrangler
cp -r tools $out/lib/tools
rm -rf node_modules/typescript node_modules/eslint node_modules/prettier node_modules/bin node_modules/.bin node_modules/**/bin node_modules/**/.bin
rm -rf $out/lib/**/bin $out/lib/**/.bin
cp -r packages/wrangler/bin $out/lib/packages/wrangler
NODE_PATH_ARRAY=( "$out/lib/node_modules" "$out/lib/packages/wrangler/node_modules" )
makeWrapper ${lib.getExe nodejs} $out/bin/wrangler \
--inherit-argv0 \
Expand All @@ -87,6 +101,12 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';

nativeInstallCheckInputs = [
versionCheckHook
];
versionCheckProgramArg = "-v";
Copy link
Member

@ezrizhu ezrizhu May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't need this line since it defaults to -v is what they meant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this ensures that the version is checked.
Even if it's set by default.
For me, this allows for better control;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i meant just line 102 the versionCheckProgramArg, but yeah sure.

doInstallCheck = true;
Comment on lines +104 to +108

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help, I do appreciate being explicit and yes it is intentional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some programs like to print their full path somewhere in --help, which would make the check obsolete. So it's always a good idea to specify the argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like --version should take precedence over --help to minimize the likelihood of this, but I agree it is ultimately best to just be explicit.


meta = {
description = "Command-line interface for all things Cloudflare Workers";
homepage = "https://github.com/cloudflare/workers-sdk#readme";
Expand Down