From 7dc8cb5500f3b8684ccea56218f6bf314d4ea5be Mon Sep 17 00:00:00 2001 From: "nathan.ainslie" Date: Fri, 8 Feb 2019 13:42:41 -0500 Subject: [PATCH] Add ability to configure working directory for unzipping/running node modules Added support for environment variable WEBCOMPILER_WORKING_DIRECTORY in CompilerService. If set, we will unzip node.exe and node modules into a subdirectory of this directory instead of into the system temp directory. This is intended for CI or build server environments where temp directories are often cleaned after every run, or are set per-build-agent. --- .gitignore | 3 ++- src/WebCompiler/Compile/CompilerService.cs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 49ea30a4..5de5fb44 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ x64/ _NCrunch_WebCompiler#Node #Node -src/WebCompiler/Node/node_modules/* \ No newline at end of file +src/WebCompiler/Node/node_modules/* +src/WebCompiler/Node/node.exe \ No newline at end of file diff --git a/src/WebCompiler/Compile/CompilerService.cs b/src/WebCompiler/Compile/CompilerService.cs index 119b7ff0..4f53bf9f 100644 --- a/src/WebCompiler/Compile/CompilerService.cs +++ b/src/WebCompiler/Compile/CompilerService.cs @@ -11,12 +11,19 @@ namespace WebCompiler public static class CompilerService { internal const string Version = "1.4.167"; - private static readonly string _path = Path.Combine(Path.GetTempPath(), "WebCompiler" + Version); + internal const string WorkingDirectoryEnvVarName = "WEBCOMPILER_WORKING_DIRECTORY"; + private static readonly string _path = GetWorkingDirectoryPath(); private static object _syncRoot = new object(); // Used to lock on the initialize step /// A list of allowed file extensions. public static readonly string[] AllowedExtensions = new[] { ".LESS", ".SCSS", ".SASS", ".STYL", ".COFFEE", ".ICED", ".JS", ".JSX", ".ES6", ".HBS", ".HANDLEBARS" }; + internal static string GetWorkingDirectoryPath() + { + var envValue = Environment.GetEnvironmentVariable(WorkingDirectoryEnvVarName); + return Path.Combine(envValue ?? Path.GetTempPath(), "WebCompiler" + Version); + } + /// /// Test if a file type is supported by the compilers. ///