diff --git a/lib/compiler.js b/lib/compiler.js index 4c184cd..25a79b3 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -62,8 +62,11 @@ module.exports = function compile(options) { // require directories var bootDirs = options.bootDirs || []; // precedence bootDirs = bootDirs.concat(path.join(appRootDir, 'boot')); + resolveRelativePaths(bootDirs, appRootDir); var bootScripts = options.bootScripts || []; + resolveRelativePaths(bootScripts, appRootDir); + bootDirs.forEach(function(dir) { bootScripts = bootScripts.concat(findScripts(dir)); }); @@ -497,3 +500,12 @@ function buildComponentInstructions(rootDir, componentConfig) { }; }); } + +function resolveRelativePaths(relativePaths, appRootDir) { + relativePaths.forEach(function(relativePath, k) { + var start = relativePath.substring(0, 2); + if (start === './' || start === '..') { + relativePaths[k] = path.resolve(appRootDir, relativePath); + } + }); +} diff --git a/test/compiler.test.js b/test/compiler.test.js index e7407c7..5eb9bbc 100644 --- a/test/compiler.test.js +++ b/test/compiler.test.js @@ -417,6 +417,28 @@ describe('compiler', function() { expect(instructions.files.boot).to.eql([initJs]); }); + it('should resolve relative path in `bootScripts`', function() { + appdir.createConfigFilesSync(); + var initJs = appdir.writeFileSync('custom-boot/init.js', + 'module.exports = function(app) { app.fnCalled = true; };'); + var instructions = boot.compile({ + appRootDir: appdir.PATH, + bootScripts: ['./custom-boot/init.js'] + }); + expect(instructions.files.boot).to.eql([initJs]); + }); + + it('should resolve relative path in `bootDirs`', function() { + appdir.createConfigFilesSync(); + var initJs = appdir.writeFileSync('custom-boot/init.js', + 'module.exports = function(app) { app.fnCalled = true; };'); + var instructions = boot.compile({ + appRootDir: appdir.PATH, + bootDirs:['./custom-boot'] + }); + expect(instructions.files.boot).to.eql([initJs]); + }); + it('ignores models/ subdirectory', function() { appdir.createConfigFilesSync(); appdir.writeFileSync('models/my-model.js', '');