diff --git a/lib/grunt/file.js b/lib/grunt/file.js index 461c62b77..22eefa368 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -305,6 +305,19 @@ file.copy = function(srcpath, destpath, options) { // If the file will be processed, use the encoding as-specified. Otherwise, // use an encoding of null to force the file to be read/written as a Buffer. var readWriteOptions = process ? options : {encoding: null}; + // Copy symlinks as symlinks + var isLink = fs.lstatSync( srcpath ).isSymbolicLink(); + if ( isLink ) { + var destdir = path.join( destpath, '..' ); + // Use the correct relative path for the symlink + if (!grunt.file.isPathAbsolute(srcpath)) { + srcpath = path.relative(destdir, srcpath) || '.'; + } + file.mkdir( destdir ); + var mode = grunt.file.isDir(srcpath) ? 'dir' : 'file'; + fs.symlinkSync(srcpath, destpath, mode); + return; + } // Actually read the file. var contents = file.read(srcpath, readWriteOptions); if (process) {