Skip to content

Commit

Permalink
Persistence: prevent NPM from overwriting node_modules by setting rea…
Browse files Browse the repository at this point in the history
…d-only attribute on the persisted directory junction.
  • Loading branch information
lukesampson authored and rrelmy committed Mar 25, 2017
1 parent 1974a02 commit 732cf2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bucket/nodejs.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
}
},
"env_add_path": "nodejs",
"persist": "nodejs/node_modules",
"post_install": "
# Remove npmrc that makes global modules get installed in AppData\\Roaming\\npm
rm $dir\\nodejs\\node_modules\\npm\\npmrc
if(test-path $dir\\nodejs\\node_modules\\npm\\npmrc) { rm $dir\\nodejs\\node_modules\\npm\\npmrc }
npm update -g",
"checkver": {
"url": "https://nodejs.org/en/download/current/",
Expand Down
9 changes: 5 additions & 4 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -966,19 +966,19 @@ function persist_def($persist) {
function persist_data($manifest) {
$persist = $manifest.persist
if($persist) {
ensure $data_dir
$data_dir = ensure $data_dir

if ($persist -is [String]) {
$persist = @($persist);
}

write-host "Persisting data..."
write-host "Persisting $persist"
$persist | % {
$source, $target = persist_def $_

# add base paths
$source = "$original_dir\$source"
$target = "$data_dir\$target"
$source = "$(resolve-path $original_dir\$source)"
$target = fullpath "$data_dir\$target"

# TODO test with files
if (!(test-path $target)) {
Expand All @@ -997,6 +997,7 @@ function persist_data($manifest) {
# create link
# TODO use /h for files
cmd /c "mklink /j $source $target" | out-null
attrib $source +R /L #
}
}
}

0 comments on commit 732cf2c

Please sign in to comment.