diff --git a/build.js b/build.js index 0053e52dd..3d51f8c72 100755 --- a/build.js +++ b/build.js @@ -1513,6 +1513,14 @@ var outputPath = options.reduce(function(result, value, index) { if (/-o|--output/.test(value)) { result = options[index + 1]; + var cwd = process.cwd(); + path.dirname(result).split(path.sep).forEach(function(pathSegment){ + try { + fs.mkdirSync(pathSegment); + } catch(err){} + process.chdir(pathSegment); + }); + process.chdir(cwd); result = path.join(fs.realpathSync(path.dirname(result)), path.basename(result)); } return result; diff --git a/test/test-build.js b/test/test-build.js index 953caa012..e68166126 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -1114,9 +1114,11 @@ QUnit.module('output options'); (function() { + var nestedDir = 'test/mkdir/'; var commands = [ '-o a.js', - '--output a.js' + '--output a.js', + '-o ' + nestedDir + 'a.js' ]; commands.forEach(function(command, index) { @@ -1127,6 +1129,7 @@ build(['-s'].concat(command.split(' ')), function(data) { equal(path.basename(data.outputPath, '.js'), (++counter ? 'a.min' : 'a'), command); start(); + fs.existsSync(nestedDir) && fs.rmdirSync(nestedDir); }); }); });