From 9b6655c1e49e393486b533f7b1ba72c7b56d8959 Mon Sep 17 00:00:00 2001 From: "Ethan J. Brown" Date: Mon, 10 Sep 2012 14:30:59 -0300 Subject: [PATCH 1/2] Fixes bug in base_path resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to how paths are shipped around, base_path would not correctly handle files in the root path, nesting them. For instance, a base_path of 'app/js' has been passed, which becomesĀ 'app/js/' in the task. Notice in the output that all files are properly re-based, except for those directly inside 'app/js/' (namely main.js, app.js): Running "coffee:app" (coffee) task Verifying property coffee.app exists in config...OK >> Note that grunt.utils has been renamed to grunt.util and is now deprecated. >> Please ensure that your custom tasks are up-to-date. (grunt 0.4.0+) Reading app/js/app.coffee...OK Writing generated\js\app\js\app.js...OK Reading app/js/controllers/auth.coffee...OK Writing generated\js\controllers\auth.js...OK Reading app/js/directives/directives.coffee...OK Writing generated\js\directives\directives.js...OK Reading app/js/filters/filters.coffee...OK Writing generated\js\filters\filters.js...OK Reading app/js/main.coffee...OK Writing generated\js\app\js\main.js...OK Reading app/js/services/auth.coffee...OK Writing generated\js\services\auth.js...OK --- tasks/coffee.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/coffee.js b/tasks/coffee.js index 68ee8e2..0fa69b6 100644 --- a/tasks/coffee.js +++ b/tasks/coffee.js @@ -44,7 +44,7 @@ module.exports = function(grunt) { extension = typeof extension === "undefined" ? '.js' : extension; if( destPath && options.preserve_dirs ){ - var dirname = path.dirname(src); + var dirname = path.dirname(src) + '/'; if ( options.base_path ) { dirname = dirname.replace(new RegExp('^'+options.base_path), ''); } From 3913a7b92673626dd90bd7b6e5a395b4c4d6cbff Mon Sep 17 00:00:00 2001 From: Iristyle Date: Tue, 11 Sep 2012 15:42:44 -0400 Subject: [PATCH 2/2] Fixes bug in base_path resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to how paths are shipped around, base_path would not correctly handle files in the root path, nesting them. Properly normalizes paths / uses path.sep when available, so that this will work on all operating systems, regardless of how paths are configured in the configuration file. For instance, a base_path of 'app/js' has been passed, which becomesĀ 'app/js/' in the task. Notice in the output that all files are properly re-based, except for those directly inside 'app/js/' (namely main.js, app.js): Running "coffee:app" (coffee) task Verifying property coffee.app exists in config...OK >> Note that grunt.utils has been renamed to grunt.util and is now deprecated. >> Please ensure that your custom tasks are up-to-date. (grunt 0.4.0+) Reading app/js/app.coffee...OK Writing generated\js\app\js\app.js...OK Reading app/js/controllers/auth.coffee...OK Writing generated\js\controllers\auth.js...OK Reading app/js/directives/directives.coffee...OK Writing generated\js\directives\directives.js...OK Reading app/js/filters/filters.coffee...OK Writing generated\js\filters\filters.js...OK Reading app/js/main.coffee...OK Writing generated\js\app\js\main.js...OK Reading app/js/services/auth.coffee...OK Writing generated\js\services\auth.js...OK --- tasks/coffee.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tasks/coffee.js b/tasks/coffee.js index 0fa69b6..cf7d732 100644 --- a/tasks/coffee.js +++ b/tasks/coffee.js @@ -8,6 +8,8 @@ module.exports = function(grunt) { var path = require('path'); + var isWindows = process.platform === "win32"; + var pathsep = path.sep || isWindows ? '\\' : '/'; // Please see the grunt documentation for more information regarding task and // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md @@ -44,9 +46,11 @@ module.exports = function(grunt) { extension = typeof extension === "undefined" ? '.js' : extension; if( destPath && options.preserve_dirs ){ - var dirname = path.dirname(src) + '/'; + var dirname = path.normalize(path.dirname(src)) + pathsep; if ( options.base_path ) { - dirname = dirname.replace(new RegExp('^'+options.base_path), ''); + //on Windows, path.sep must be escaped in a regex + var safeRegex = path.normalize(options.base_path).replace(/\\/g, "\\\\"); + dirname = dirname.replace(new RegExp('^' + safeRegex), ''); } destPath = path.join(destPath, dirname); } else if( !destPath ){