Skip to content

Commit

Permalink
nodejs persistence: use npm prefix to install bins into data dir / en…
Browse files Browse the repository at this point in the history
…v_add_path with $data_dir
  • Loading branch information
rrelmy committed Mar 25, 2017
1 parent 19d45fd commit 912fbe8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bucket/nodejs.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"hash": "28a2b3cec0fd883ef203d5d1bfdc22f4e87b581145825c8cebaae635117849d3"
}
},
"env_add_path": "nodejs",
"env_add_path": ["nodejs", "$data_dir"],
"persist": "nodejs/node_modules",
"post_install": "
# Remove npmrc that makes global modules get installed in AppData\\Roaming\\npm
if(test-path $dir\\nodejs\\node_modules\\npm\\npmrc) { rm $dir\\nodejs\\node_modules\\npm\\npmrc }
# Set npm prefix to install module inside $data_dir
Set-Content -Value \"prefix=$data_dir\" -Path $data_dir\\node_modules\\npm\\npmrc
npm update -g",
"checkver": {
"url": "https://nodejs.org/en/download/current/",
Expand Down
20 changes: 16 additions & 4 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,21 @@ function find_dir_or_subdir($path, $dir) {
return [string]::join(';', $fixed), $removed
}

function prepare_env_path ($path) {
if ($path -like '*$*') {

This comment has been minimized.

Copy link
@rrelmy

rrelmy Mar 25, 2017

Author Owner

Any better ideas to add the ability to add paths inside the persistent directory to the PATH?

$path_dir = format $path @{ "dir" = $dir; "data_dir" = $data_dir }
} else {
$path_dir = "$dir\$($path)"
}

return $path_dir
}

function env_add_path($manifest, $dir, $global) {
$manifest.env_add_path | ? { $_ } | % {
$path_dir = "$dir\$($_)"
if(!(is_in_dir $dir $path_dir)) {
$path_dir = prepare_env_path $_

if(!(is_in_dir $dir $path_dir) -and !(is_in_dir $data_dir $path_dir)) {
abort "Error in manifest: env_add_path '$_' is outside the app directory."
}
add_first_in_path $path_dir $global
Expand All @@ -827,7 +838,8 @@ function add_first_in_path($dir, $global) {
function env_rm_path($manifest, $dir, $global) {
# remove from path
$manifest.env_add_path | ? { $_ } | % {
$path_dir = "$dir\$($_)"
$path_dir = prepare_env_path $_

remove_from_path $path_dir $global
}
}
Expand All @@ -836,7 +848,7 @@ function env_set($manifest, $dir, $global) {
if($manifest.env_set) {
$manifest.env_set | gm -member noteproperty | % {
$name = $_.name;
$val = format $manifest.env_set.$($_.name) @{ "dir" = $dir }
$val = format $manifest.env_set.$($_.name) @{ "dir" = $dir; "data_dir" = $data_dir }
env $name $global $val
sc env:\$name $val
}
Expand Down
2 changes: 2 additions & 0 deletions libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ foreach($app in $apps) {
"Uninstalling '$app' ($version)."

$dir = versiondir $app $version $global
$data_dir = appdatadir $app

try {
test-path $dir -ea stop | out-null
} catch [unauthorizedaccessexception] {
Expand Down

0 comments on commit 912fbe8

Please sign in to comment.