From 4382206cfe5a83f82bce51ccdfb480e4774c4a34 Mon Sep 17 00:00:00 2001 From: Luke Sampson Date: Fri, 24 Mar 2017 19:09:28 +1100 Subject: [PATCH] Persistence: prevent NPM from overwriting node_modules by setting read-only attribute on the persisted directory junction. --- bucket/nodejs.json | 3 ++- lib/install.ps1 | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bucket/nodejs.json b/bucket/nodejs.json index 98afc133a4..851406c205 100644 --- a/bucket/nodejs.json +++ b/bucket/nodejs.json @@ -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/", diff --git a/lib/install.ps1 b/lib/install.ps1 index c6ca284587..0bc4de9540 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -976,19 +976,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)) { @@ -1007,6 +1007,7 @@ function persist_data($manifest) { # create link # TODO use /h for files cmd /c "mklink /j $source $target" | out-null + attrib $source +R /L # } } }