mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-09-20 02:48:04 +03:00
introduce dlib.construct
for safe object cosntruction
This commit is contained in:
parent
83c1d872d7
commit
1fbd29bc66
@ -117,22 +117,23 @@
|
||||
l.forEach workspacePaths
|
||||
(wPath: makeWorkspaceProjectInfo tree wPath parentInfo)));
|
||||
|
||||
makeWorkspaceProjectInfo = tree: wsRelPath: parentInfo: {
|
||||
inherit subsystem;
|
||||
name =
|
||||
(getPackageJson "${tree.fullPath}/${wsRelPath}").name
|
||||
or "${parentInfo.name}/${wsRelPath}";
|
||||
relPath = dlib.sanitizeRelativePath "${tree.relPath}/${wsRelPath}";
|
||||
translators =
|
||||
l.unique
|
||||
(
|
||||
(lib.filter (trans: l.elem trans ["package-lock" "yarn-lock"]) parentInfo.translators)
|
||||
++ (getTranslatorNames "${tree.fullPath}/${wsRelPath}")
|
||||
);
|
||||
subsystemInfo = {
|
||||
workspaceParent = tree.relPath;
|
||||
makeWorkspaceProjectInfo = tree: wsRelPath: parentInfo:
|
||||
dlib.construct.discoveredProject {
|
||||
inherit subsystem;
|
||||
name =
|
||||
(getPackageJson "${tree.fullPath}/${wsRelPath}").name
|
||||
or "${parentInfo.name}/${wsRelPath}";
|
||||
relPath = dlib.sanitizeRelativePath "${tree.relPath}/${wsRelPath}";
|
||||
translators =
|
||||
l.unique
|
||||
(
|
||||
(lib.filter (trans: l.elem trans ["package-lock" "yarn-lock"]) parentInfo.translators)
|
||||
++ (getTranslatorNames "${tree.fullPath}/${wsRelPath}")
|
||||
);
|
||||
subsystemInfo = {
|
||||
workspaceParent = tree.relPath;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
discoverInternal = {
|
||||
tree,
|
||||
@ -160,7 +161,7 @@
|
||||
foundSubProjects alreadyDiscovered
|
||||
else let
|
||||
# project info of current directory
|
||||
currentProjectInfo = {
|
||||
currentProjectInfo = dlib.construct.discoveredProject {
|
||||
inherit subsystem;
|
||||
inherit (tree) relPath;
|
||||
name = tree.files."package.json".jsonContent.name or tree.relPath;
|
||||
|
18
src/lib/construct.nix
Normal file
18
src/lib/construct.nix
Normal file
@ -0,0 +1,18 @@
|
||||
# constructors to have at least some kind of `type` safety
|
||||
{lib}: {
|
||||
discoveredProject = {
|
||||
name,
|
||||
relPath,
|
||||
subsystem,
|
||||
subsystemInfo,
|
||||
translators,
|
||||
}: {
|
||||
inherit
|
||||
name
|
||||
relPath
|
||||
subsystem
|
||||
subsystemInfo
|
||||
translators
|
||||
;
|
||||
};
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
inherit
|
||||
calcInvalidationHash
|
||||
callViaEnv
|
||||
construct
|
||||
containsMatchingFile
|
||||
dirNames
|
||||
discoverers
|
||||
@ -34,8 +35,9 @@
|
||||
};
|
||||
|
||||
# other libs
|
||||
translators = import ./translators.nix {inherit dlib lib;};
|
||||
construct = import ./construct.nix {inherit lib;};
|
||||
discoverers = import ../discoverers {inherit config dlib lib;};
|
||||
translators = import ./translators.nix {inherit dlib lib;};
|
||||
|
||||
parseUtils = import ./parsing.nix {inherit lib;};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user