From 12c0d08222a1da36bbcc5a39818722b718f9847d Mon Sep 17 00:00:00 2001 From: amtoine Date: Mon, 11 Dec 2023 15:47:54 +0100 Subject: [PATCH] Revert "allow installing multiple modules from a single package (#33)" This reverts commit f4288262bc7941dcd2d25908c82295c4a9a158f4. --- nupm/install.nu | 100 +++++++----------- tests/mod.nu | 9 -- .../spam_module_nodefault/package.nuon | 6 -- .../src/nodefault/mod.nu | 3 - 4 files changed, 37 insertions(+), 81 deletions(-) delete mode 100644 tests/packages/spam_module_nodefault/package.nuon delete mode 100644 tests/packages/spam_module_nodefault/src/nodefault/mod.nu diff --git a/nupm/install.nu b/nupm/install.nu index 0f1eb5a..952490c 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -38,20 +38,19 @@ def install-scripts [ ]: list -> nothing { each {|script| let src_path = $pkg_dir | path join $script - let dst_path = $scripts_dir | path join $script if ($src_path | path type) != file { throw-error "script_not_found" $"Script ($src_path) does not exist" } - if $force { - rm --recursive --force $dst_path - } - - if ($dst_path | path type) == file and (not $force) { - throw-error "script_already_installed" ( + if (($scripts_dir + | path join ($script | path basename) + | path type) == file + and (not $force) + ) { + throw-error "package_already_installed" ( $"Script ($src_path) is already installed in" - + $" ($scripts_dir). Use `--force` to override it." + + $" ($scripts_dir). Use `--force` to override the package." ) } @@ -62,41 +61,6 @@ def install-scripts [ null } -# Install list of modules into a directory -# -# Input: Modules taken from 'package.nuon' -def install-modules [ - pkg_dir: path # Package directory - modules_dir: path # Target directory where to install - --force(-f): bool # Overwrite already installed modules -]: list -> nothing { - each {|module| - let src_path = $pkg_dir | path join $module - let dst_path = $modules_dir | path join ($module | path split | last) - - if not ($src_path | path exists) { - throw-error "module_not_found" $"Module ($src_path) does not exist" - } - - if $force { - rm --recursive --force $dst_path - } - - if ($dst_path | path exists) and (not $force) { - throw-error "module_already_installed" ( - $"Module ($src_path) is already installed in" - + $" ($modules_dir). Use `--force` to override it." - ) - } - - log debug $"installing module `($src_path)` to `($modules_dir)`" - cp -r $src_path $modules_dir - } - - null -} - - # Install package from a directory containing 'project.nuon' def install-path [ pkg_dir: path # Directory (hopefully) containing 'package.nuon' @@ -110,34 +74,44 @@ def install-path [ match $package.type { "module" => { - let default_name = $package.name + let mod_dir = $pkg_dir | path join $package.name - if ($pkg_dir | path join $default_name | path exists) { - [ $default_name ] - } else { - [] + if ($mod_dir | path type) != dir { + throw-error "invalid_module_package" ( + $"Module package '($package.name)' does not" + + $" contain directory '($package.name)'" + ) } - | append ($package.modules? | default []) - | install-modules $pkg_dir (module-dir --ensure) --force $force - $package.scripts? - | default [] - | install-scripts $pkg_dir (script-dir --ensure) --force $force + let module_dir = module-dir --ensure + let destination = $module_dir | path join $package.name + + if $force { + rm --recursive --force $destination + } + + if ($destination | path type) == dir { + throw-error "package_already_installed" ( + $"Package ($package.name) is already installed." + + "Use `--force` to override the package" + ) + } + + cp --recursive $mod_dir $module_dir + + if $package.scripts? != null { + log debug $"installing scripts for package ($package.name)" + + $package.scripts + | install-scripts $pkg_dir (script-dir --ensure) --force $force + } }, "script" => { - let default_name = $"($package.name).nu" + log debug $"installing scripts for package ($package.name)" - if ($pkg_dir | path join $default_name | path exists) { - [ $default_name ] - } else { - [] - } + [ ($pkg_dir | path join $"($package.name).nu") ] | append ($package.scripts? | default []) | install-scripts $pkg_dir (script-dir --ensure) --force $force - - $package.modules? - | default [] - | install-modules $pkg_dir (module-dir --ensure) --force $force }, "custom" => { let build_file = $pkg_dir | path join "build.nu" diff --git a/tests/mod.nu b/tests/mod.nu index dae5e0d..dc6980f 100644 --- a/tests/mod.nu +++ b/tests/mod.nu @@ -36,15 +36,6 @@ export def install-module [] { } } -export def install-module-nodefault [] { - with-nupm-home { - nupm install --path tests/packages/spam_module_nodefault - - assert installed [modules nodefault ] - assert installed [modules nodefault mod.nu] - } -} - export def install-custom [] { with-nupm-home { nupm install --path tests/packages/spam_custom diff --git a/tests/packages/spam_module_nodefault/package.nuon b/tests/packages/spam_module_nodefault/package.nuon deleted file mode 100644 index 03ab982..0000000 --- a/tests/packages/spam_module_nodefault/package.nuon +++ /dev/null @@ -1,6 +0,0 @@ -{ - name: spam_module_nodefault, - type: module, - version: "0.1.0" - modules: src/nodefault -} diff --git a/tests/packages/spam_module_nodefault/src/nodefault/mod.nu b/tests/packages/spam_module_nodefault/src/nodefault/mod.nu deleted file mode 100644 index 7b31588..0000000 --- a/tests/packages/spam_module_nodefault/src/nodefault/mod.nu +++ /dev/null @@ -1,3 +0,0 @@ -export def main [] { - "No default module!" -}