From 0b87bbe8399b3c4a31e787426c830148480d3862 Mon Sep 17 00:00:00 2001 From: willthames Date: Fri, 21 Mar 2014 13:26:07 +1000 Subject: [PATCH] Allow npm to install to a directory that doesn't yet exist If path is specified but does not exist, create it. Fail if path is specified but is not a directory --- packaging/npm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packaging/npm b/packaging/npm index 1157d8f6636..7034c7f9964 100644 --- a/packaging/npm +++ b/packaging/npm @@ -139,6 +139,10 @@ class Npm(object): #If path is specified, cd into that path and run the command. cwd = None if self.path: + if not os.path.exists(self.path): + os.makedirs(self.path) + if not os.path.isdir(self.path): + self.module.fail_json(msg="path %s is not a directory" % self.path) cwd = self.path rc, out, err = self.module.run_command(cmd, check_rc=check_rc, cwd=cwd)