From 2c6b774e87e598d5e530cb0ee7026501abfbebdf Mon Sep 17 00:00:00 2001 From: Rusty Tanton Date: Tue, 16 Feb 2016 11:06:53 -0500 Subject: [PATCH 1/2] updated to account for npm3 installing local modules to a flat directory structure --- bsp-grunt.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bsp-grunt.js b/bsp-grunt.js index bd3a072..4123691 100644 --- a/bsp-grunt.js +++ b/bsp-grunt.js @@ -5,6 +5,17 @@ module.exports = function(grunt, config) { var EXTEND = require('extend'); var Builder = require('systemjs-builder'); var builder = new Builder(); + var fs = require('fs'); + + // npm 3 flattens the node_modules directory structure, so + // we need to look for modules at multiple paths + var lessContribDir = __dirname + '/node_modules/grunt-contrib-less/node_modules/less/'; + try { + fs.statSync(lessContribDir); + } catch(e) { + lessContribDir = process.cwd() + '/node_modules/less/'; + fs.statSync(lessContribDir); + } grunt.initConfig(EXTEND(true, { }, { bsp: { @@ -99,8 +110,8 @@ module.exports = function(grunt, config) { less: { files: { '<%= bsp.scripts.devDir %>/less.js': - __dirname + '/node_modules/grunt-contrib-less/node_modules/less/' + - grunt.file.readJSON(__dirname + '/node_modules/grunt-contrib-less/node_modules/less/bower.json').main + lessContribDir + + grunt.file.readJSON(lessContribDir + '/bower.json').main } } }, @@ -191,7 +202,10 @@ module.exports = function(grunt, config) { }, (config || { }))); + // look in two places because npm3 downloads modules to + // a flat directory structure grunt.file.expand(__dirname + '/node_modules/grunt-*/tasks').forEach(grunt.loadTasks); + grunt.file.expand(process.cwd() + '/node_modules/grunt-*/tasks').forEach(grunt.loadTasks); grunt.loadTasks(__dirname + '/tasks'); @@ -216,4 +230,4 @@ module.exports = function(grunt, config) { 'bsp' ]); -}; +}; \ No newline at end of file From a5f1e81811311218b34d74cd8a420a2299e74419 Mon Sep 17 00:00:00 2001 From: Rusty Tanton Date: Tue, 16 Feb 2016 12:00:41 -0500 Subject: [PATCH 2/2] update to npm3 directory search logic --- bsp-grunt.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bsp-grunt.js b/bsp-grunt.js index 4123691..a4a7b01 100644 --- a/bsp-grunt.js +++ b/bsp-grunt.js @@ -5,17 +5,21 @@ module.exports = function(grunt, config) { var EXTEND = require('extend'); var Builder = require('systemjs-builder'); var builder = new Builder(); - var fs = require('fs'); // npm 3 flattens the node_modules directory structure, so // we need to look for modules at multiple paths - var lessContribDir = __dirname + '/node_modules/grunt-contrib-less/node_modules/less/'; - try { - fs.statSync(lessContribDir); - } catch(e) { - lessContribDir = process.cwd() + '/node_modules/less/'; - fs.statSync(lessContribDir); - } + var lessContribDir; + grunt.file.recurse( + process.cwd() + '/node_modules', + function(abspath, rootdir, subdir, filename) { + if (/\/less$/.test(subdir) && !lessContribDir) { + var subDirFullPath = process.cwd() + '/node_modules/' + subdir; + if (grunt.file.exists(subDirFullPath + '/bower.json')) { + lessContribDir = subDirFullPath; + } + } + } + ); grunt.initConfig(EXTEND(true, { }, { bsp: {