some fixes for package-json and package-lock

- fix missing git & ssh in pacakge-json translator
- package-lock: if dependency missing, raise warning instead of error.
This commit is contained in:
DavHau 2022-03-30 16:17:55 +07:00
parent 28b890821f
commit ec30059894
2 changed files with 25 additions and 3 deletions

View File

@ -11,8 +11,10 @@
# nixpkgs dependenies
bash,
coreutils,
git,
jq,
nodePackages,
openssh,
writeScriptBin,
...
}:
@ -20,8 +22,10 @@
[
bash
coreutils
git
jq
nodePackages.npm
openssh
]
''
# accroding to the spec, the translator reads the input from a json file
@ -30,10 +34,14 @@
# read the json input
outputFile=$(jq '.outputFile' -c -r $jsonInput)
source=$(jq '.source' -c -r $jsonInput)
npmArgs=$(jq '.npmArgs' -c -r $jsonInput)
relPath=$(jq '.project.relPath' -c -r $jsonInput)
npmArgs=$(jq '.project.subsystemInfo.npmArgs' -c -r $jsonInput)
cp -r $source/* ./
chmod -R +w ./
newSource=$(pwd)
cd $relPath
rm -rf package-lock.json
if [ "$(jq '.project.subsystemInfo.noDev' -c -r $jsonInput)" == "true" ]; then
@ -45,7 +53,7 @@
npm install --package-lock-only $npmArgs
fi
jq ".source = \"$(pwd)\"" -c -r $jsonInput > $TMPDIR/newJsonInput
jq ".source = \"$newSource\"" -c -r $jsonInput > $TMPDIR/newJsonInput
cd $WORKDIR
${translators.translatorsV2.nodejs.pure.package-lock.translateBin} $TMPDIR/newJsonInput

View File

@ -86,12 +86,26 @@
selfScopeDeps = parentScopeDeps // dependencies;
requires = pdata.requires or {};
dependencies = pdata.dependencies or {};
filteredRequires =
l.filterAttrs
(name: spec:
if selfScopeDeps ? ${name}
then true
else
l.trace
''
WARNING: could not find dependency ${name} in package-lock.json
This might be expected for bundled dependencies of sub-dependencies.
''
false)
requires;
in
pdata
// {
depsExact =
lib.forEach
(lib.attrNames requires)
(lib.attrNames filteredRequires)
(reqName: {
name = reqName;
version = getVersion selfScopeDeps."${reqName}";