Merge pull request #72 from esatterwhite/lb-64-multiple-invocation-same-boot-script
Ensure to dedupe boot scripts array before running. Closes #72 Fixes #64
This commit is contained in:
commit
8a3e529ea3
|
@ -6,6 +6,7 @@ var toposort = require('toposort');
|
||||||
var ConfigLoader = require('./config-loader');
|
var ConfigLoader = require('./config-loader');
|
||||||
var debug = require('debug')('loopback:boot:compiler');
|
var debug = require('debug')('loopback:boot:compiler');
|
||||||
var Module = require('module');
|
var Module = require('module');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather all bootstrap-related configuration data and compile it into
|
* Gather all bootstrap-related configuration data and compile it into
|
||||||
|
@ -61,6 +62,10 @@ module.exports = function compile(options) {
|
||||||
bootScripts = bootScripts.concat(findScripts(dir));
|
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 || {};
|
var modelsMeta = modelsConfig._meta || {};
|
||||||
delete modelsConfig._meta;
|
delete modelsConfig._meta;
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,18 @@ describe('compiler', function() {
|
||||||
expect(instructions.files.boot).to.eql([initJs]);
|
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() {
|
it('ignores models/ subdirectory', function() {
|
||||||
appdir.createConfigFilesSync();
|
appdir.createConfigFilesSync();
|
||||||
appdir.writeFileSync('models/my-model.js', '');
|
appdir.writeFileSync('models/my-model.js', '');
|
||||||
|
|
Loading…
Reference in New Issue