-
-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyright: repackage using buildNpmPackage
- Loading branch information
Showing
8 changed files
with
314 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ lib, buildNpmPackage, fetchFromGitHub, runCommand, jq }: | ||
|
||
let | ||
version = "1.1.359"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "Microsoft"; | ||
repo = "pyright"; | ||
rev = "${version}"; | ||
hash = "sha256-gqMAfmYjYO6D9sRu+uJv4yJ/+csioFAwsUPBDF29VDs="; | ||
}; | ||
|
||
patchedPackageJSON = runCommand "package.json" { } '' | ||
${jq}/bin/jq ' | ||
.devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser")) | ||
| .scripts = { } | ||
' ${src}/package.json > $out | ||
''; | ||
|
||
pyright-root = buildNpmPackage { | ||
pname = "pyright-root"; | ||
inherit version src; | ||
npmDepsHash = "sha256-63kUhKrxtJhwGCRBnxBfOFXs2ARCNn+OOGu6+fSJey4="; | ||
dontNpmBuild = true; | ||
postPatch = '' | ||
cp ${patchedPackageJSON} ./package.json | ||
cp ${./package-lock.json} ./package-lock.json | ||
''; | ||
installPhase = '' | ||
runHook preInstall | ||
cp -r . "$out" | ||
runHook postInstall | ||
''; | ||
}; | ||
|
||
pyright-internal = buildNpmPackage { | ||
pname = "pyright-internal"; | ||
inherit version src; | ||
sourceRoot = "${src.name}/packages/pyright-internal"; | ||
npmDepsHash = "sha256-p2KamNFJ3sJHmJm0MEPhI8L/8zAVzfc9NYy24rAdFcQ="; | ||
dontNpmBuild = true; | ||
installPhase = '' | ||
runHook preInstall | ||
cp -r . "$out" | ||
runHook postInstall | ||
''; | ||
}; | ||
in | ||
buildNpmPackage rec { | ||
pname = "pyright"; | ||
inherit version src; | ||
|
||
sourceRoot = "${src.name}/packages/pyright"; | ||
npmDepsHash = "sha256-U7WdMIYg9U4fJ8YtDruMzloRS2BQAa2QWExle9uwPbU="; | ||
|
||
postPatch = '' | ||
chmod +w ../../ | ||
ln -s ${pyright-root}/node_modules ../../node_modules | ||
chmod +w ../pyright-internal | ||
ln -s ${pyright-internal}/node_modules ../pyright-internal/node_modules | ||
''; | ||
|
||
dontNpmBuild = true; | ||
|
||
passthru.updateScript = ./update.sh; | ||
|
||
meta = { | ||
changelog = "https://github.com/Microsoft/pyright/releases/tag/${version}"; | ||
description = "Type checker for the Python language"; | ||
homepage = "https://github.com/Microsoft/pyright"; | ||
license = lib.licenses.mit; | ||
mainProgram = "pyright"; | ||
maintainers = with lib.maintainers; [ kalekseev ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env nix-shell | ||
#!nix-shell -i bash -p curl gnused common-updater-scripts jq prefetch-npm-deps | ||
set -euo pipefail | ||
|
||
version=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s https://api.github.com/repos/microsoft/pyright/releases/latest | jq -r '.tag_name | sub("^v"; "")') | ||
|
||
update-source-version pyright "$version" | ||
|
||
root="$(dirname "$(readlink -f "$0")")" | ||
FILE_PATH="$root/package.nix" | ||
REPO_URL_PREFIX="https://github.com/microsoft/pyright/raw" | ||
TEMP_DIR=$(mktemp -d) | ||
|
||
trap 'rm -rf "$TEMP_DIR"' EXIT | ||
|
||
# Function to download `package-lock.json` for a given source path and update hash | ||
update_hash() { | ||
local source_root_path="$1" | ||
local existing_hash="$2" | ||
|
||
# Formulate download URL | ||
local download_url="${REPO_URL_PREFIX}/${version}${source_root_path}/package-lock.json" | ||
|
||
# Download package-lock.json to temporary directory | ||
curl -fsSL -o "${TEMP_DIR}/package-lock.json" "$download_url" | ||
|
||
# Calculate the new hash | ||
local new_hash | ||
new_hash=$(prefetch-npm-deps "${TEMP_DIR}/package-lock.json") | ||
|
||
# Update npmDepsHash in the original file | ||
sed -i "s|$existing_hash|${new_hash}|" "$FILE_PATH" | ||
} | ||
|
||
while IFS= read -r source_root_line; do | ||
[[ "$source_root_line" =~ sourceRoot ]] || continue | ||
source_root_path=$(echo "$source_root_line" | sed -e 's/^.*"${src.name}\(.*\)";.*$/\1/') | ||
|
||
# Extract the current npmDepsHash for this sourceRoot | ||
existing_hash=$(grep -A1 "$source_root_line" "$FILE_PATH" | grep 'npmDepsHash' | sed -e 's/^.*npmDepsHash = "\(.*\)";$/\1/') | ||
|
||
# Call the function to download and update the hash | ||
update_hash "$source_root_path" "$existing_hash" | ||
done < "$FILE_PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,7 +200,6 @@ | |
, "purescript-psa" | ||
, "purs-tidy" | ||
, "purty" | ||
, "pyright" | ||
, "remod-cli" | ||
, "reveal.js" | ||
, "rimraf" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters