mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-20 13:01:44 +03:00
imrpove nodejs discovery
- use dream-lock transaltor for packages without any dependencies - scan sub-directories of non-project dirs
This commit is contained in:
parent
d76407b4cd
commit
6fb2ec0e6a
@ -20,9 +20,16 @@ let
|
||||
getTranslatorNames = path:
|
||||
let
|
||||
nodes = l.readDir path;
|
||||
packageJson = l.fromJSON (l.readFile "${path}/package.json");
|
||||
in
|
||||
l.optionals (nodes ? "package-lock.json") [ "package-lock" ]
|
||||
++ l.optionals (nodes ? "yarn.lock") [ "yarn-lock" ]
|
||||
# if the package has no dependencies we use the
|
||||
# package-lock translator with `packageLock = null`
|
||||
++ l.optionals
|
||||
(! packageJson ? dependencies
|
||||
&& ! packageJson ? devDependencies)
|
||||
[ "package-lock" ]
|
||||
++ [ "package-json" ];
|
||||
|
||||
# returns the parsed package.json of a given directory
|
||||
@ -78,12 +85,21 @@ let
|
||||
# twice.
|
||||
alreadyDiscovered ? {},
|
||||
}:
|
||||
let
|
||||
foundSubProjects = alreadyDiscovered:
|
||||
l.flatten
|
||||
((l.mapAttrsToList
|
||||
(dname: dir: discoverInternal {
|
||||
inherit alreadyDiscovered;
|
||||
tree = dir;
|
||||
})
|
||||
(tree.directories or {})));
|
||||
in
|
||||
# skip if not a nodajs project
|
||||
if alreadyDiscovered ? "${tree.relPath}"
|
||||
|| ! tree ? files."package.json"
|
||||
then
|
||||
|| ! tree ? files."package.json" then
|
||||
# this will be cleaned by `flatten` for sub-directories
|
||||
[]
|
||||
foundSubProjects alreadyDiscovered
|
||||
else
|
||||
let
|
||||
|
||||
@ -130,13 +146,7 @@ let
|
||||
# Thanks to `alreadyDiscovered`, workspace projects won't be discovered
|
||||
# a second time.
|
||||
++
|
||||
l.flatten
|
||||
((l.mapAttrsToList
|
||||
(dname: dir: discoverInternal {
|
||||
alreadyDiscovered = alreadyDiscovered';
|
||||
tree = dir;
|
||||
})
|
||||
(tree.directories or {})));
|
||||
(foundSubProjects alreadyDiscovered');
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -53,13 +53,23 @@ let
|
||||
getPackageLock = project:
|
||||
let
|
||||
# returns the parsed package-lock.json for a given project
|
||||
fileRelPath =
|
||||
dirRelPath =
|
||||
if project ? subsystemInfo.workspaceParent then
|
||||
"${project.subsystemInfo.workspaceParent}/package-lock.json"
|
||||
"${project.subsystemInfo.workspaceParent}"
|
||||
else
|
||||
"${project.relPath}/package-lock.json";
|
||||
"${project.relPath}";
|
||||
|
||||
packageJson =
|
||||
(tree.getNodeFromPath "${dirRelPath}/package.json").jsonContent;
|
||||
|
||||
hasNoDependencies =
|
||||
! packageJson ? dependencies && ! packageJson ? devDependenices;
|
||||
|
||||
in
|
||||
(tree.getNodeFromPath fileRelPath).jsonContent;
|
||||
if hasNoDependencies then
|
||||
null
|
||||
else
|
||||
(tree.getNodeFromPath "${dirRelPath}/package-lock.json").jsonContent;
|
||||
|
||||
getPackageJson = project:
|
||||
let
|
||||
@ -110,7 +120,11 @@ let
|
||||
|
||||
dev = ! noDev;
|
||||
|
||||
parsed = packageLock;
|
||||
packageLockDeps =
|
||||
if packageLock == null then
|
||||
{}
|
||||
else
|
||||
packageLock.dependencies or {};
|
||||
|
||||
workspacePackageJson =
|
||||
l.genAttrs
|
||||
@ -126,8 +140,7 @@ let
|
||||
json.version)
|
||||
workspacePackageJson;
|
||||
|
||||
rootDependencies =
|
||||
packageLock.dependencies or {};
|
||||
rootDependencies = packageLockDeps;
|
||||
|
||||
packageJsonDeps =
|
||||
packageJson.dependencies or {} // packageJson.devDependencies or {};
|
||||
@ -135,7 +148,7 @@ let
|
||||
parsedDependencies =
|
||||
l.filterAttrs
|
||||
(name: dep: packageJsonDeps ? "${name}")
|
||||
parsed.dependencies or {};
|
||||
packageLockDeps;
|
||||
|
||||
identifyGitSource = dependencyObject:
|
||||
# TODO: when integrity is there, and git url is github then use tarball instead
|
||||
@ -223,7 +236,7 @@ let
|
||||
));
|
||||
|
||||
packages =
|
||||
{ "${defaultPackage}" = parsed.version or "unknown"; }
|
||||
{ "${defaultPackage}" = packageJson.version or "unknown"; }
|
||||
// workspacePackages;
|
||||
|
||||
mainPackageDependencies =
|
||||
|
Loading…
Reference in New Issue
Block a user