fix updating packages + add test

This commit is contained in:
DavHau 2021-12-09 15:47:08 +07:00
parent 728677b654
commit 87b6959039
5 changed files with 51 additions and 9 deletions

View File

@ -33,14 +33,19 @@ class UpdateCommand(Command):
if self.io.is_interactive():
self.line(f"\n{self.description}\n")
# handle if package name given
if config['packagesDir'] and '/' not in self.argument("name"):
dreamLockFile =\
os.path.abspath(
f"{config['packagesDir']}/{self.argument('name')}/dream-lock.json")
attribute_name = self.argument('name')
# handle if path to dream-lock.json given
else:
dreamLockFile = os.path.abspath(self.argument("name"))
if not dreamLockFile.endswith('dream-lock.json'):
dreamLockFile = os.path.abspath(dreamLockFile + "/dream-lock.json")
attribute_name = dreamLockFile.split('/')[-2]
# parse dream lock
with open(dreamLockFile) as f:
@ -76,6 +81,10 @@ class UpdateCommand(Command):
mainPackageName = lock['_generic']['mainPackageName']
mainPackageVersion = lock['_generic']['mainPackageVersion']
mainPackageSource = lock['sources'][mainPackageName][mainPackageVersion]
mainPackageSource.update(dict(
pname = mainPackageName,
version = mainPackageVersion,
))
updatedSourceSpec = callNixFunction(
"fetchers.updateSource",
source=mainPackageSource,
@ -88,7 +97,8 @@ class UpdateCommand(Command):
sp.run(
[
sys.executable, f"{cli_py}", "add", tmpDreamLock.name, "--force",
"--target", os.path.abspath(os.path.dirname(dreamLockFile))
"--target", os.path.abspath(os.path.dirname(dreamLockFile)),
"--attribute-name", attribute_name
]
+ lock['_generic']['translatorParams'].split()
)

View File

@ -31,7 +31,9 @@ rec {
let
fetcher = fetchers."${type}";
argsKeep = b.removeAttrs args [ "reComputeHash" ];
fetcherOutputs = fetcher.outputs argsKeep;
fetcherOutputs =
fetcher.outputs
(b.removeAttrs argsKeep [ "dir" "hash" "type" ]);
in
argsKeep
# if the hash was not provided, calculate hash on the fly (impure)
@ -46,14 +48,10 @@ rec {
newVersion,
...
}:
let
fetcher = fetchers."${source.type}";
argsKeep = b.removeAttrs source [ "hash" ];
in
constructSource (argsKeep // {
constructSource (source // {
reComputeHash = true;
} // {
"${fetcher.versionField}" = newVersion;
"${fetchers."${source.type}".versionField}" = newVersion;
});
# fetch a source defined via a dream lock source spec

View File

@ -16,6 +16,8 @@ rec {
versionField = "version";
defaultUpdater = "npmNewestReleaseVersion";
# becuase some node packages contain submodules like `@hhhtj/draw.io`
# the amount of arguments can vary and a custom parser is needed
parseParams = params:

View File

@ -105,7 +105,11 @@ let
getMainPackageSource = dreamLock:
dreamLock.sources
."${dreamLock._generic.mainPackageName}"
."${dreamLock._generic.mainPackageVersion}";
."${dreamLock._generic.mainPackageVersion}"
// {
pname = dreamLock._generic.mainPackageName;
version = dreamLock._generic.mainPackageVersion;
};
getSource = fetchedSources: pname: version:
if fetchedSources ? "${pname}"."${version}"

View File

@ -0,0 +1,28 @@
{
lib,
# dream2nix
apps,
utils,
...
}:
let
l = lib // builtins;
cli = apps.cli.program;
in
utils.writePureShellScript
[]
''
${cli} add npm:eslint/8.4.0 \
--no-default-nix \
--translator package-json \
--attribute-name eslint \
--arg name="{automatic}" \
--arg noDev=true \
--arg nodejs=14
${cli} update eslint --to-version 8.4.1
''