Merge pull request #257121 from NyCodeGHG/update-pgrok

pgrok: move to node-packages.nix
This commit is contained in:
Robert Schütz 2023-09-26 16:51:29 +00:00 committed by GitHub
commit cef748b8bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 3466 additions and 8575 deletions

View file

@ -191,6 +191,7 @@
, "patch-package"
, "peerflix"
, "peerflix-server"
, {"pgrok-build-deps": "../../tools/networking/pgrok/build-deps"}
, "pkg"
, "pm2"
, "pnpm"

File diff suppressed because it is too large Load diff

View file

@ -1,11 +0,0 @@
diff --git a/package.json b/package.json
index 35d34c5..82eda74 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
{
"name": "pgrokd",
+ "version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build --outDir=../cli/dist --emptyOutDir",

View file

@ -0,0 +1,38 @@
{
"name": "pgrokd",
"scripts": {
"dev": "vite",
"build": "tsc && vite build --outDir=dist --emptyOutDir",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
},
"version": "1.4.0",
"dependencies": {
"axios": "~1.4.0",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"react-router-dom": "~6.15.0",
"@headlessui/react": "~1.7.17",
"@heroicons/react": "~2.0.18",
"@tailwindcss/forms": "~0.5.4",
"@trivago/prettier-plugin-sort-imports": "~4.2.0",
"@types/node": "~20.5.1",
"@types/react": "~18.2.15",
"@types/react-dom": "~18.2.7",
"@typescript-eslint/eslint-plugin": "~6.0.0",
"@typescript-eslint/parser": "~6.0.0",
"@vitejs/plugin-react": "~4.0.3",
"autoprefixer": "~10.4.15",
"code-inspector-plugin": "v0.1.9",
"eslint": "~8.45.0",
"eslint-plugin-import": "~2.28.0",
"eslint-plugin-react": "~7.33.2",
"eslint-plugin-react-hooks": "~4.6.0",
"eslint-plugin-react-refresh": "~0.4.3",
"eslint-plugin-unicorn": "~48.0.1",
"postcss": "~8.4.28",
"prettier": "~3.0.2",
"tailwindcss": "~3.3.3",
"typescript": "~5.0.2",
"vite": "~4.4.5"
}
}

View file

@ -3,23 +3,22 @@
, callPackage
, fetchFromGitHub
}:
let
buildGoModule rec {
pname = "pgrok";
version = "1.4.0";
src = fetchFromGitHub {
owner = "pgrok";
repo = "pgrok";
rev = "v${version}";
hash = "sha256-2k3XLXmf1Xnx4HvS7sD/aq+78Z4I7uY4djV958n5TX4=";
};
web = callPackage ./web.nix { inherit src version; };
in
buildGoModule {
pname = "pgrok";
inherit version src;
vendorHash = "sha256-M0xVHRh9NKPxmUEmx1dDQUZc8aXcdAfHisQAnt72RdY=";
outputs = [ "out" "server" "web" ];
outputs = [ "out" "server" ];
web = callPackage ./web.nix { inherit src version; };
ldflags = [
"-s"
@ -43,7 +42,6 @@ buildGoModule {
postInstall = ''
moveToOutput bin/pgrokd $server
cp -r ${web} $web
'';
passthru.updateScript = ./update.sh;

File diff suppressed because it is too large Load diff

View file

@ -1,58 +1,40 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix wget nix-prefetch-github moreutils jq prefetch-npm-deps nodejs
# adapted from https://github.com/NixOS/nixpkgs/blob/f4ffbe5ecb8039816f2dae60526e0a47f65a2b4e/pkgs/servers/memos/update.sh
#!nix-shell -i bash -p nix curl nix-update jq
set -euo pipefail
nix-update
cd "$(dirname "$0")"
nixpkgs=../../../..
node_packages="$nixpkgs/pkgs/development/node-packages"
pgrok="$nixpkgs/pkgs/tools/networking/pgrok"
TARGET_VERSION_REMOTE=$(curl -s https://api.github.com/repos/pgrok/pgrok/releases/latest | jq -r ".tag_name")
TARGET_VERSION=${TARGET_VERSION_REMOTE#v}
if [[ "$UPDATE_NIX_OLD_VERSION" == "$TARGET_VERSION" ]]; then
echo "pgrok is up-to-date: ${UPDATE_NIX_OLD_VERSION}"
exit 0
fi
extractVendorHash() {
original="${1?original hash missing}"
result="$(nix-build -A pgrok.goModules 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
[ -z "$result" ] && { echo "$original"; } || { echo "$result"; }
}
replaceHash() {
old="${1?old hash missing}"
new="${2?new hash missing}"
awk -v OLD="$old" -v NEW="$new" '{
if (i=index($0, OLD)) {
$0 = substr($0, 1, i-1) NEW substr($0, i+length(OLD));
}
print $0;
}' ./pkgs/tools/networking/pgrok/default.nix | sponge ./pkgs/tools/networking/pgrok/default.nix
}
# change version number
sed -e "s/version =.*;/version = \"$TARGET_VERSION\";/g" \
-i ./pkgs/tools/networking/pgrok/default.nix
# update hash
SRC_HASH="$(nix-instantiate --eval -A pgrok.src.outputHash | tr -d '"')"
NEW_HASH="$(nix-prefetch-github pgrok pgrok --rev v$TARGET_VERSION | jq -r .hash)"
replaceHash "$SRC_HASH" "$NEW_HASH"
GO_HASH="$(nix-instantiate --eval -A pgrok.vendorHash | tr -d '"')"
EMPTY_HASH="$(nix-instantiate --eval -A lib.fakeHash | tr -d '"')"
replaceHash "$GO_HASH" "$EMPTY_HASH"
replaceHash "$EMPTY_HASH" "$(extractVendorHash "$GO_HASH")"
# update src yarn lock
SRC_FILE_BASE="https://raw.githubusercontent.com/pgrok/pgrok/v$TARGET_VERSION"
pushd ./pkgs/tools/networking/pgrok
wget -q "$SRC_FILE_BASE/pgrokd/web/package.json"
npm install --package-lock-only
rm package.json*
NPM_HASH=$(prefetch-npm-deps ./package-lock.json)
popd
# replace ^ versions with ~, replace outdir to dist
curl https://raw.githubusercontent.com/pgrok/pgrok/main/pgrokd/web/package.json \
| jq "{name,scripts,version: \"${TARGET_VERSION}\",dependencies: (.dependencies + .devDependencies) }" \
| sed -e 's/"\^/"~/g' -e 's/\.\.\/cli\/dist/dist/g' \
> "$pgrok/build-deps/package.json.new"
old_deps="$(jq '.dependencies' "$pgrok/build-deps/package.json")"
new_deps="$(jq '.dependencies' "$pgrok/build-deps/package.json.new")"
if [[ "$old_deps" == "$new_deps" ]]; then
echo "package.json dependencies not changed, do simple version change"
sed -e '/^ "pgrok-build-deps/,+3 s/version = ".*"/version = "'"$TARGET_VERSION"'"/' \
--in-place "$node_packages"/node-packages.nix
mv build-deps/package.json{.new,}
else
echo "package.json dependencies changed, updating nodePackages"
mv build-deps/package.json{.new,}
./"$node_packages"/generate.sh
fi
sed -i -E -e "s#npmDepsHash = \".*\"#npmDepsHash = \"$NPM_HASH\"#" ./pkgs/tools/networking/pgrok/web.nix

View file

@ -1,29 +1,30 @@
{ buildNpmPackage
, src
{ src
, version
, nodejs
, nodePackages
, stdenvNoCC
}:
buildNpmPackage {
name = "pgrok-web";
inherit src version;
sourceRoot = "${src.name}/pgrokd/web";
let
build-deps = nodePackages."pgrok-build-deps-../../tools/networking/pgrok/build-deps";
in
stdenvNoCC.mkDerivation {
pname = "pgrok-web";
inherit version;
src = "${src}/pgrokd/web";
npmDepsHash = "sha256-f4pDBoG6sTJE3aUknqUvHHpBR9KWo/B4YMrWHkGbvA8=";
nativeBuildInputs = [ nodejs ];
# Upstream doesn't have a lockfile
postPatch = ''
cp ${./package-lock.json} ./package-lock.json
substituteInPlace ./package.json \
--replace "../cli/dist" "$out"
'';
buildPhase = ''
runHook preBuild
cp ${./build-deps/package.json} package.json
ln -s ${build-deps}/lib/node_modules/pgrokd/node_modules node_modules
npm run build
runHook postBuild
'';
patches = [
./add_version_to_package.json.patch
];
dontInstall = true;
dontFixup = true;
NODE_OPTIONS = "--openssl-legacy-provider";
npmPackFlags = [ "--ignore-scripts" ];
}
installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';
}