mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-13 08:06:18 +03:00
yarn-translator: enable workspace support
This commit is contained in:
parent
07a2e7cd9f
commit
193b852534
@ -73,7 +73,7 @@ let
|
||||
translators =
|
||||
l.unique
|
||||
(
|
||||
(lib.filter (trans: trans == "package-lock") parentInfo.translators)
|
||||
(lib.filter (trans: l.elem trans ["package-lock" "yarn-lock"]) parentInfo.translators)
|
||||
++ (getTranslatorNames "${tree.fullPath}/${wsRelPath}")
|
||||
);
|
||||
subsystemInfo = {
|
||||
|
@ -23,7 +23,7 @@ let
|
||||
...
|
||||
}@args: let
|
||||
|
||||
# filteredProjects = nodejsUtils.filterProjects projects;
|
||||
filteredProjects = nodejsUtils.filterProjects projects;
|
||||
|
||||
parser = import ./parser.nix { inherit lib; };
|
||||
|
||||
@ -41,9 +41,9 @@ let
|
||||
yarnLock =
|
||||
parser.parse (getYarnLock proj).content;
|
||||
relPath = proj.relPath;
|
||||
# workspaces = proj.subsystemInfo.workspaces or [];
|
||||
workspaces = proj.subsystemInfo.workspaces or [];
|
||||
})
|
||||
projects;
|
||||
filteredProjects;
|
||||
|
||||
in
|
||||
allProjectsTranslated;
|
||||
@ -58,7 +58,7 @@ let
|
||||
# subsystem specific
|
||||
yarnLock,
|
||||
relPath,
|
||||
# workspaces,
|
||||
workspaces,
|
||||
|
||||
# extraArgs
|
||||
name,
|
||||
@ -71,24 +71,22 @@ let
|
||||
b = builtins;
|
||||
dev = ! noDev;
|
||||
|
||||
defaultPackage =
|
||||
if name != "{automatic}" then
|
||||
name
|
||||
else
|
||||
packageJson.name or (throw (
|
||||
"Could not identify package name. "
|
||||
+ "Please specify extra argument 'name'"
|
||||
));
|
||||
|
||||
packageJson =
|
||||
(tree.getNodeFromPath "package.json").jsonContent;
|
||||
|
||||
packageJsonDeps = nodejsUtils.getPackageJsonDeps packageJson noDev;
|
||||
|
||||
# workspacesPackageJson = utils.getWorkspacePackageJson tree workspaces;
|
||||
workspacesPackageJson = nodejsUtils.getWorkspacePackageJson tree workspaces;
|
||||
|
||||
# workspaceYarnEntries = workspace
|
||||
# l.map
|
||||
# (ws:
|
||||
# let
|
||||
# json =
|
||||
# (tree.getNodeFromPath "${wsRelPath}/package.json").jsonContent;
|
||||
# in {
|
||||
|
||||
# }
|
||||
# )
|
||||
# workspacesPackageJson."${workspace}".;
|
||||
in
|
||||
|
||||
utils.simpleTranslate2
|
||||
@ -97,6 +95,48 @@ let
|
||||
...
|
||||
}: let
|
||||
|
||||
makeWorkspaceExtraObject = workspace: let
|
||||
json = workspacesPackageJson."${workspace}";
|
||||
name = json.name or workspace;
|
||||
version = json.version or "unknown";
|
||||
in
|
||||
{
|
||||
inherit name version;
|
||||
|
||||
dependencies =
|
||||
l.mapAttrsToList
|
||||
(depName: semVer: let
|
||||
yarnName = "${depName}@${semVer}";
|
||||
depObject = objectsByKey.yarnName."${yarnName}";
|
||||
in
|
||||
if exportedWorkspacePackages ? "${depName}"
|
||||
then
|
||||
{
|
||||
name = depName;
|
||||
version = exportedWorkspacePackages."${depName}";
|
||||
}
|
||||
else {name = depName; version = depObject.version;})
|
||||
(nodejsUtils.getPackageJsonDeps json noDev);
|
||||
|
||||
sourceSpec = {
|
||||
type = "path";
|
||||
path = workspace;
|
||||
rootName = defaultPackage;
|
||||
rootVersion = packageJson.version or "unknown";
|
||||
};
|
||||
};
|
||||
|
||||
extraObjects = l.map makeWorkspaceExtraObject workspaces;
|
||||
|
||||
exportedWorkspacePackages =
|
||||
l.listToAttrs
|
||||
(l.map
|
||||
(wsObject:
|
||||
l.nameValuePair
|
||||
wsObject.name
|
||||
wsObject.version)
|
||||
extraObjects);
|
||||
|
||||
getSourceType = rawObj: finalObj: let
|
||||
dObj = rawObj;
|
||||
in
|
||||
@ -133,20 +173,11 @@ let
|
||||
|
||||
in rec {
|
||||
|
||||
inherit translatorName;
|
||||
|
||||
defaultPackage =
|
||||
if name != "{automatic}" then
|
||||
name
|
||||
else
|
||||
packageJson.name or (throw (
|
||||
"Could not identify package name. "
|
||||
+ "Please specify extra argument 'name'"
|
||||
));
|
||||
inherit defaultPackage extraObjects translatorName;
|
||||
|
||||
exportedPackages =
|
||||
{ "${defaultPackage}" = packageJson.version or "unknown"; };
|
||||
# // (nodejsUtils.getWorkspacePackages tree workspaces);
|
||||
{ "${defaultPackage}" = packageJson.version or "unknown"; }
|
||||
// exportedWorkspacePackages;
|
||||
|
||||
subsystemName = "nodejs";
|
||||
|
||||
@ -176,7 +207,16 @@ let
|
||||
lib.head split;
|
||||
|
||||
version = rawObj: finalObj:
|
||||
rawObj.version;
|
||||
if l.hasInfix "@git+" rawObj.yarnName
|
||||
then
|
||||
let
|
||||
split = l.splitString "@git+" rawObj.yarnName;
|
||||
gitUrl = l.last split;
|
||||
in
|
||||
# l.strings.sanitizeDerivationName
|
||||
"${rawObj.version}@git+${gitUrl}"
|
||||
|
||||
else rawObj.version;
|
||||
|
||||
dependencies = rawObj: finalObj: let
|
||||
dependencies = let
|
||||
|
@ -62,7 +62,7 @@ let
|
||||
merged
|
||||
// {"${keyFunc finalObj.rawObj finalObj}" = finalObj;})
|
||||
{}
|
||||
finalObjects)
|
||||
finalObjects')
|
||||
final.keys;
|
||||
|
||||
|
||||
@ -86,13 +86,13 @@ let
|
||||
|
||||
allDependencies = l.foldl'
|
||||
(result: finalObj:
|
||||
lib.recursiveUpdate
|
||||
result
|
||||
{
|
||||
"${finalObj.name}" = {
|
||||
"${finalObj.version}" = finalObj;
|
||||
};
|
||||
})
|
||||
lib.recursiveUpdate
|
||||
result
|
||||
{
|
||||
"${finalObj.name}" = {
|
||||
"${finalObj.version}" = finalObj;
|
||||
};
|
||||
})
|
||||
{}
|
||||
finalObjects;
|
||||
|
||||
@ -132,10 +132,21 @@ let
|
||||
cyclicDependencies =
|
||||
# TODO: inefficient! Implement some kind of early cutoff
|
||||
let
|
||||
depGraphWithFakeRoot =
|
||||
l.recursiveUpdate
|
||||
dependencyGraph
|
||||
{
|
||||
__fake-entry.__fake-version =
|
||||
l.mapAttrsToList
|
||||
dlib.nameVersionPair
|
||||
exportedPackages;
|
||||
};
|
||||
|
||||
findCycles = node: prevNodes: cycles:
|
||||
let
|
||||
|
||||
children = dependencyGraph."${node.name}"."${node.version}";
|
||||
children =
|
||||
depGraphWithFakeRoot."${node.name}"."${node.version}";
|
||||
|
||||
cyclicChildren =
|
||||
lib.filter
|
||||
@ -169,8 +180,8 @@ let
|
||||
cyclesList =
|
||||
findCycles
|
||||
(dlib.nameVersionPair
|
||||
defaultPackage
|
||||
exportedPackages."${defaultPackage}")
|
||||
"__fake-entry"
|
||||
"__fake-version")
|
||||
{}
|
||||
[];
|
||||
in
|
||||
|
Loading…
Reference in New Issue
Block a user