vencord: refactor to use pnpm.fetchDeps

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2024-08-05 10:16:14 +02:00
parent c32bd049ad
commit 29bc58a302
No known key found for this signature in database
GPG Key ID: E13DFD4B47127951
3 changed files with 43 additions and 5970 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +1,61 @@
{ buildNpmPackage
{ stdenv
, fetchFromGitHub
, lib
, git
, nodejs
, pnpm
, esbuild
, nix-update-script
, buildWebExtension ? false
}:
let
version = "1.9.5";
gitHash = "5bd10c8";
in
buildNpmPackage rec {
stdenv.mkDerivation (finalAttrs: {
pname = "vencord";
inherit version;
version = "1.9.5";
src = fetchFromGitHub {
owner = "Vendicated";
repo = "Vencord";
rev = "v${version}";
hash = "sha256-7eJkdcZX4D6PUnnpY+iucWWZx9/ned8z/zA0M5TRcaY=";
rev = "v${finalAttrs.version}";
# Allow Vencord to query the Git commit during build
leaveDotGit = true;
hash = "sha256-0FwUQZoaelo96CC95o9CAInIS740f1jx8CgSB6FKfB0=";
};
ESBUILD_BINARY_PATH = lib.getExe (esbuild.overrideAttrs (final: _: {
version = "0.15.18";
src = fetchFromGitHub {
owner = "evanw";
repo = "esbuild";
rev = "v${final.version}";
hash = "sha256-b9R1ML+pgRg9j2yrkQmBulPuLHYLUQvW+WTyR/Cq6zE=";
};
vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ=";
}));
pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname src;
# Supresses an error about esbuild's version.
npmRebuildFlags = [ "|| true" ];
hash = "sha256-X7oMA8/P1Uf4bBI+Hu1y1REl70QGIc6rQrXj/vG1Cyo=";
};
makeCacheWritable = true;
npmDepsHash = "sha256-GTjL6cjYPoa1ohtqslxDskCN9tKuu1OP1ZWIWtFx+E0=";
npmFlags = [ "--legacy-peer-deps" ];
npmBuildScript = if buildWebExtension then "buildWeb" else "build";
npmBuildFlags = [ "--" "--standalone" "--disable-updater" ];
nativeBuildInputs = [
git
nodejs
pnpm.configHook
];
prePatch = ''
cp ${./package-lock.json} ./package-lock.json
chmod +w ./package-lock.json
env = {
ESBUILD_BINARY_PATH = lib.getExe (esbuild.overrideAttrs (final: _: {
version = "0.15.18";
src = fetchFromGitHub {
owner = "evanw";
repo = "esbuild";
rev = "v${final.version}";
hash = "sha256-b9R1ML+pgRg9j2yrkQmBulPuLHYLUQvW+WTyR/Cq6zE=";
};
vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ=";
}));
VENCORD_REMOTE = "${finalAttrs.src.owner}/${finalAttrs.src.repo}";
};
buildPhase = ''
runHook preBuild
pnpm run ${if buildWebExtension then "buildWeb" else "build"} \
-- --standalone --disable-updater
runHook postBuild
'';
VENCORD_HASH = gitHash;
VENCORD_REMOTE = "${src.owner}/${src.repo}";
installPhase =
if buildWebExtension then ''
cp -r dist/chromium-unpacked/ $out
@ -54,7 +63,7 @@ buildNpmPackage rec {
cp -r dist/ $out
'';
passthru.updateScript = ./update.sh;
passthru.updateScript = nix-update-script { };
meta = with lib; {
description = "Vencord web extension";
@ -62,4 +71,4 @@ buildNpmPackage rec {
license = licenses.gpl3Only;
maintainers = with maintainers; [ FlafyDev NotAShelf Scrumplex ];
};
}
})

View File

@ -1,24 +0,0 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq common-updater-scripts prefetch-npm-deps nodejs
set -eou pipefail
pkgDir="$(dirname "$(readlink -f "$0")")"
tempDir=$(mktemp -d)
ghTags=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} "https://api.github.com/repos/Vendicated/Vencord/tags")
latestTag=$(echo "$ghTags" | jq -r .[0].name)
gitHash=$(echo "$ghTags" | jq -r .[0].commit.sha)
pushd "$tempDir"
curl "https://raw.githubusercontent.com/Vendicated/Vencord/$latestTag/package.json" -o package.json
npm install --legacy-peer-deps -f
npmDepsHash=$(prefetch-npm-deps ./package-lock.json)
popd
update-source-version vencord "${latestTag#v}"
sed -E 's#\bgitHash = ".*?"#gitHash = "'"${gitHash:0:7}"'"#' -i "$pkgDir/package.nix"
sed -E 's#\bnpmDepsHash = ".*?"#npmDepsHash = "'"$npmDepsHash"'"#' -i "$pkgDir/package.nix"
cp "$tempDir/package-lock.json" "$pkgDir/package-lock.json"