From 301031b78ff84e92232f9ca24feedf7e421106dc Mon Sep 17 00:00:00 2001 From: Eric Satterwhite Date: Wed, 19 Nov 2014 11:54:36 -0600 Subject: [PATCH 1/2] Dedupe boot scripts Remove duplicated entries in the array of boot scripts to run. Because the bootDirs defaults to process.cwd(), if the user manually includes scripts in the same directory, without specifying a bootDir, those scripts will be included multiple times. --- lib/compiler.js | 5 +++++ test/compiler.test.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/compiler.js b/lib/compiler.js index 70e7f65..63e4c99 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -6,6 +6,7 @@ var toposort = require('toposort'); var ConfigLoader = require('./config-loader'); var debug = require('debug')('loopback:boot:compiler'); var Module = require('module'); +var _ = require('lodash'); /** * Gather all bootstrap-related configuration data and compile it into @@ -61,6 +62,10 @@ module.exports = function compile(options) { bootScripts = bootScripts.concat(findScripts(dir)); }); + // de-dedup boot scripts -ERS + // https://github.com/strongloop/loopback-boot/issues/64 + bootScripts = _.uniq(bootScripts); + var modelsMeta = modelsConfig._meta || {}; delete modelsConfig._meta; diff --git a/test/compiler.test.js b/test/compiler.test.js index edc128e..c5a952d 100644 --- a/test/compiler.test.js +++ b/test/compiler.test.js @@ -405,6 +405,18 @@ describe('compiler', function() { expect(instructions.files.boot).to.eql([initJs]); }); + it('should remove duplicate scripts', 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:[path.dirname(initJs)], + bootScripts: [initJs] + }); + expect(instructions.files.boot).to.eql([initJs]); + }); + it('ignores models/ subdirectory', function() { appdir.createConfigFilesSync(); appdir.writeFileSync('models/my-model.js', ''); From 4031f6b98557a766ae8a5868ff95d602c6959b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 19 Dec 2014 15:21:40 +0100 Subject: [PATCH 2/2] v2.5.2 --- CHANGES.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 1118730..676b350 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +2014-12-19, Version 2.5.2 +========================= + + * Dedupe boot scripts (Eric Satterwhite) + + 2014-12-08, Version 2.5.1 ========================= diff --git a/package.json b/package.json index b40ee46..82acc86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-boot", - "version": "2.5.1", + "version": "2.5.2", "description": "Convention-based bootstrapper for LoopBack applications", "keywords": [ "StrongLoop",