From 9302d24fc3f19a72a4512fb61b4ebde99faefaa7 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 10 Nov 2021 13:11:21 +0700 Subject: [PATCH 1/4] add name argument to package-lock translator --- .../nodejs/pure/package-lock/default.nix | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/translators/nodejs/pure/package-lock/default.nix b/src/translators/nodejs/pure/package-lock/default.nix index eca332c8..165e55c6 100644 --- a/src/translators/nodejs/pure/package-lock/default.nix +++ b/src/translators/nodejs/pure/package-lock/default.nix @@ -14,6 +14,7 @@ inputDirectories, inputFiles, + name, noDev, nodejs, ... @@ -73,8 +74,17 @@ utils.simpleTranslate translatorName { # values inputData = packageLockWithPinnedVersions; - mainPackageName = parsed.name; - mainPackageVersion = parsed.version; + + mainPackageName = + parsed.name or + (if name != "{automatic}" then name else + throw ( + "Could not identify package name. " + + "Please specify extra argument 'name'" + )); + + mainPackageVersion = parsed.version or "unknown"; + mainPackageDependencies = lib.mapAttrsToList (pname: pdata: @@ -82,7 +92,9 @@ (lib.filterAttrs (pname: pdata: ! (pdata.dev or false) || dev) parsedDependencies); + subsystemName = "nodejs"; + subsystemAttrs = { nodejsVersion = args.nodejs; }; # functions @@ -156,6 +168,16 @@ extraArgs = { + name = { + description = "The name of the main package"; + examples = [ + "react" + "@babel/code-frame" + ]; + default = "{automatic}"; + type = "argument"; + }; + noDev = { description = "Exclude development dependencies"; type = "flag"; From 6097051a5f0c6e572d2338e6d6983481d475bb4c Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 10 Nov 2021 13:11:33 +0700 Subject: [PATCH 2/4] automatically add new packages to git --- src/apps/cli/commands/add.py | 5 ++++- src/apps/cli/utils.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/apps/cli/commands/add.py b/src/apps/cli/commands/add.py index 691ffe88..3dc06832 100644 --- a/src/apps/cli/commands/add.py +++ b/src/apps/cli/commands/add.py @@ -448,4 +448,7 @@ class AddCommand(Command): defaultNix.write(template) print(f"Created {output}/default.nix") - print(f"Created {output}/dream-lock.json") \ No newline at end of file + print(f"Created {output}/dream-lock.json") + + if config['isRepo']: + sp.run(f"git add -N {output}") \ No newline at end of file diff --git a/src/apps/cli/utils.py b/src/apps/cli/utils.py index 9674dc10..36a25927 100644 --- a/src/apps/cli/utils.py +++ b/src/apps/cli/utils.py @@ -25,8 +25,10 @@ def find_repo_root(): with open(os.environ.get("dream2nixConfig")) as f: config = json.load(f) + config.["isRepo"] = False if config['repoName'] and config ['packagesDir']: config['packagesDir'] = f"{find_repo_root()}/{config['packagesDir']}" + config.["isRepo"] = True def checkLockJSON(lock): lock_schema_raw=open(dream2nix_src+"/specifications/dream-lock-schema.json").read() From 48af5f0ec1ad5c151e9ff672ae5d350e243bfe99 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 10 Nov 2021 14:05:51 +0700 Subject: [PATCH 3/4] nodejs builder: just exclude cyclic deps --- src/builders/nodejs/granular/default.nix | 20 -------------------- src/builders/nodejs/granular/fix-package.py | 6 ++++++ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/builders/nodejs/granular/default.nix b/src/builders/nodejs/granular/default.nix index 3dd93607..71a34f95 100644 --- a/src/builders/nodejs/granular/default.nix +++ b/src/builders/nodejs/granular/default.nix @@ -48,11 +48,6 @@ let b = builtins; - # tells if a dependency introduces a cycle - # -> needs to be built in a combined derivation - isCyclic = name: version: - (getCyclicDependencies name version) != []; - nodejsVersion = subsystemAttrs.nodejsVersion; nodejs = @@ -72,23 +67,8 @@ let lib.genAttrs versions (version: - if isCyclic name version - || b.elem name standalonePackageNames then - makeCombinedPackage name version - else makePackage name version)) packageVersions; - - makeCombinedPackage = name: version: - let - built = - buildPackageWithOtherBuilder { - inherit name version; - builder = builders.nodejs.node2nix; - inject = {}; - }; - in - built.defaultPackage; # Generates a derivation for a specific package name + version makePackage = name: version: diff --git a/src/builders/nodejs/granular/fix-package.py b/src/builders/nodejs/granular/fix-package.py index 61ec0cb4..ba958bd7 100644 --- a/src/builders/nodejs/granular/fix-package.py +++ b/src/builders/nodejs/granular/fix-package.py @@ -49,6 +49,12 @@ if 'dependencies' in package_json: if 'bundledDependencies' in package_json\ and pname in package_json['bundledDependencies']: continue + if pname not in available_deps: + print( + f"WARNING: Dependency {pname} wanted but not available. Ignoring.", + file=sys.stderr + ) + continue if available_deps[pname] != package_json['dependencies'][pname]: package_json['dependencies'][pname] = available_deps[pname] changed = True From 6d2a9fd95eb505b67ad8f0e7b92e8a3568d4a8ef Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 11 Nov 2021 19:08:25 +0700 Subject: [PATCH 4/4] nodejs buider: fix crash on empty string `bin` field --- src/apps/cli/commands/add.py | 2 +- src/apps/cli/utils.py | 4 ++-- src/builders/nodejs/granular/fix-package.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apps/cli/commands/add.py b/src/apps/cli/commands/add.py index 3dc06832..360456f2 100644 --- a/src/apps/cli/commands/add.py +++ b/src/apps/cli/commands/add.py @@ -451,4 +451,4 @@ class AddCommand(Command): print(f"Created {output}/dream-lock.json") if config['isRepo']: - sp.run(f"git add -N {output}") \ No newline at end of file + sp.run(f"git add -N {output}".split()) \ No newline at end of file diff --git a/src/apps/cli/utils.py b/src/apps/cli/utils.py index 36a25927..c0c0c701 100644 --- a/src/apps/cli/utils.py +++ b/src/apps/cli/utils.py @@ -25,10 +25,10 @@ def find_repo_root(): with open(os.environ.get("dream2nixConfig")) as f: config = json.load(f) - config.["isRepo"] = False + config["isRepo"] = False if config['repoName'] and config ['packagesDir']: config['packagesDir'] = f"{find_repo_root()}/{config['packagesDir']}" - config.["isRepo"] = True + config["isRepo"] = True def checkLockJSON(lock): lock_schema_raw=open(dream2nix_src+"/specifications/dream-lock-schema.json").read() diff --git a/src/builders/nodejs/granular/fix-package.py b/src/builders/nodejs/granular/fix-package.py index ba958bd7..de152bee 100644 --- a/src/builders/nodejs/granular/fix-package.py +++ b/src/builders/nodejs/granular/fix-package.py @@ -65,7 +65,7 @@ if 'dependencies' in package_json: ) # create symlinks for executables (bin entries from package.json) -if 'bin' in package_json: +if 'bin' in package_json and package_json['bin']: bin = package_json['bin'] if isinstance(bin, str):