Persistence: prevent NPM from overwriting node_modules by setting read-only attribute on the persisted directory junction.

This commit is contained in:
Luke Sampson
2017-03-25 16:28:05 +01:00
committed by Rémy
parent 1974a02eb7
commit 732cf2caa2
2 changed files with 7 additions and 5 deletions
+2 -1
View File
@@ -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/",
+5 -4
View File
@@ -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)) {
@@ -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 #
}
}
}