Merge pull request #50 from DavHau/dev

nodejs builder/translator and CLI improvements
This commit is contained in:
DavHau 2021-11-11 21:49:43 +07:00 committed by GitHub
commit e909fb1cb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 24 deletions

View File

@ -448,4 +448,7 @@ class AddCommand(Command):
defaultNix.write(template)
print(f"Created {output}/default.nix")
print(f"Created {output}/dream-lock.json")
print(f"Created {output}/dream-lock.json")
if config['isRepo']:
sp.run(f"git add -N {output}".split())

View File

@ -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()

View File

@ -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:

View File

@ -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
@ -59,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):

View File

@ -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";