fixes for yarn translator and node builder

This commit is contained in:
DavHau 2021-11-03 10:46:02 +07:00
parent aa81800846
commit b1cb420434
3 changed files with 87 additions and 40 deletions

View File

@ -113,6 +113,11 @@ let
pname = utils.sanitizeDerivationName name; pname = utils.sanitizeDerivationName name;
# only run build on the main package
runBuild =
packageName == mainPackageName
&& version == mainPackageVersion;
inherit dependenciesJson nodeDeps nodeSources version; inherit dependenciesJson nodeDeps nodeSources version;
src = getSource name version; src = getSource name version;
@ -270,6 +275,8 @@ let
else else
echo "$installScript" | bash echo "$installScript" | bash
fi fi
elif [ -n "$runBuild" ] && [ "$(jq '.scripts.build' ./package.json)" != "null" ]; then
npm run build
elif [ "$(jq '.scripts.postinstall' ./package.json)" != "null" ]; then elif [ "$(jq '.scripts.postinstall' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run postinstall npm --production --offline --nodedir=$nodeSources run postinstall
fi fi

View File

@ -22,15 +22,19 @@
}); });
fetched = hash: fetched = hash:
if lib.stringLength hash == 40 then let drv =
fetchurl { if lib.stringLength hash == 40 then
inherit url; fetchurl {
sha1 = hash; inherit url;
} sha1 = hash;
else }
fetchurl { else
inherit url hash; fetchurl {
}; inherit url hash;
};
in drv.overrideAttrs (old: {
name = lib.strings.sanitizeDerivationName old.name;
});
}; };
} }

View File

@ -25,9 +25,13 @@
b = builtins; b = builtins;
dev = ! noDev; dev = ! noDev;
optional = ! noOptional; optional = ! noOptional;
yarnLock = utils.readTextFile "${lib.elemAt inputDirectories 0}/yarn.lock";
packageJSON = b.fromJSON (b.readFile "${lib.elemAt inputDirectories 0}/package.json"); sourceDir = lib.elemAt inputDirectories 0;
parser = import ../yarn-lock/parser.nix { inherit lib; inherit (externals) nix-parsec;}; yarnLock = utils.readTextFile "${sourceDir}/yarn.lock";
packageJSON = b.fromJSON (b.readFile "${sourceDir}/package.json");
parser = import ../yarn-lock/parser.nix
{ inherit lib; inherit (externals) nix-parsec;};
tryParse = parser.parseLock yarnLock; tryParse = parser.parseLock yarnLock;
parsedLock = parsedLock =
if tryParse.type == "success" then if tryParse.type == "success" then
@ -36,7 +40,10 @@
let let
failureOffset = tryParse.value.offset; failureOffset = tryParse.value.offset;
in in
throw "parser failed at: \n${lib.substring failureOffset 50 tryParse.value.str}"; throw ''
parser failed at:
${lib.substring failureOffset 50 tryParse.value.str}
'';
in in
utils.simpleTranslate translatorName rec { utils.simpleTranslate translatorName rec {
@ -46,7 +53,10 @@
mainPackageName = mainPackageName =
packageJSON.name or packageJSON.name or
(if name != null then name else (if name != null then name else
throw "Could not identify package name. Please specify extra argument 'name'"); throw (
"Could not identify package name. "
+ "Please specify extra argument 'name'"
));
mainPackageVersion = packageJSON.version or "unknown"; mainPackageVersion = packageJSON.version or "unknown";
@ -89,10 +99,13 @@
dependencyObject.yarnName; dependencyObject.yarnName;
getName = dependencyObject: getName = dependencyObject:
let if lib.hasInfix "@git+" dependencyObject.yarnName then
version = lib.last (lib.splitString "@" dependencyObject.yarnName); lib.head (lib.splitString "@git+" dependencyObject.yarnName)
in else
lib.removeSuffix "@${version}" dependencyObject.yarnName; let
version = lib.last (lib.splitString "@" dependencyObject.yarnName);
in
lib.removeSuffix "@${version}" dependencyObject.yarnName;
getVersion = dependencyObject: getVersion = dependencyObject:
dependencyObject.version; dependencyObject.version;
@ -117,7 +130,8 @@
if ! dependenciesByOriginalID ? ${yarnName} then if ! dependenciesByOriginalID ? ${yarnName} then
# handle missing lock file entry # handle missing lock file entry
let let
versionMatch = b.match ''.*\^([[:digit:]|\.]+)'' versionSpec; versionMatch =
b.match ''.*\^([[:digit:]|\.]+)'' versionSpec;
in in
{ {
inherit name; inherit name;
@ -132,15 +146,21 @@
getSourceType = dependencyObject: getSourceType = dependencyObject:
if lib.hasInfix "@github:" dependencyObject.yarnName if lib.hasInfix "@github:" dependencyObject.yarnName
|| || (dependencyObject ? resolved
(dependencyObject ? resolved && lib.hasInfix
&& lib.hasInfix "codeload.github.com/" dependencyObject.resolved ) then "codeload.github.com/"
dependencyObject.resolved)
|| (lib.hasInfix "@git+" dependencyObject.yarnName) then
if dependencyObject ? integrity then if dependencyObject ? integrity then
b.trace "Warning: Using git despite integrity exists for ${getName dependencyObject}" b.trace (
"Warning: Using git despite integrity exists for"
+ "${getName dependencyObject}"
)
"git" "git"
else else
"git" "git"
else if lib.hasInfix "@link:" dependencyObject.yarnName then else if lib.hasInfix "@link:" dependencyObject.yarnName
|| lib.hasInfix "@file:" dependencyObject.yarnName then
"path" "path"
else else
"http"; "http";
@ -148,23 +168,38 @@
sourceConstructors = { sourceConstructors = {
git = dependencyObject: git = dependencyObject:
let if utils.identifyGitUrl dependencyObject.resolved then
gitUrlInfos = lib.splitString "/" dependencyObject.resolved; (utils.parseGitUrl dependencyObject.resolved) // {
rev = lib.elemAt gitUrlInfos 6; version = dependencyObject.version;
owner = lib.elemAt gitUrlInfos 3; }
repo = lib.elemAt gitUrlInfos 4; else
version = dependencyObject.version; let
in githubUrlInfos = lib.splitString "/" dependencyObject.resolved;
{ owner = lib.elemAt githubUrlInfos 3;
url = "https://github.com/${owner}/${repo}"; repo = lib.elemAt githubUrlInfos 4;
inherit rev version; rev = lib.elemAt githubUrlInfos 6;
}; version = dependencyObject.version;
in
{
url = "https://github.com/${owner}/${repo}";
inherit rev version;
};
path = dependencyObject: path = dependencyObject:
{ if lib.hasInfix "@link:" dependencyObject.yarnName then
version = dependencyObject.version; {
path = lib.last (lib.splitString "@link:" dependencyObject.yarnName); version = dependencyObject.version;
}; path =
lib.last (lib.splitString "@link:" dependencyObject.yarnName);
}
else if lib.hasInfix "@file:" dependencyObject.yarnName then
{
version = dependencyObject.version;
path =
lib.last (lib.splitString "@file:" dependencyObject.yarnName);
}
else
throw "unknown path format ${b.toJSON dependencyObject}";
http = dependencyObject: http = dependencyObject:
{ {
@ -175,7 +210,8 @@
dependencyObject.integrity dependencyObject.integrity
else else
let let
hash = lib.last (lib.splitString "#" dependencyObject.resolved); hash =
lib.last (lib.splitString "#" dependencyObject.resolved);
in in
if lib.stringLength hash == 40 then hash if lib.stringLength hash == 40 then hash
else else