chore: npm translator: optimizations and fixes

- don't use expensive replaceRootSources
- don't mess with sources, just use data from package-lock
This commit is contained in:
DavHau 2022-09-05 11:24:51 +02:00
parent 1d182f0808
commit 12267818db
2 changed files with 26 additions and 20 deletions

View File

@ -20,6 +20,7 @@
moreutils, moreutils,
nodePackages, nodePackages,
openssh, openssh,
python3,
writeScriptBin, writeScriptBin,
... ...
}: }:
@ -32,6 +33,7 @@
moreutils moreutils
nodePackages.npm nodePackages.npm
openssh openssh
python3
] ]
'' ''
# accroding to the spec, the translator reads the input from a json file # accroding to the spec, the translator reads the input from a json file
@ -42,6 +44,9 @@
name=$(jq '.project.name' -c -r $jsonInput) name=$(jq '.project.name' -c -r $jsonInput)
version=$(jq '.project.version' -c -r $jsonInput) version=$(jq '.project.version' -c -r $jsonInput)
npmArgs=$(jq '.project.subsystemInfo.npmArgs' -c -r $jsonInput) npmArgs=$(jq '.project.subsystemInfo.npmArgs' -c -r $jsonInput)
if [ "$npmArgs" == "null" ]; then
npmArgs=
fi
if [ "$version" = "null" ]; then if [ "$version" = "null" ]; then
candidate="$name" candidate="$name"
@ -49,7 +54,6 @@
candidate="$name@$version" candidate="$name@$version"
fi fi
pushd $TMPDIR pushd $TMPDIR
newSource=$(pwd) newSource=$(pwd)
@ -62,26 +66,14 @@
# call package-lock translator # call package-lock translator
${subsystems.nodejs.translators.package-lock.translateBin} $TMPDIR/newJsonInput ${subsystems.nodejs.translators.package-lock.translateBin} $TMPDIR/newJsonInput
# generate source info for main package # get resolved package version
url=$(npm view $candidate dist.tarball) export version=$(npm view $candidate version)
hash=$(npm view $candidate dist.integrity)
echo " # set correct package version under `packages`
{ cat $outputFile \
\"type\": \"http\", | python3 ${./fixup-dream-lock.py} $TMPDIR/sourceInfo.json \
\"url\": \"$url\", | sponge $outputFile
\"hash\": \"$hash\"
}
" > $TMPDIR/sourceInfo.json
# add main package source info to dream-lock.json
${apps.callNixWithD2N} eval --json "
with dream2nix.utils.dreamLock;
replaceRootSources {
dreamLock = l.fromJSON (l.readFile \"$outputFile\");
newSourceRoot = l.fromJSON (l.readFile \"$TMPDIR/sourceInfo.json\");
}
" \
| sponge "$outputFile"
''; '';
# inherit options from package-lock translator # inherit options from package-lock translator

View File

@ -0,0 +1,14 @@
import json
import os
import sys
lock = json.load(sys.stdin)
version = os.environ.get('version')
# set default package version correctly
defaultPackage = lock['_generic']['defaultPackage']
lock['_generic']['packages'] = {
defaultPackage: version
}
print(json.dumps(lock, indent=2))