diff --git a/lib/compiler.js b/lib/compiler.js index 04f2845..e75ff6b 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -1,4 +1,5 @@ var assert = require('assert'); +var cloneDeep = require('lodash.clonedeep'); var fs = require('fs'); var path = require('path'); var toposort = require('toposort'); @@ -50,14 +51,17 @@ module.exports = function compile(options) { var modelInstructions = buildAllModelInstructions( modelsRootDir, modelsConfig, modelSources); - return { + // When executor passes the instruction to loopback methods, + // loopback modifies the data. Since we are loading the data using `require`, + // such change affects also code that calls `require` for the same file. + return cloneDeep({ config: appConfig, dataSources: dataSourcesConfig, models: modelInstructions, files: { boot: bootScripts } - }; + }); }; function assertIsValidConfig(name, config) { diff --git a/package.json b/package.json index 65c14ef..7a9002c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-boot", - "version": "2.0.0-beta2", + "version": "2.0.0-beta3", "description": "Convention-based bootstrapper for LoopBack applications", "keywords": [ "StrongLoop", @@ -25,6 +25,7 @@ "dependencies": { "commondir": "0.0.1", "debug": "^0.8.1", + "lodash.clonedeep": "^2.4.1", "semver": "^2.3.0", "toposort": "^0.2.10", "underscore": "^1.6.0" diff --git a/test/compiler.test.js b/test/compiler.test.js index e128235..5b6e450 100644 --- a/test/compiler.test.js +++ b/test/compiler.test.js @@ -402,6 +402,16 @@ describe('compiler', function() { expect(function() { boot.compile(appdir.PATH); }) .to.throw(/cyclic dependency/i); }); + + it('returns a new copy of JSON data', function() { + appdir.createConfigFilesSync(); + + var instructions = boot.compile(appdir.PATH); + instructions.config.modified = true; + + instructions = boot.compile(appdir.PATH); + expect(instructions.config).to.not.have.property('modified'); + }); }); });