Skip to content

Revert "allow installing multiple modules from a single package (#33)" #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 37 additions & 63 deletions nupm/install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@ def install-scripts [
]: list<path> -> 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."
)
}

Expand All @@ -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<path> -> 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'
Expand All @@ -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"
Expand Down
9 changes: 0 additions & 9 deletions tests/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/packages/spam_module_nodefault/package.nuon

This file was deleted.

3 changes: 0 additions & 3 deletions tests/packages/spam_module_nodefault/src/nodefault/mod.nu

This file was deleted.