Skip to content

Commit

Permalink
Dedupe boot scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
esatterwhite authored and Miroslav Bajtoš committed Dec 19, 2014
1 parent beb4f8c commit 301031b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions test/compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand Down

0 comments on commit 301031b

Please sign in to comment.