mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-19 20:41:54 +03:00
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:
parent
1d182f0808
commit
12267818db
@ -20,6 +20,7 @@
|
||||
moreutils,
|
||||
nodePackages,
|
||||
openssh,
|
||||
python3,
|
||||
writeScriptBin,
|
||||
...
|
||||
}:
|
||||
@ -32,6 +33,7 @@
|
||||
moreutils
|
||||
nodePackages.npm
|
||||
openssh
|
||||
python3
|
||||
]
|
||||
''
|
||||
# accroding to the spec, the translator reads the input from a json file
|
||||
@ -42,6 +44,9 @@
|
||||
name=$(jq '.project.name' -c -r $jsonInput)
|
||||
version=$(jq '.project.version' -c -r $jsonInput)
|
||||
npmArgs=$(jq '.project.subsystemInfo.npmArgs' -c -r $jsonInput)
|
||||
if [ "$npmArgs" == "null" ]; then
|
||||
npmArgs=
|
||||
fi
|
||||
|
||||
if [ "$version" = "null" ]; then
|
||||
candidate="$name"
|
||||
@ -49,7 +54,6 @@
|
||||
candidate="$name@$version"
|
||||
fi
|
||||
|
||||
|
||||
pushd $TMPDIR
|
||||
newSource=$(pwd)
|
||||
|
||||
@ -62,26 +66,14 @@
|
||||
# call package-lock translator
|
||||
${subsystems.nodejs.translators.package-lock.translateBin} $TMPDIR/newJsonInput
|
||||
|
||||
# generate source info for main package
|
||||
url=$(npm view $candidate dist.tarball)
|
||||
hash=$(npm view $candidate dist.integrity)
|
||||
echo "
|
||||
{
|
||||
\"type\": \"http\",
|
||||
\"url\": \"$url\",
|
||||
\"hash\": \"$hash\"
|
||||
}
|
||||
" > $TMPDIR/sourceInfo.json
|
||||
# get resolved package version
|
||||
export version=$(npm view $candidate version)
|
||||
|
||||
# set correct package version under `packages`
|
||||
cat $outputFile \
|
||||
| python3 ${./fixup-dream-lock.py} $TMPDIR/sourceInfo.json \
|
||||
| sponge $outputFile
|
||||
|
||||
# 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
|
||||
|
14
src/subsystems/nodejs/translators/npm/fixup-dream-lock.py
Normal file
14
src/subsystems/nodejs/translators/npm/fixup-dream-lock.py
Normal 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))
|
Loading…
Reference in New Issue
Block a user