commit
2675771ec1
3
index.js
3
index.js
|
@ -200,7 +200,8 @@ exports.PluginBase = PluginBase;
|
|||
|
||||
exports.execute = function(app, instructions, done) {
|
||||
var bootstrapper = new Bootstrapper(
|
||||
{phases: ['starting', 'start', 'started']});
|
||||
{phases: ['starting', 'start', 'started']}
|
||||
);
|
||||
var context = {
|
||||
app: app,
|
||||
instructions: instructions,
|
||||
|
|
|
@ -104,7 +104,8 @@ function bundleInstructions(context, bundler) {
|
|||
if (hasMiddleware) {
|
||||
g.warn(
|
||||
'Discarding {{middleware}} instructions,' +
|
||||
' {{loopback}} client does not support {{middleware}}.');
|
||||
' {{loopback}} client does not support {{middleware}}.'
|
||||
);
|
||||
}
|
||||
delete instructions.middleware;
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ function getConfigVariable(app, param, useEnvVars) {
|
|||
configVariable = undefined;
|
||||
g.warn('%s does not resolve to a valid value, returned as %s. ' +
|
||||
'"%s" must be resolvable in Environment variable or by {{app.get()}}.',
|
||||
param, configVariable, varName);
|
||||
param, configVariable, varName);
|
||||
debug('Dynamic Configuration: Cannot resolve variable for `%s`, ' +
|
||||
'returned as %s', varName, configVariable);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ function assertLoopBackVersion(app) {
|
|||
'The `app` is powered by an incompatible loopback version %s. ' +
|
||||
'Supported versions: %s',
|
||||
loopback.version || '(unknown)',
|
||||
RANGE);
|
||||
RANGE
|
||||
);
|
||||
throw new Error(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ function Component(options) {
|
|||
|
||||
util.inherits(Component, PluginBase);
|
||||
|
||||
Component.prototype.getRootDir = function() {
|
||||
Component.prototype.getRootDir = function() {
|
||||
return this.options.componentRootDir || this.options.rootDir;
|
||||
};
|
||||
|
||||
|
|
|
@ -102,8 +102,7 @@ Middleware.prototype.buildInstructions = function(context, rootDir, config) {
|
|||
if (!resolved.sourceFile) {
|
||||
return g.log('Middleware "%s" not found: %s',
|
||||
middleware,
|
||||
resolved.optional
|
||||
);
|
||||
resolved.optional);
|
||||
}
|
||||
|
||||
var middlewareConfig = cloneDeep(config);
|
||||
|
@ -111,7 +110,8 @@ Middleware.prototype.buildInstructions = function(context, rootDir, config) {
|
|||
|
||||
if (middlewareConfig.params) {
|
||||
middlewareConfig.params = resolveMiddlewareParams(
|
||||
rootDir, middlewareConfig.params);
|
||||
rootDir, middlewareConfig.params
|
||||
);
|
||||
}
|
||||
|
||||
var item = {
|
||||
|
|
|
@ -37,13 +37,14 @@ Mixin.prototype.buildInstructions = function(context, rootDir, config) {
|
|||
var scriptExtensions = this.options.scriptExtensions || require.extensions;
|
||||
|
||||
var mixinInstructions = buildAllMixinInstructions(
|
||||
rootDir, this.options, mixinSources, scriptExtensions, modelInstructions);
|
||||
rootDir, this.options, mixinSources, scriptExtensions, modelInstructions
|
||||
);
|
||||
|
||||
return mixinInstructions;
|
||||
};
|
||||
|
||||
function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
||||
scriptExtensions, modelInstructions) {
|
||||
scriptExtensions, modelInstructions) {
|
||||
// load mixins from `options.mixins`
|
||||
var sourceFiles = options.mixins || [];
|
||||
var mixinDirs = options.mixinDirs || [];
|
||||
|
@ -53,7 +54,7 @@ function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
|||
sourceFiles = findMixinDefinitions(appRootDir, mixinDirs, scriptExtensions);
|
||||
if (sourceFiles === undefined) return;
|
||||
var instructionsFromMixinDirs = loadMixins(sourceFiles,
|
||||
options.normalization);
|
||||
options.normalization);
|
||||
|
||||
/* If `mixinDirs` and `mixinSources` have any directories in common,
|
||||
* then remove the common directories from `mixinSources` */
|
||||
|
@ -61,10 +62,10 @@ function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
|||
|
||||
// load mixins from `options.mixinSources`
|
||||
sourceFiles = findMixinDefinitions(appRootDir, mixinSources,
|
||||
scriptExtensions);
|
||||
scriptExtensions);
|
||||
if (sourceFiles === undefined) return;
|
||||
var instructionsFromMixinSources = loadMixins(sourceFiles,
|
||||
options.normalization);
|
||||
options.normalization);
|
||||
|
||||
// Fetch unique list of mixin names, used in models
|
||||
var modelMixins = fetchMixinNamesUsedInModelInstructions(modelInstructions);
|
||||
|
@ -72,12 +73,14 @@ function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
|||
|
||||
// Filter-in only mixins, that are used in models
|
||||
instructionsFromMixinSources = filterMixinInstructionsUsingWhitelist(
|
||||
instructionsFromMixinSources, modelMixins);
|
||||
instructionsFromMixinSources, modelMixins
|
||||
);
|
||||
|
||||
var mixins = _.assign(
|
||||
instructionsFromMixins,
|
||||
instructionsFromMixinDirs,
|
||||
instructionsFromMixinSources);
|
||||
instructionsFromMixinSources
|
||||
);
|
||||
|
||||
return _.values(mixins);
|
||||
}
|
||||
|
|
|
@ -49,14 +49,15 @@ Model.prototype.buildInstructions = function(context, rootDir, modelsConfig) {
|
|||
['./models'];
|
||||
var modelInstructions = buildAllModelInstructions(
|
||||
rootDir, modelsConfig, modelSources, this.options.modelDefinitions,
|
||||
this.options.scriptExtensions);
|
||||
this.options.scriptExtensions
|
||||
);
|
||||
return modelInstructions;
|
||||
};
|
||||
|
||||
function buildAllModelInstructions(rootDir, modelsConfig, sources,
|
||||
modelDefinitions, scriptExtensions) {
|
||||
modelDefinitions, scriptExtensions) {
|
||||
var registry = verifyModelDefinitions(rootDir, modelDefinitions,
|
||||
scriptExtensions);
|
||||
scriptExtensions);
|
||||
if (!registry) {
|
||||
registry = findModelDefinitions(rootDir, sources, scriptExtensions);
|
||||
}
|
||||
|
@ -152,7 +153,8 @@ function verifyModelDefinitions(rootDir, modelDefinitions, scriptExtensions) {
|
|||
definition.sourceFile = fixFileExtension(
|
||||
fullPath,
|
||||
tryReadDir(path.dirname(fullPath)),
|
||||
scriptExtensions);
|
||||
scriptExtensions
|
||||
);
|
||||
|
||||
if (!definition.sourceFile) {
|
||||
debug('Model source code not found: %s - %s', definition.sourceFile);
|
||||
|
@ -170,7 +172,7 @@ function verifyModelDefinitions(rootDir, modelDefinitions, scriptExtensions) {
|
|||
if (!modelName) {
|
||||
debug('Skipping model definition without Model name ' +
|
||||
'(from options.modelDefinitions @ index %s)',
|
||||
idx);
|
||||
idx);
|
||||
return;
|
||||
}
|
||||
registry[modelName] = definition;
|
||||
|
@ -198,7 +200,7 @@ function findModelDefinitions(rootDir, sources, scriptExtensions) {
|
|||
.forEach(function(f) {
|
||||
var fullPath = path.resolve(srcDir, f);
|
||||
var entry = loadModelDefinition(rootDir, fullPath, files,
|
||||
scriptExtensions);
|
||||
scriptExtensions);
|
||||
var modelName = entry.definition.name;
|
||||
if (!modelName) {
|
||||
debug('Skipping model definition without Model name: %s',
|
||||
|
@ -246,7 +248,8 @@ function assertIsValidModelConfig(config) {
|
|||
if (unsupported) {
|
||||
throw new Error(g.f(
|
||||
'The data in {{model-config.json}} ' +
|
||||
'is in the unsupported {{1.x}} format.'));
|
||||
'is in the unsupported {{1.x}} format.'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +257,8 @@ function assertIsValidModelConfig(config) {
|
|||
// Regular expression to match built-in loopback models
|
||||
var LOOPBACK_MODEL_REGEXP = new RegExp(
|
||||
['', 'node_modules', 'loopback', '[^\\/\\\\]+', 'models', '[^\\/\\\\]+\\.js$']
|
||||
.join('\\' + path.sep));
|
||||
.join('\\' + path.sep)
|
||||
);
|
||||
|
||||
function isBuiltinLoopBackModel(app, data) {
|
||||
// 1. Built-in models are exposed on the loopback object
|
||||
|
|
|
@ -102,7 +102,7 @@ function getExcludedExtensions() {
|
|||
return {
|
||||
'.json': '.json',
|
||||
'.node': 'node',
|
||||
/**
|
||||
/**
|
||||
* This is a temporary workaround for #246
|
||||
* See discussion here for full description of the underlying issue
|
||||
* https://github.com/strongloop/loopback-boot/pull/245#issuecomment-311052798
|
||||
|
|
10
package.json
10
package.json
|
@ -34,8 +34,8 @@
|
|||
"debug": "^2.2.0",
|
||||
"lodash": "^4.13.1",
|
||||
"semver": "^5.1.0",
|
||||
"strong-globalize": "^3.1.0",
|
||||
"toposort": "^1.0.0"
|
||||
"strong-globalize": "^4.1.1",
|
||||
"toposort": "^2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^4.2.3",
|
||||
|
@ -43,11 +43,11 @@
|
|||
"coffeescript": "^2.3.1",
|
||||
"coffeeify": "^2.0.1",
|
||||
"dirty-chai": "^1.2.2",
|
||||
"eslint": "^3.19.0",
|
||||
"eslint-config-loopback": "^8.0.0",
|
||||
"eslint": "^5.2.0",
|
||||
"eslint-config-loopback": "^11.0.0",
|
||||
"fs-extra": "^3.0.1",
|
||||
"loopback": "^3.0.0",
|
||||
"mocha": "^3.3.0",
|
||||
"mocha": "^5.2.0",
|
||||
"supertest": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,24 +300,24 @@ describe('compiler', function() {
|
|||
name: 'model-with-definition-with-falsey-source-file',
|
||||
},
|
||||
sourceFile: appdir.resolve(
|
||||
'custom-models',
|
||||
'file-does-not-exist.js'
|
||||
),
|
||||
'custom-models',
|
||||
'file-does-not-exist.js'
|
||||
),
|
||||
},
|
||||
],
|
||||
dataSources: dataSources,
|
||||
},
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.models[0].name).to.equal(
|
||||
'model-with-definition-with-falsey-source-file'
|
||||
);
|
||||
expect(instructions.models[0].definition).not.to.equal(undefined);
|
||||
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.models[0].name).to.equal(
|
||||
'model-with-definition-with-falsey-source-file'
|
||||
);
|
||||
expect(instructions.models[0].definition).not.to.equal(undefined);
|
||||
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('does not set source file path if no source file supplied.',
|
||||
|
@ -340,17 +340,17 @@ describe('compiler', function() {
|
|||
],
|
||||
dataSources: dataSources,
|
||||
},
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.models[0].name).to.equal(
|
||||
'model-with-definition-without-source-file-property'
|
||||
);
|
||||
expect(instructions.models[0].definition).not.to.equal(undefined);
|
||||
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.models[0].name).to.equal(
|
||||
'model-with-definition-without-source-file-property'
|
||||
);
|
||||
expect(instructions.models[0].definition).not.to.equal(undefined);
|
||||
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('loads models defined in `models` only.', function(done) {
|
||||
|
@ -949,13 +949,13 @@ describe('compiler', function() {
|
|||
appRootDir: appdir.PATH,
|
||||
bootDirs: ['./custom-boot'],
|
||||
},
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.bootScripts).to.eql([coffee]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.bootScripts).to.eql([coffee]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('prefers coffeescript over json in `bootDir` non-relative path',
|
||||
|
@ -969,13 +969,13 @@ describe('compiler', function() {
|
|||
appRootDir: appdir.PATH,
|
||||
bootDirs: ['custom-boot'],
|
||||
},
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.bootScripts).to.eql([coffee]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.bootScripts).to.eql([coffee]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('supports `bootScripts` option', function(done) {
|
||||
|
@ -1084,13 +1084,13 @@ describe('compiler', function() {
|
|||
appRootDir: appdir.PATH,
|
||||
bootScripts: ['custom-boot/init'],
|
||||
},
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.bootScripts).to.eql([initJs]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
expect(instructions.bootScripts).to.eql([initJs]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('resolves module relative path for `bootScripts`', function(done) {
|
||||
|
@ -1146,12 +1146,12 @@ describe('compiler', function() {
|
|||
it('throws when models-config.json contains 1.x `properties`',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
foo: {properties: {name: 'string'}},
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
expectCompileToThrow(/unsupported 1\.x format/, done);
|
||||
});
|
||||
|
@ -1159,12 +1159,12 @@ describe('compiler', function() {
|
|||
it('throws when model-config.json contains 1.x `options.base`',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
Customer: {options: {base: 'User'}},
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
expectCompileToThrow(/unsupported 1\.x format/, done);
|
||||
});
|
||||
|
@ -1363,12 +1363,12 @@ describe('compiler', function() {
|
|||
it('resolves module relative path in `modelSources` option',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
Car: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('node_modules/custom-models/car.json', {
|
||||
name: 'Car',
|
||||
});
|
||||
|
@ -1380,29 +1380,29 @@ describe('compiler', function() {
|
|||
appRootDir: appdir.PATH,
|
||||
modelSources: ['custom-models'],
|
||||
},
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
function(err, context) {
|
||||
if (err) return done(err);
|
||||
var instructions = context.instructions;
|
||||
|
||||
expect(instructions.models).to.have.length(1);
|
||||
expect(instructions.models[0].sourceFile).to.equal(appJS);
|
||||
done();
|
||||
}
|
||||
);
|
||||
expect(instructions.models).to.have.length(1);
|
||||
expect(instructions.models[0].sourceFile).to.equal(appJS);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('resolves relative path in `sources` option in `model-config.json`',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
_meta: {
|
||||
sources: ['./custom-models'],
|
||||
},
|
||||
Car: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('custom-models/car.json', {name: 'Car'});
|
||||
var appJS = appdir.writeFileSync('custom-models/car.js', '');
|
||||
|
||||
|
@ -1419,15 +1419,15 @@ describe('compiler', function() {
|
|||
it('resolves module relative path in `sources` option in model-config.json',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
_meta: {
|
||||
sources: ['custom-models'],
|
||||
},
|
||||
Car: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('node_modules/custom-models/car.json', {
|
||||
name: 'Car',
|
||||
});
|
||||
|
@ -1623,12 +1623,12 @@ describe('compiler', function() {
|
|||
it('uses `OrderItem` as default model name for file with name `order-item`',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
OrderItem: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('models/order-item.json', {});
|
||||
|
||||
boot.compile(appdir.PATH, function(err, context) {
|
||||
|
@ -1644,12 +1644,12 @@ describe('compiler', function() {
|
|||
it('uses `OrderItem` as default model name for file with name `order_item`',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
OrderItem: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('models/order_item.json', {});
|
||||
|
||||
boot.compile(appdir.PATH, function(err, context) {
|
||||
|
@ -1665,12 +1665,12 @@ describe('compiler', function() {
|
|||
it('uses `OrderItem` as default model name for file with name `order item`',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
OrderItem: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('models/order item.json', {});
|
||||
|
||||
boot.compile(appdir.PATH, function(err, context) {
|
||||
|
@ -1686,12 +1686,12 @@ describe('compiler', function() {
|
|||
it('overrides `default model name` by `name` in model definition',
|
||||
function(done) {
|
||||
appdir.createConfigFilesSync(
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
overrideCar: {dataSource: 'db'},
|
||||
}
|
||||
);
|
||||
);
|
||||
appdir.writeConfigFileSync('models/car.json', {name: 'overrideCar'});
|
||||
|
||||
boot.compile(appdir.PATH, function(err, context) {
|
||||
|
@ -1853,10 +1853,10 @@ describe('compiler', function() {
|
|||
it('resolves module relative path in `mixinDirs` option',
|
||||
function(done) {
|
||||
verifyMixinIsFoundViaMixinDirs(
|
||||
'node_modules/custom-mixins/other.js',
|
||||
['custom-mixins'],
|
||||
done
|
||||
);
|
||||
'node_modules/custom-mixins/other.js',
|
||||
['custom-mixins'],
|
||||
done
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1915,10 +1915,10 @@ describe('compiler', function() {
|
|||
it('resolves module relative path in `mixinSources` option',
|
||||
function(done) {
|
||||
verifyMixinIsFoundViaMixinSources(
|
||||
'node_modules/custom-mixins/time-stamps.js',
|
||||
['custom-mixins'],
|
||||
done
|
||||
);
|
||||
'node_modules/custom-mixins/time-stamps.js',
|
||||
['custom-mixins'],
|
||||
done
|
||||
);
|
||||
});
|
||||
|
||||
it('supports `mixins` option in `model-config.json`', function(done) {
|
||||
|
@ -2808,13 +2808,13 @@ describe('compiler', function() {
|
|||
var instructions = context.instructions;
|
||||
|
||||
expect(instructions.middleware.middleware[0]).have.property(
|
||||
'sourceFile',
|
||||
pathWithoutIndex(require.resolve('loopback'))
|
||||
);
|
||||
'sourceFile',
|
||||
pathWithoutIndex(require.resolve('loopback'))
|
||||
);
|
||||
expect(instructions.middleware.middleware[0]).have.property(
|
||||
'fragment',
|
||||
'errorHandler'
|
||||
);
|
||||
'fragment',
|
||||
'errorHandler'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -2883,9 +2883,9 @@ describe('compiler', function() {
|
|||
|
||||
expect(instructions.middleware.middleware).to.have.length(1);
|
||||
expect(instructions.middleware.middleware[0]).have.property(
|
||||
'sourceFile',
|
||||
moduleJS
|
||||
);
|
||||
'sourceFile',
|
||||
moduleJS
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -2951,9 +2951,9 @@ describe('compiler', function() {
|
|||
|
||||
expect(instructions.middleware.middleware).to.have.length(1);
|
||||
expect(instructions.middleware.middleware[0]).have.property(
|
||||
'sourceFile',
|
||||
coffee
|
||||
);
|
||||
'sourceFile',
|
||||
coffee
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -2961,9 +2961,9 @@ describe('compiler', function() {
|
|||
it('prefers coffeescript over json for module relative middleware path',
|
||||
function(done) {
|
||||
var coffee = appdir.writeFileSync(
|
||||
'node_modules/my-middleware.coffee',
|
||||
''
|
||||
);
|
||||
'node_modules/my-middleware.coffee',
|
||||
''
|
||||
);
|
||||
appdir.writeFileSync('node_modules/my-middleware.json', '');
|
||||
appdir.writeConfigFileSync('middleware.json', {
|
||||
routes: {
|
||||
|
@ -2977,9 +2977,9 @@ describe('compiler', function() {
|
|||
|
||||
expect(instructions.middleware.middleware).to.have.length(1);
|
||||
expect(instructions.middleware.middleware[0]).have.property(
|
||||
'sourceFile',
|
||||
coffee
|
||||
);
|
||||
'sourceFile',
|
||||
coffee
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -3209,9 +3209,9 @@ describe('compiler', function() {
|
|||
appdir.writeConfigFileSync('./my-component/component.js', '');
|
||||
|
||||
expectCompileToThrow(
|
||||
'Cannot resolve path "my-component/component.js"',
|
||||
done
|
||||
);
|
||||
'Cannot resolve path "my-component/component.js"',
|
||||
done
|
||||
);
|
||||
});
|
||||
|
||||
it('prefers coffeescript over json for relative path component',
|
||||
|
|
|
@ -355,16 +355,16 @@ describe('executor', function() {
|
|||
});
|
||||
|
||||
it('receives rejected promise as callback error',
|
||||
function(done) {
|
||||
simpleAppInstructions(function(err, context) {
|
||||
if (err) return done(err);
|
||||
boot.execute(app, context.instructions, function(err) {
|
||||
expect(err).to.exist.and.be.an.instanceOf(Error)
|
||||
.with.property('message', 'reject');
|
||||
done();
|
||||
function(done) {
|
||||
simpleAppInstructions(function(err, context) {
|
||||
if (err) return done(err);
|
||||
boot.execute(app, context.instructions, function(err) {
|
||||
expect(err).to.exist.and.be.an.instanceOf(Error)
|
||||
.with.property('message', 'reject');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with boot script throwing an error', function() {
|
||||
|
@ -378,16 +378,16 @@ describe('executor', function() {
|
|||
});
|
||||
|
||||
it('receives thrown error as callback errors',
|
||||
function(done) {
|
||||
simpleAppInstructions(function(err, context) {
|
||||
if (err) return done(err);
|
||||
boot.execute(app, context.instructions, function(err) {
|
||||
expect(err).to.exist.and.be.an.instanceOf(Error)
|
||||
.with.property('message', 'throw');
|
||||
done();
|
||||
function(done) {
|
||||
simpleAppInstructions(function(err, context) {
|
||||
if (err) return done(err);
|
||||
boot.execute(app, context.instructions, function(err) {
|
||||
expect(err).to.exist.and.be.an.instanceOf(Error)
|
||||
.with.property('message', 'throw');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with boot script returning a promise and calling callback',
|
||||
|
@ -407,8 +407,7 @@ describe('executor', function() {
|
|||
boot.execute(app, context.instructions, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('for mixins', function() {
|
||||
var options;
|
||||
|
@ -598,8 +597,7 @@ describe('executor', function() {
|
|||
|
||||
it('should parse a simple config variable', function(done) {
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{path: '${restApiRoot}'}
|
||||
), function(err) {
|
||||
{path: '${restApiRoot}'}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/').end(function(err, res) {
|
||||
|
@ -613,8 +611,7 @@ describe('executor', function() {
|
|||
it('should parse simple config variable from env var', function(done) {
|
||||
process.env.restApiRoot = '/url-from-env-var';
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{path: '${restApiRoot}'}
|
||||
), function(err) {
|
||||
{path: '${restApiRoot}'}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/url-from-env-var').end(function(err, res) {
|
||||
|
@ -646,8 +643,7 @@ describe('executor', function() {
|
|||
|
||||
it('should parse multiple config variables', function(done) {
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{path: '${restApiRoot}', env: '${env}'}
|
||||
), function(err) {
|
||||
{path: '${restApiRoot}', env: '${env}'}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/').end(function(err, res) {
|
||||
|
@ -661,8 +657,7 @@ describe('executor', function() {
|
|||
|
||||
it('should parse config variables in an array', function(done) {
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{paths: ['${restApiRoot}']}
|
||||
), function(err) {
|
||||
{paths: ['${restApiRoot}']}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/').end(function(err, res) {
|
||||
|
@ -677,8 +672,7 @@ describe('executor', function() {
|
|||
|
||||
it('should parse config variables in an object', function(done) {
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{info: {path: '${restApiRoot}'}}
|
||||
), function(err) {
|
||||
{info: {path: '${restApiRoot}'}}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/').end(function(err, res) {
|
||||
|
@ -693,8 +687,7 @@ describe('executor', function() {
|
|||
|
||||
it('should parse config variables in a nested object', function(done) {
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{nested: {info: {path: '${restApiRoot}'}}}
|
||||
), function(err) {
|
||||
{nested: {info: {path: '${restApiRoot}'}}}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/').end(function(err, res) {
|
||||
|
@ -709,8 +702,7 @@ describe('executor', function() {
|
|||
|
||||
it('should parse config variables with null values', function(done) {
|
||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||
{nested: {info: {path: '${restApiRoot}', some: null}}}
|
||||
), function(err) {
|
||||
{nested: {info: {path: '${restApiRoot}', some: null}}}), function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
supertest(app).get('/').end(function(err, res) {
|
||||
|
@ -769,7 +761,8 @@ describe('executor', function() {
|
|||
'routes',
|
||||
// IMPORTANT we need more than one item to trigger the original issue
|
||||
[/^\/foobar/, /^\/another/],
|
||||
{});
|
||||
{}
|
||||
);
|
||||
boot.execute(app, config, function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
|
@ -1036,7 +1029,8 @@ describe('executor', function() {
|
|||
if (err) return done(err);
|
||||
|
||||
expect(Object.keys(require.cache)).to.include(
|
||||
appdir.resolve('components/test-component/index.js'));
|
||||
appdir.resolve('components/test-component/index.js')
|
||||
);
|
||||
|
||||
expect(app.componentOptions).to.eql({option: 'value'});
|
||||
done();
|
||||
|
@ -1056,32 +1050,34 @@ describe('executor', function() {
|
|||
if (err) return done(err);
|
||||
|
||||
expect(Object.keys(require.cache)).to.not.include(
|
||||
appdir.resolve('components/test-component/index.js'));
|
||||
appdir.resolve('components/test-component/index.js')
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('disables component if overrided by production configuration',
|
||||
function(done) {
|
||||
appdir.writeConfigFileSync('component-config.json', {
|
||||
'./components/test-component': {},
|
||||
});
|
||||
appdir.writeConfigFileSync('component-config.production.json', {
|
||||
'./components/test-component': null,
|
||||
});
|
||||
function(done) {
|
||||
appdir.writeConfigFileSync('component-config.json', {
|
||||
'./components/test-component': {},
|
||||
});
|
||||
appdir.writeConfigFileSync('component-config.production.json', {
|
||||
'./components/test-component': null,
|
||||
});
|
||||
|
||||
appdir.writeFileSync('components/test-component/index.js',
|
||||
'module.exports = ' +
|
||||
appdir.writeFileSync('components/test-component/index.js',
|
||||
'module.exports = ' +
|
||||
'function(app, options) { app.componentOptions = options; }');
|
||||
|
||||
boot(app, {appRootDir: appdir.PATH, env: 'production'}, function(err) {
|
||||
if (err) return done(err);
|
||||
boot(app, {appRootDir: appdir.PATH, env: 'production'}, function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
expect(Object.keys(require.cache)).to.not.include(
|
||||
appdir.resolve('components/test-component/index.js'));
|
||||
done();
|
||||
expect(Object.keys(require.cache)).to.not.include(
|
||||
appdir.resolve('components/test-component/index.js')
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('configures middleware (that requires `this`)', function(done) {
|
||||
var passportPath = require.resolve('./fixtures/passport');
|
||||
|
@ -1219,7 +1215,8 @@ describe('executor', function() {
|
|||
boot.execute(app, someInstructions(bootInstructions), function() {
|
||||
expect(app.get('DYNAMIC_HOST')).to.equal('127.0.0.4');
|
||||
expect(app.datasources.mydb.settings.host).to.equal(
|
||||
'127.0.0.4');
|
||||
'127.0.0.4'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue