1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gnused common-updater-scripts jq prefetch-npm-deps
5 version
=$
(curl
${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -v -s https
://api.github.com
/repos
/detachhead
/basedpyright
/releases
/latest | jq
-r '.tag_name | sub("^v"; "")')
7 update-source-version basedpyright
"$version"
9 root
="$(dirname "$
(readlink
-f "$0")")"
10 FILE_PATH
="$root/package.nix"
11 REPO_URL_PREFIX
="https://github.com/detachhead/basedpyright/raw"
14 trap 'rm -rf "$TEMP_DIR"' EXIT
16 # Function to download `package-lock.json` for a given source path and update hash
18 local source_root_path
="$1"
19 local existing_hash
="$2"
21 # Formulate download URL
22 local download_url
="${REPO_URL_PREFIX}/v${version}${source_root_path}/package-lock.json"
24 # Download package-lock.json to temporary directory
25 curl
-fsSL -v -o "${TEMP_DIR}/package-lock.json" "$download_url"
27 # Calculate the new hash
29 new_hash
=$
(prefetch-npm-deps
"${TEMP_DIR}/package-lock.json")
31 # Update npmDepsHash in the original file
32 sed -i "s|$existing_hash|${new_hash}|" "$FILE_PATH"
35 while IFS
= read -r source_root_line
; do
36 [[ "$source_root_line" =~ sourceRoot
]] ||
continue
37 source_root_path
=$
(echo "$source_root_line" |
sed -e 's/^.*"${src.name}\(.*\)";.*$/\1/')
39 # Extract the current npmDepsHash for this sourceRoot
40 existing_hash
=$
(grep -A1 "$source_root_line" "$FILE_PATH" |
grep 'npmDepsHash' |
sed -e 's/^.*npmDepsHash = "\(.*\)";$/\1/')
42 # Call the function to download and update the hash
43 update_hash
"$source_root_path" "$existing_hash"